Skip to content

Commit f3daf74

Browse files
committed
objectives update
1 parent b7350a5 commit f3daf74

5 files changed

Lines changed: 16 additions & 13 deletions

File tree

epde/eq_mo_objectives.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def equation_fitness(system, equation_key = None):
3636
else:
3737
for equation in system.vals:
3838
assert equation.fitness_value
39-
res = np.mean([equation.fitness_value for equation in system.vals])
39+
# res = np.mean([equation.fitness_value for equation in system.vals])
40+
res = tuple([equation.fitness_value for equation in system.vals])
4041
return res
4142

4243

@@ -109,7 +110,8 @@ def equation_terms_stability(system, equation_key = None):
109110
else:
110111
for equation in system.vals:
111112
assert equation.stability_calculated
112-
res = np.mean([equation.coefficients_stability for equation in system.vals])
113+
# res = np.mean([equation.coefficients_stability for equation in system.vals])
114+
res = tuple([equation.coefficients_stability for equation in system.vals])
113115
return res
114116

115117
def equation_aic(system, equation_key):

epde/operators/multiobjective/moeadd_specific.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ def penalty_based_intersection(sol_obj, weight, ideal_obj,
6262
# print(f'Objective before normalization: {sol_obj.obj_fun} for normalizer {obj_normalizer}')
6363
solution_objective = sol_obj.obj_fun if obj_normalizer is None else obj_normalizer(sol_obj.obj_fun)
6464
# print(f'Objective after expected normalization: {solution_objective}')
65-
66-
d_1 = np.dot((solution_objective - ideal_obj), weight) / np.linalg.norm(weight)
67-
d_2 = np.linalg.norm(solution_objective - (ideal_obj + d_1 * weight/np.linalg.norm(weight)))
65+
66+
weight_full = [item for item in weight for _ in sol_obj.vals]
67+
ideal_obj_full = [item for item in ideal_obj for _ in sol_obj.vals]
68+
69+
d_1 = np.dot((solution_objective - ideal_obj_full), weight_full) / np.linalg.norm(weight_full)
70+
d_2 = np.linalg.norm(solution_objective - (ideal_obj_full + np.multiply(d_1, weight_full) / np.linalg.norm(weight_full)))
6871
return d_1 + penalty_factor * d_2
6972

7073

epde/optimizers/moeadd/moeadd.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,7 @@ def __init__(self, population_instruct, pop_size, solution_params,
366366
raise TypeError(f'Incorrect type of the population passed. Expected ParetoLevels object, instead got \
367367
{type(passed_population)}')
368368
self.pareto_levels = passed_population
369-
370-
self.weights = []
371-
weights_size = len(population[0].obj_funs) #np.empty((pop_size, len(optimized_functionals)))
369+
weights_size = len(best_sol_vals) #np.empty((pop_size, len(optimized_functionals)))
372370
# weights_size = len(set([fun.func for fun in population[0].obj_funs]))
373371
self.weights = np.array(self.weights_generation_new(weights_size, H))
374372

@@ -379,7 +377,7 @@ def __init__(self, population_instruct, pop_size, solution_params,
379377
list(zip(np.arange(weights_num), [np.linalg.norm(self.weights[weights_idx, :] - self.weights[weights_idx_inner, :]) for weights_idx_inner in np.arange(weights_num)])),
380378
key = lambda pair: pair[1])][:neighbors_number+1]) # срез листа - задаёт регион "близости"
381379

382-
self.best_obj = None
380+
self.best_obj = best_sol_vals
383381
self._hist = []
384382

385383
def abbreviated_search(self, population, sorting_method, update_method):

epde/optimizers/moeadd/solution_template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def get_domain_idx(solution, weights) -> int:
3030
if type(solution) == np.ndarray:
3131
return np.fromiter(map(lambda x: acute_angle(x, solution), weights), dtype=float).argmin()
3232
elif type(solution.obj_fun) == np.ndarray:
33-
return np.fromiter(map(lambda x: acute_angle(x, solution.obj_fun), weights), dtype=float).argmin()
33+
return np.fromiter(map(lambda x: acute_angle([item for item in x for _ in solution.vals], solution.obj_fun), weights), dtype=float).argmin()
3434
else:
3535
raise ValueError(
3636
'Can not detect the vector of objective function for solution')

epde/optimizers/moeadd/supplementary.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ def check_dominance(target, compared_with) -> bool:
5252
flag = False
5353

5454
sdn = 5 # Number of significant digits
55-
for obj_fun_idx in range(len(target.obj_fun)):
55+
for obj_fun_idx in range(len(target.obj_fun.reshape(-1))):
5656
# if rts(target.obj_fun[obj_fun_idx], sdn) <= rts(compared_with.obj_fun[obj_fun_idx], sdn):
5757
# if rts(target.obj_fun[obj_fun_idx], sdn) < rts(compared_with.obj_fun[obj_fun_idx], sdn):
58-
if target.obj_fun[obj_fun_idx] <= compared_with.obj_fun[obj_fun_idx]:
59-
if target.obj_fun[obj_fun_idx] < compared_with.obj_fun[obj_fun_idx]:
58+
if target.obj_fun.reshape(-1)[obj_fun_idx] <= compared_with.obj_fun.reshape(-1)[obj_fun_idx]:
59+
if target.obj_fun.reshape(-1)[obj_fun_idx] < compared_with.obj_fun.reshape(-1)[obj_fun_idx]:
6060
flag = True
6161
else:
6262
return False

0 commit comments

Comments
 (0)