Skip to content

Commit d9b6754

Browse files
authored
Merge pull request #58 from Gromwud/main
Bugfixes
2 parents df04923 + 76da087 commit d9b6754

5 files changed

Lines changed: 26 additions & 23 deletions

File tree

epde/operators/common/fitness.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,14 @@ def apply(self, objective: Equation, arguments: dict, force_out_of_place: bool =
202202
eq_window_weights.append(valuable_weights)
203203
std = np.array(eq_window_weights).std(axis=0, ddof=1)
204204
mu = np.array(eq_window_weights).mean(axis=0)
205-
scale = []
206-
for feature in range(features.shape[-1]):
207-
scale.append(feature_window[:, feature] ** 2 / (feature_window[:, feature] ** 2 + target_window ** 2))
208-
scale = np.array(scale).mean(axis=1)
209-
eq_cv = np.sqrt(std ** 2 / (std ** 2 + mu ** 2) * scale)
205+
# scale = []
206+
# for feature in range(features.shape[-1]):
207+
# # scale.append(feature_window[:, feature] ** 2 / (feature_window[:, feature] ** 2 + target_window ** 2))
208+
# scale.append(np.linalg.norm(feature_window[:, feature] * mu[feature], ord=2) / np.linalg.norm(target_window, ord=2))
209+
# scale = np.array(scale) / sum(scale)
210+
# eq_cv = np.sqrt(std ** 2 / (std ** 2 + mu ** 2) * scale)
211+
# eq_cv = np.sqrt(std ** 2 / (std ** 2 + mu ** 2)) * scale
212+
eq_cv = std ** 2 / (mu ** 2)
210213
lr += np.nan_to_num(eq_cv).sum()
211214

212215
lr = lr / (len(objective.structure) - 1) / target_vals.ndim

epde/operators/common/sparsity.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def get_cv(self, weights):
3131
std = np.array(weights).std(axis=0, ddof=1)
3232
mu = np.array(weights).mean(axis=0)
3333
# cv = std ** 2 / (std ** 2 + mu ** 2)
34-
cv = np.sqrt(std ** 2 / (std ** 2 + mu ** 2))
34+
# cv = np.sqrt(std ** 2 / (std ** 2 + mu ** 2))
35+
cv = std ** 2 / (mu ** 2)
3536
return cv
3637

3738
def calculate_weights(self, X, y):

epde/operators/multiobjective/moeadd_specific.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def apply_deprecated(self, objective : Tuple[Union[SoEq, ParetoLevels]], argumen
168168

169169
# TODO: Init normalizer here!
170170
# print('objective is ', objective)
171-
# objective[1].set_normalizer()
171+
objective[1].set_normalizer()
172172

173173
objective[1].update(objective[0]) #levels_updated = ndl_update(offspring, levels)
174174
if len(objective[1].levels) == 1:
@@ -434,9 +434,9 @@ def apply(self, objective: ParetoLevels, arguments: dict):
434434
while objective.unplaced_candidates:
435435
offspring = objective.unplaced_candidates.pop()
436436
attempt = 0
437-
replaced = 0
437+
# replaced = 0
438438
mutation_attempt_limit = self.params['mutation_attempt_limit']
439-
offspring_attempt_limit = self.params['offspring_attempt_limit']
439+
# offspring_attempt_limit = self.params['offspring_attempt_limit']
440440
# self.suboperators['sparsity'].apply(objective=offspring,
441441
# arguments=subop_args['sparsity'])
442442
temp_offspring = deepcopy(offspring)
@@ -464,13 +464,13 @@ def apply(self, objective: ParetoLevels, arguments: dict):
464464
objective.history.add(system)
465465
print(temp_offspring.obj_fun)
466466
break
467-
elif replaced == offspring_attempt_limit:
467+
elif attempt == mutation_attempt_limit:
468468
print("Could not generate unique offspring")
469469
break
470-
elif attempt == mutation_attempt_limit:
471-
temp_offspring = deepcopy(offspring)
472-
replaced += 1
473-
attempt = 0
470+
# elif attempt == mutation_attempt_limit:
471+
# temp_offspring = deepcopy(offspring)
472+
# replaced += 1
473+
# attempt = 0
474474
attempt += 1
475475
return objective
476476

epde/operators/multiobjective/mutations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ def apply(self, objective : SoEq, arguments : dict): # TODO: add setter for best
3434
# altered_eq = self.suboperators['equation_mutation'].apply(altered_objective.vals[eq_key],
3535
# subop_args['equation_mutation'])
3636
for eq_key in eqs_keys:
37-
affected_by_mutation = np.random.random() < (self.params['indiv_mutation_prob'] / len(eq_key))
37+
affected_by_mutation = np.random.random() < (self.params['indiv_mutation_prob'] / len(eqs_keys))
3838
if affected_by_mutation:
3939
altered_eq = self.suboperators['equation_mutation'].apply(altered_objective.vals[eq_key],
4040
subop_args['equation_mutation'])
4141

42-
altered_objective.vals.replace_gene(gene_key = eq_key, value = altered_eq)
42+
altered_objective.vals.replace_gene(gene_key = eq_key, value = altered_eq)
4343

4444
for param_key in params_keys:
4545
altered_param = self.suboperators['param_mutation'].apply(altered_objective.vals[param_key],

epde/operators/multiobjective/variation.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,14 @@ def apply(self, objective : ParetoLevels, arguments : dict):
8383
new_system_2 = deepcopy(crossover_pool[pair_idx, 1])
8484
# new_system_1.reset_state(False); new_system_2.reset_state()
8585

86-
new_system_1, new_system_2 = self.suboperators['chromosome_crossover'].apply(objective = (new_system_1, new_system_2),
87-
86+
new_system_1, new_system_2 = self.suboperators['chromosome_crossover'].apply(objective = (new_system_1, new_system_2),
8887
arguments = subop_args['chromosome_crossover'])
8988

90-
if len(new_system_1.vars_to_describe) > 1 and np.random.random() < 0.2:
91-
key = np.random.choice(new_system_1.vars_to_describe)
92-
temp = deepcopy(new_system_1.vals.chromosome[key])
93-
new_system_1.vals.chromosome[key] = new_system_2.vals.chromosome[key]
94-
new_system_2.vals.chromosome[key] = temp
89+
# if len(new_system_1.vars_to_describe) > 1 and np.random.random() < 0.2:
90+
# key = np.random.choice(new_system_1.vars_to_describe)
91+
# temp = deepcopy(new_system_1.vals.chromosome[key])
92+
# new_system_1.vals.chromosome[key] = new_system_2.vals.chromosome[key]
93+
# new_system_2.vals.chromosome[key] = temp
9594

9695
offsprings.extend([new_system_1, new_system_2])
9796

0 commit comments

Comments
 (0)