Skip to content

Commit df9681f

Browse files
authored
Merge pull request #48 from Gromwud/main
cumulitive update
2 parents 3f5e5e8 + 94de954 commit df9681f

5 files changed

Lines changed: 46 additions & 34 deletions

File tree

epde/operators/common/fitness.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,20 @@ def apply(self, objective: Equation, arguments: dict, force_out_of_place: bool =
318318

319319
lr += eq_cv.mean()
320320

321+
fitness_value = round(fitness_value, 8)
322+
lr = round(lr / target_vals.ndim, 8)
323+
324+
# if lr > self.params['max_lr']:
325+
# self.params['max_lr'] = lr
326+
# if fitness_value > self.params['max_lp']:
327+
# self.params['max_lp'] = fitness_value
328+
321329
objective.fitness_calculated = True
322330
objective.fitness_value = fitness_value
323331
objective.stability_calculated = True
324332
objective.coefficients_stability = lr
325333

334+
326335
def feature_reshape(self, features_vals):
327336
features = features_vals[0]
328337
if len(features_vals) > 1:

epde/operators/multiobjective/moeadd_specific.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ def penalty_based_intersection(sol_obj, weight, ideal_obj,
5858
Normalizer for solution objective functions.
5959
6060
'''
61-
print(f'Objective before normalization: {sol_obj.obj_fun} for normalizer {obj_normalizer}')
61+
# print(f'Objective before normalization: {sol_obj.obj_fun} for normalizer {obj_normalizer}')
6262
solution_objective = sol_obj.obj_fun if obj_normalizer is None else obj_normalizer(sol_obj.obj_fun)
63-
print(f'Objective after expected normalization: {solution_objective}')
63+
# print(f'Objective after expected normalization: {solution_objective}')
6464

6565
d_1 = np.dot((solution_objective - ideal_obj), weight) / np.linalg.norm(weight)
6666
d_2 = np.linalg.norm(solution_objective - (ideal_obj + d_1 * weight/np.linalg.norm(weight)))
@@ -378,32 +378,38 @@ def apply(self, objective: ParetoLevels, arguments: dict):
378378
offspring = objective.unplaced_candidates.pop()
379379
attempt = 1
380380
attempt_limit = self.params['attempt_limit']
381-
temp_offspring = self.suboperators['chromosome_mutation'].apply(objective=offspring,
382-
arguments=subop_args['chromosome_mutation'])
381+
temp_offspring = offspring
383382
replaced = 0
384383
while True:
384+
# temp_offspring = self.suboperators['chromosome_mutation'].apply(objective=offspring,
385+
# arguments=subop_args['chromosome_mutation'])
386+
temp_offspring = self.suboperators['chromosome_mutation'].apply(objective=temp_offspring,
387+
arguments=subop_args[
388+
'chromosome_mutation'])
389+
# temp_offspring.reset_state()
385390
self.suboperators['right_part_selector'].apply(objective=temp_offspring,
386391
arguments=subop_args['right_part_selector'])
387392
self.suboperators['chromosome_fitness'].apply(objective=temp_offspring,
388393
arguments=subop_args['chromosome_fitness'])
389394

390395
if tuple(temp_offspring.obj_fun) not in objective.history:
396+
# for obj_idx, obj in enumerate(temp_offspring.obj_fun):
397+
# obj = obj / objective.max_obj[obj_idx]
391398
self.suboperators['pareto_level_updater'].apply(objective=(temp_offspring, objective),
392399
arguments=subop_args['pareto_level_updater'])
393400
objective.history.add(tuple(temp_offspring.obj_fun))
401+
# print(tuple(temp_offspring.obj_fun))
394402
break
395-
elif replaced >= attempt_limit:
396-
print("Allowed replication")
397-
self.suboperators['pareto_level_updater'].apply(objective=(temp_offspring, objective),
398-
arguments=subop_args['pareto_level_updater'])
403+
# return objective
404+
elif replaced == attempt_limit:
405+
print("Could not generate unique offspring")
399406
break
400-
elif attempt >= attempt_limit:
401-
temp_offspring.create()
407+
elif attempt == attempt_limit:
408+
# temp_offspring.create()
409+
temp_offspring = offspring
410+
# temp_offspring.reset_state()
402411
replaced += 1
403-
attempt = 1
404-
405-
self.suboperators['chromosome_mutation'].apply(objective=temp_offspring,
406-
arguments=subop_args['chromosome_mutation'])
412+
attempt = 0
407413
attempt += 1
408414
return objective
409415

epde/operators/multiobjective/mutations.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,15 @@ def apply(self, objective : tuple, arguments : dict): #term_idx, equation):
109109
110110
"""
111111
self_args, subop_args = self.parse_suboperator_args(arguments = arguments)
112-
113-
create_derivs = bool(objective[1].structure[objective[0]].descr_variable_marker)
114-
115-
new_term = Term(objective[1].pool, mandatory_family = objective[1].structure[objective[0]].descr_variable_marker,
116-
create_derivs=create_derivs,
117-
max_factors_in_term = objective[1].metaparameters['max_factors_in_term']['value'])
118-
while not (check_uniqueness(new_term, objective[1].structure[:objective[0]] + objective[1].structure[objective[0]+1:]) and
119-
new_term.contains_meaningful()):
120-
new_term = Term(objective[1].pool, mandatory_family = objective[1].structure[objective[0]].descr_variable_marker,
121-
create_derivs=create_derivs,
122-
max_factors_in_term = objective[1].metaparameters['max_factors_in_term']['value'])
123-
new_term.use_cache()
112+
113+
objective[1].structure[objective[0]].randomize()
114+
objective[1].structure[objective[0]].reset_saved_state()
115+
while not objective[1].structure.count(objective[1].structure[objective[0]]) == 1:
116+
objective[1].structure[objective[0]].randomize()
117+
objective[1].structure[objective[0]].reset_saved_state()
118+
# objective[1].structure[objective[0]].use_cache()
124119
# print(f'CREATED DURING MUTATION: {new_term.name}, while contatining {objective[1].structure[objective[0]].descr_variable_marker}')
125-
return new_term
120+
return objective[1].structure[objective[0]]
126121

127122
def use_default_tags(self):
128123
self._tags = {'mutation', 'term level', 'exploration', 'no suboperators'}

epde/operators/multiobjective/variation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def apply(self, objective : tuple, arguments : dict):
109109
objective[1].vals[eq_key]),
110110
arguments = subop_args['equation_crossover'])
111111
objective[0].vals.replace_gene(gene_key = eq_key, value = temp_eq_1)
112-
offspring_2.vals.replace_gene(gene_key = eq_key, value = temp_eq_2)
112+
objective[1].vals.replace_gene(gene_key = eq_key, value = temp_eq_2)
113113

114114
for param_key in params_keys:
115115
temp_param_1, temp_param_2 = self.suboperators['param_crossover'].apply(objective = (objective[0].vals[param_key],

epde/optimizers/moeadd/moeadd.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,22 +175,24 @@ def delete_point(self, point):
175175
None
176176
"""
177177
new_levels = []
178-
history = []
178+
deleted = False
179179
for level in self.levels:
180180
temp = []
181181
for element in level:
182-
if not np.allclose(element.obj_fun, point.obj_fun) or any(np.allclose(element.obj_fun, h) for h in history):
182+
if not np.allclose(element.obj_fun, point.obj_fun) or deleted:
183183
temp.append(element)
184-
history.append(element.obj_fun)
184+
else:
185+
deleted = True
185186
if not len(temp) == 0:
186187
new_levels.append(temp)
187188

188189
population_cleared = []
189-
history = []
190+
deleted = False
190191
for elem in self.population:
191-
if not np.allclose(elem.obj_fun, point.obj_fun) or any(np.allclose(elem.obj_fun, h) for h in history):
192+
if not np.allclose(elem.obj_fun, point.obj_fun) or deleted:
192193
population_cleared.append(elem)
193-
history.append(elem.obj_fun)
194+
else:
195+
deleted = True
194196

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

0 commit comments

Comments
 (0)