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
9 changes: 9 additions & 0 deletions epde/operators/common/fitness.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,20 @@ def apply(self, objective: Equation, arguments: dict, force_out_of_place: bool =

lr += eq_cv.mean()

fitness_value = round(fitness_value, 8)
lr = round(lr / target_vals.ndim, 8)

# if lr > self.params['max_lr']:
# self.params['max_lr'] = lr
# if fitness_value > self.params['max_lp']:
# self.params['max_lp'] = fitness_value

objective.fitness_calculated = True
objective.fitness_value = fitness_value
objective.stability_calculated = True
objective.coefficients_stability = lr


def feature_reshape(self, features_vals):
features = features_vals[0]
if len(features_vals) > 1:
Expand Down
34 changes: 20 additions & 14 deletions epde/operators/multiobjective/moeadd_specific.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def penalty_based_intersection(sol_obj, weight, ideal_obj,
Normalizer for solution objective functions.

'''
print(f'Objective before normalization: {sol_obj.obj_fun} for normalizer {obj_normalizer}')
# print(f'Objective before normalization: {sol_obj.obj_fun} for normalizer {obj_normalizer}')
solution_objective = sol_obj.obj_fun if obj_normalizer is None else obj_normalizer(sol_obj.obj_fun)
print(f'Objective after expected normalization: {solution_objective}')
# print(f'Objective after expected normalization: {solution_objective}')

d_1 = np.dot((solution_objective - ideal_obj), weight) / np.linalg.norm(weight)
d_2 = np.linalg.norm(solution_objective - (ideal_obj + d_1 * weight/np.linalg.norm(weight)))
Expand Down Expand Up @@ -378,32 +378,38 @@ def apply(self, objective: ParetoLevels, arguments: dict):
offspring = objective.unplaced_candidates.pop()
attempt = 1
attempt_limit = self.params['attempt_limit']
temp_offspring = self.suboperators['chromosome_mutation'].apply(objective=offspring,
arguments=subop_args['chromosome_mutation'])
temp_offspring = offspring
replaced = 0
while True:
# temp_offspring = self.suboperators['chromosome_mutation'].apply(objective=offspring,
# arguments=subop_args['chromosome_mutation'])
temp_offspring = self.suboperators['chromosome_mutation'].apply(objective=temp_offspring,
arguments=subop_args[
'chromosome_mutation'])
# temp_offspring.reset_state()
self.suboperators['right_part_selector'].apply(objective=temp_offspring,
arguments=subop_args['right_part_selector'])
self.suboperators['chromosome_fitness'].apply(objective=temp_offspring,
arguments=subop_args['chromosome_fitness'])

if tuple(temp_offspring.obj_fun) not in objective.history:
# for obj_idx, obj in enumerate(temp_offspring.obj_fun):
# obj = obj / objective.max_obj[obj_idx]
self.suboperators['pareto_level_updater'].apply(objective=(temp_offspring, objective),
arguments=subop_args['pareto_level_updater'])
objective.history.add(tuple(temp_offspring.obj_fun))
# print(tuple(temp_offspring.obj_fun))
break
elif replaced >= attempt_limit:
print("Allowed replication")
self.suboperators['pareto_level_updater'].apply(objective=(temp_offspring, objective),
arguments=subop_args['pareto_level_updater'])
# return objective
elif replaced == attempt_limit:
print("Could not generate unique offspring")
break
elif attempt >= attempt_limit:
temp_offspring.create()
elif attempt == attempt_limit:
# temp_offspring.create()
temp_offspring = offspring
# temp_offspring.reset_state()
replaced += 1
attempt = 1

self.suboperators['chromosome_mutation'].apply(objective=temp_offspring,
arguments=subop_args['chromosome_mutation'])
attempt = 0
attempt += 1
return objective

Expand Down
21 changes: 8 additions & 13 deletions epde/operators/multiobjective/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,15 @@ def apply(self, objective : tuple, arguments : dict): #term_idx, equation):

"""
self_args, subop_args = self.parse_suboperator_args(arguments = arguments)

create_derivs = bool(objective[1].structure[objective[0]].descr_variable_marker)

new_term = Term(objective[1].pool, mandatory_family = objective[1].structure[objective[0]].descr_variable_marker,
create_derivs=create_derivs,
max_factors_in_term = objective[1].metaparameters['max_factors_in_term']['value'])
while not (check_uniqueness(new_term, objective[1].structure[:objective[0]] + objective[1].structure[objective[0]+1:]) and
new_term.contains_meaningful()):
new_term = Term(objective[1].pool, mandatory_family = objective[1].structure[objective[0]].descr_variable_marker,
create_derivs=create_derivs,
max_factors_in_term = objective[1].metaparameters['max_factors_in_term']['value'])
new_term.use_cache()

objective[1].structure[objective[0]].randomize()
objective[1].structure[objective[0]].reset_saved_state()
while not objective[1].structure.count(objective[1].structure[objective[0]]) == 1:
objective[1].structure[objective[0]].randomize()
objective[1].structure[objective[0]].reset_saved_state()
# objective[1].structure[objective[0]].use_cache()
# print(f'CREATED DURING MUTATION: {new_term.name}, while contatining {objective[1].structure[objective[0]].descr_variable_marker}')
return new_term
return objective[1].structure[objective[0]]

def use_default_tags(self):
self._tags = {'mutation', 'term level', 'exploration', 'no suboperators'}
Expand Down
2 changes: 1 addition & 1 deletion epde/operators/multiobjective/variation.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def apply(self, objective : tuple, arguments : dict):
objective[1].vals[eq_key]),
arguments = subop_args['equation_crossover'])
objective[0].vals.replace_gene(gene_key = eq_key, value = temp_eq_1)
offspring_2.vals.replace_gene(gene_key = eq_key, value = temp_eq_2)
objective[1].vals.replace_gene(gene_key = eq_key, value = temp_eq_2)

for param_key in params_keys:
temp_param_1, temp_param_2 = self.suboperators['param_crossover'].apply(objective = (objective[0].vals[param_key],
Expand Down
14 changes: 8 additions & 6 deletions epde/optimizers/moeadd/moeadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,24 @@ def delete_point(self, point):
None
"""
new_levels = []
history = []
deleted = False
for level in self.levels:
temp = []
for element in level:
if not np.allclose(element.obj_fun, point.obj_fun) or any(np.allclose(element.obj_fun, h) for h in history):
if not np.allclose(element.obj_fun, point.obj_fun) or deleted:
temp.append(element)
history.append(element.obj_fun)
else:
deleted = True
if not len(temp) == 0:
new_levels.append(temp)

population_cleared = []
history = []
deleted = False
for elem in self.population:
if not np.allclose(elem.obj_fun, point.obj_fun) or any(np.allclose(elem.obj_fun, h) for h in history):
if not np.allclose(elem.obj_fun, point.obj_fun) or deleted:
population_cleared.append(elem)
history.append(elem.obj_fun)
else:
deleted = True

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