Skip to content

Commit 74ffb49

Browse files
committed
Minor changes and fixes: mutation + lr criterion
1 parent 84547c9 commit 74ffb49

5 files changed

Lines changed: 13 additions & 10 deletions

File tree

epde/operators/common/fitness.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def apply(self, objective: Equation, arguments: dict, force_out_of_place: bool =
200200
for start_idx in range(0, num_horizons, step_size):
201201
end_idx = start_idx + window_size
202202
target_window = target_vals[start_idx:end_idx]
203-
if np.isclose(np.sqrt(np.mean(np.power(_, 2))), 0, atol=1e-10):
203+
if np.isclose(np.sqrt(np.mean(np.power(target_window, 2))), 0, atol=1e-10):
204204
window_stability = np.abs(np.std(target_window))
205205
else:
206206
window_stability = np.abs(np.std(target_window) / np.sqrt(np.mean(np.power(target_window, 2))))
@@ -241,7 +241,7 @@ def apply(self, objective: Equation, arguments: dict, force_out_of_place: bool =
241241
target_window = target_vals[start_idx:end_idx, :].reshape(-1)
242242
else:
243243
target_window = target_vals[:, start_idx:end_idx].reshape(-1)
244-
if np.isclose(np.sqrt(np.mean(np.power(_, 2))), 0, atol=1e-10):
244+
if np.isclose(np.sqrt(np.mean(np.power(target_window, 2))), 0, atol=1e-10):
245245
window_stability = np.abs(np.std(target_window))
246246
else:
247247
window_stability = np.abs(np.std(target_window) / np.sqrt(np.mean(np.power(target_window, 2))))
@@ -285,7 +285,7 @@ def apply(self, objective: Equation, arguments: dict, force_out_of_place: bool =
285285
target_window = target_vals[:, start_idx:end_idx, :].reshape(-1)
286286
else:
287287
target_window = target_vals[:, :, start_idx:end_idx].reshape(-1)
288-
if np.isclose(np.sqrt(np.mean(np.power(_, 2))), 0, atol=1e-10):
288+
if np.isclose(np.sqrt(np.mean(np.power(target_window, 2))), 0, atol=1e-10):
289289
window_stability = np.abs(np.std(target_window))
290290
else:
291291
window_stability = np.abs(np.std(target_window) / np.sqrt(np.mean(np.power(target_window, 2))))

epde/operators/multiobjective/mutations.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def apply(self, objective : SoEq, arguments : dict): # TODO: add setter for best
3030
altered_objective = deepcopy(objective)
3131

3232
eqs_keys = altered_objective.vals.equation_keys; params_keys = altered_objective.vals.params_keys
33-
affected_by_mutation = True
33+
affected_by_mutation = np.random.random() < self.params['indiv_mutation_prob']
3434

3535
if affected_by_mutation:
3636
for eq_key in eqs_keys:
@@ -56,7 +56,7 @@ class EquationMutation(CompoundOperator):
5656
key = 'EquationMutation'
5757
@HistoryExtender(f'\n -> mutating equation', 'ba')
5858
def apply(self, objective : Equation, arguments : dict):
59-
self_args, subop_args = self.parse_suboperator_args(arguments = arguments)
59+
self_args, subop_args = self.parse_suboperator_args(arguments = arguments)
6060

6161
for term_idx in range(objective.n_immutable, len(objective.structure)):
6262
if np.random.uniform(0, 1) <= self.params['r_mutation']:
@@ -213,7 +213,8 @@ def get_basic_mutation(mutation_params):
213213
metaparameter_mutation = MetaparameterMutation(['std', 'mean'])
214214
add_kwarg_to_operator(operator = metaparameter_mutation)
215215

216-
chromosome_mutation = SystemMutation([])
216+
chromosome_mutation = SystemMutation(['indiv_mutation_prob'])
217+
add_kwarg_to_operator(operator = chromosome_mutation)
217218

218219
equation_mutation.set_suboperators(operators = {'mutation' : term_mutation})#, [term_param_mutation, ]
219220
# probas = {'equation_crossover' : [0.0, 1.0]})

epde/operators/singleobjective/mutations.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ def get_multiobjective_mutation(mutation_params): # TODO: rename function calls
221221
add_kwarg_to_operator(operator = metaparameter_mutation)
222222

223223
chromosome_mutation = SystemMutation(['indiv_mutation_prob'])
224+
add_kwarg_to_operator(operator = chromosome_mutation)
224225

225226
equation_mutation.set_suboperators(operators = {'mutation' : term_mutation})
226227

@@ -239,7 +240,8 @@ def get_singleobjective_mutation(mutation_params):
239240
add_kwarg_to_operator(operator = equation_mutation)
240241

241242
chromosome_mutation = SystemMutation(['indiv_mutation_prob'])
242-
243+
add_kwarg_to_operator(operator = chromosome_mutation)
244+
243245
equation_mutation.set_suboperators(operators = {'mutation' : term_mutation})
244246

245247
chromosome_mutation.set_suboperators(operators = {'equation_mutation' : equation_mutation})

epde/operators/utils/parameters/default_parameters_multi_objective.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
"term_param_proportion" : 0.4
5252
},
5353
"SystemMutation" : {
54-
55-
},
54+
"indiv_mutation_prob" : 0.7
55+
},
5656
"EquationMutation" : {
5757
"r_mutation" : 0.6
5858
},

epde/operators/utils/parameters/default_parameters_single_objective.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"term_param_proportion" : 0.4
3434
},
3535
"SystemMutation" : {
36-
36+
"indiv_mutation_prob" : 0.7
3737
},
3838
"EquationMutation" : {
3939
"r_mutation" : 0.6

0 commit comments

Comments
 (0)