Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion epde/operators/common/coeff_calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ def apply(self, objective : Equation, arguments : dict = None):
for weight_idx in range(len(weights)-1):
if weight_idx in nonzero_features_indexes:
weights[weight_idx] = valueable_weights[nonzero_features_indexes.index(weight_idx)]
weights[-1] = valueable_weights[-1]
weights[-1] = valueable_weights[-1]
nonzero_terms_mask = np.array([False if np.isclose(weight, 0) else True for weight in weights])
weights = np.array([item if keep else 0 for item, keep in zip(weights, nonzero_terms_mask)])
objective.weights_internal = np.array([item if keep else 0 for item, keep in zip(objective.weights_internal, nonzero_terms_mask[:-1])])
objective.weights_final_evald = True
objective.weights_final = weights

Expand Down
6 changes: 2 additions & 4 deletions epde/operators/multiobjective/moeadd_specific.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def apply(self, objective: ParetoLevels, arguments: dict):

while objective.unplaced_candidates:
offspring = objective.unplaced_candidates.pop()
attempt = 1;
attempt = 1
attempt_limit = self.params['attempt_limit']
temp_offspring = self.suboperators['chromosome_mutation'].apply(objective=offspring,
arguments=subop_args['chromosome_mutation'])
Expand All @@ -359,14 +359,12 @@ def apply(self, objective: ParetoLevels, arguments: dict):
self.suboperators['chromosome_fitness'].apply(objective=temp_offspring,
arguments=subop_args['chromosome_fitness'])

if all([not np.allclose(temp_offspring.obj_fun, solution.obj_fun) for solution in objective.population]):
if all([not np.array_equal(temp_offspring.obj_fun, solution.obj_fun) for solution in objective.population]):
self.suboperators['pareto_level_updater'].apply(objective=(temp_offspring, objective),
arguments=subop_args['pareto_level_updater'])
break
elif attempt >= attempt_limit:
# print('The algorithm had issues with generating unique offsprings.')
temp_offspring.create()
# temp_offspring.reset_state()
attempt = 1
self.suboperators['chromosome_mutation'].apply(objective=temp_offspring,
arguments=subop_args['chromosome_mutation'])
Expand Down
10 changes: 5 additions & 5 deletions epde/operators/multiobjective/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def apply(self, objective : SoEq, arguments : dict): # TODO: add setter for best

altered_objective.vals.replace_gene(gene_key = eq_key, value = altered_eq)

for param_key in params_keys:
altered_param = self.suboperators['param_mutation'].apply(altered_objective.vals[param_key],
subop_args['param_mutation'])
altered_objective.vals.replace_gene(gene_key = param_key, value = altered_param)
altered_objective.vals.pass_parametric_gene(key = param_key, value = altered_param)
for param_key in params_keys:
altered_param = self.suboperators['param_mutation'].apply(altered_objective.vals[param_key],
subop_args['param_mutation'])
altered_objective.vals.replace_gene(gene_key = param_key, value = altered_param)
altered_objective.vals.pass_parametric_gene(key = param_key, value = altered_param)

altered_objective.reset_state() # Использовать ли reset_right_part
return altered_objective
Expand Down
8 changes: 4 additions & 4 deletions epde/optimizers/moeadd/moeadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,18 @@ def delete_point(self, point):
for level in self.levels:
temp = []
for element in level:
if element != point or element in history:
if not np.array_equal(element.obj_fun, point.obj_fun) or any(np.array_equal(element.obj_fun, h) for h in history):
temp.append(element)
history.append(element)
history.append(element.obj_fun)
if not len(temp) == 0:
new_levels.append(temp)

population_cleared = []
history = []
for elem in self.population:
if elem != point or elem in history:
if not np.array_equal(elem.obj_fun, point.obj_fun) or any(np.array_equal(elem.obj_fun, h) for h in history):
population_cleared.append(elem)
history.append(elem)
history.append(elem.obj_fun)

if len(population_cleared) != sum([len(level) for level in new_levels]):
print(len(population_cleared), len(self.population), sum([len(level) for level in new_levels]))
Expand Down