Update ethics.py
Browse files
ethics.py
CHANGED
@@ -25,25 +25,25 @@ class QuantumInspiredMultiObjectiveOptimizer:
|
|
25 |
self.population = [self._random_solution() for _ in range(population_size)]
|
26 |
self.pareto_front = []
|
27 |
|
28 |
-
def
|
29 |
return [random.uniform(-10, 10) for _ in range(self.dimension)]
|
30 |
|
31 |
-
def
|
32 |
return [x + np.random.normal(0, 1) * random.choice([-1, 1])
|
33 |
if random.random() < self.tunneling_prob else x
|
34 |
for x in solution]
|
35 |
|
36 |
-
def
|
37 |
return [(1 - self.entanglement_factor) * x + self.entanglement_factor * y
|
38 |
for x, y in zip(solution1, solution2)]
|
39 |
|
40 |
-
def
|
41 |
return [fn(solution) for fn in self.objective_fns]
|
42 |
|
43 |
-
def
|
44 |
return all(o1 <= o2 for o1, o2 in zip(obj1, obj2)) and any(o1 < o2 for o1, o2 in zip(obj1, obj2))
|
45 |
|
46 |
-
def
|
47 |
pareto = []
|
48 |
for candidate in scored_population:
|
49 |
if not any(self._dominates(other[1], candidate[1]) for other in scored_population if other != candidate):
|
|
|
25 |
self.population = [self._random_solution() for _ in range(population_size)]
|
26 |
self.pareto_front = []
|
27 |
|
28 |
+
def random_solution(self) -> List[float]:
|
29 |
return [random.uniform(-10, 10) for _ in range(self.dimension)]
|
30 |
|
31 |
+
def tunnel(self, solution: List[float]) -> List[float]:
|
32 |
return [x + np.random.normal(0, 1) * random.choice([-1, 1])
|
33 |
if random.random() < self.tunneling_prob else x
|
34 |
for x in solution]
|
35 |
|
36 |
+
def entangle(self, solution1: List[float], solution2: List[float]) -> List[float]:
|
37 |
return [(1 - self.entanglement_factor) * x + self.entanglement_factor * y
|
38 |
for x, y in zip(solution1, solution2)]
|
39 |
|
40 |
+
def evaluate(self, solution: List[float]) -> List[float]:
|
41 |
return [fn(solution) for fn in self.objective_fns]
|
42 |
|
43 |
+
def dominates(self, obj1: List[float], obj2: List[float]) -> bool:
|
44 |
return all(o1 <= o2 for o1, o2 in zip(obj1, obj2)) and any(o1 < o2 for o1, o2 in zip(obj1, obj2))
|
45 |
|
46 |
+
def pareto_selection(self, scored_population: List[Tuple[List[float], List[float]]]) -> List[Tuple[List[float], List[float]]]:
|
47 |
pareto = []
|
48 |
for candidate in scored_population:
|
49 |
if not any(self._dominates(other[1], candidate[1]) for other in scored_population if other != candidate):
|