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
13 changes: 8 additions & 5 deletions epde/operators/common/fitness.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,14 @@ def apply(self, objective: Equation, arguments: dict, force_out_of_place: bool =
eq_window_weights.append(valuable_weights)
std = np.array(eq_window_weights).std(axis=0, ddof=1)
mu = np.array(eq_window_weights).mean(axis=0)
scale = []
for feature in range(features.shape[-1]):
scale.append(feature_window[:, feature] ** 2 / (feature_window[:, feature] ** 2 + target_window ** 2))
scale = np.array(scale).mean(axis=1)
eq_cv = np.sqrt(std ** 2 / (std ** 2 + mu ** 2) * scale)
# scale = []
# for feature in range(features.shape[-1]):
# # scale.append(feature_window[:, feature] ** 2 / (feature_window[:, feature] ** 2 + target_window ** 2))
# scale.append(np.linalg.norm(feature_window[:, feature] * mu[feature], ord=2) / np.linalg.norm(target_window, ord=2))
# scale = np.array(scale) / sum(scale)
# eq_cv = np.sqrt(std ** 2 / (std ** 2 + mu ** 2) * scale)
# eq_cv = np.sqrt(std ** 2 / (std ** 2 + mu ** 2)) * scale
eq_cv = std ** 2 / (mu ** 2)
lr += np.nan_to_num(eq_cv).sum()

lr = lr / (len(objective.structure) - 1) / target_vals.ndim
Expand Down
3 changes: 2 additions & 1 deletion epde/operators/common/sparsity.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def get_cv(self, weights):
std = np.array(weights).std(axis=0, ddof=1)
mu = np.array(weights).mean(axis=0)
# cv = std ** 2 / (std ** 2 + mu ** 2)
cv = np.sqrt(std ** 2 / (std ** 2 + mu ** 2))
# cv = np.sqrt(std ** 2 / (std ** 2 + mu ** 2))
cv = std ** 2 / (mu ** 2)
return cv

def calculate_weights(self, X, y):
Expand Down
16 changes: 8 additions & 8 deletions epde/operators/multiobjective/moeadd_specific.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def apply_deprecated(self, objective : Tuple[Union[SoEq, ParetoLevels]], argumen

# TODO: Init normalizer here!
# print('objective is ', objective)
# objective[1].set_normalizer()
objective[1].set_normalizer()

objective[1].update(objective[0]) #levels_updated = ndl_update(offspring, levels)
if len(objective[1].levels) == 1:
Expand Down Expand Up @@ -434,9 +434,9 @@ def apply(self, objective: ParetoLevels, arguments: dict):
while objective.unplaced_candidates:
offspring = objective.unplaced_candidates.pop()
attempt = 0
replaced = 0
# replaced = 0
mutation_attempt_limit = self.params['mutation_attempt_limit']
offspring_attempt_limit = self.params['offspring_attempt_limit']
# offspring_attempt_limit = self.params['offspring_attempt_limit']
# self.suboperators['sparsity'].apply(objective=offspring,
# arguments=subop_args['sparsity'])
temp_offspring = deepcopy(offspring)
Expand Down Expand Up @@ -464,13 +464,13 @@ def apply(self, objective: ParetoLevels, arguments: dict):
objective.history.add(system)
print(temp_offspring.obj_fun)
break
elif replaced == offspring_attempt_limit:
elif attempt == mutation_attempt_limit:
print("Could not generate unique offspring")
break
elif attempt == mutation_attempt_limit:
temp_offspring = deepcopy(offspring)
replaced += 1
attempt = 0
# elif attempt == mutation_attempt_limit:
# temp_offspring = deepcopy(offspring)
# replaced += 1
# attempt = 0
attempt += 1
return objective

Expand Down
4 changes: 2 additions & 2 deletions epde/operators/multiobjective/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ def apply(self, objective : SoEq, arguments : dict): # TODO: add setter for best
# altered_eq = self.suboperators['equation_mutation'].apply(altered_objective.vals[eq_key],
# subop_args['equation_mutation'])
for eq_key in eqs_keys:
affected_by_mutation = np.random.random() < (self.params['indiv_mutation_prob'] / len(eq_key))
affected_by_mutation = np.random.random() < (self.params['indiv_mutation_prob'] / len(eqs_keys))
if affected_by_mutation:
altered_eq = self.suboperators['equation_mutation'].apply(altered_objective.vals[eq_key],
subop_args['equation_mutation'])

altered_objective.vals.replace_gene(gene_key = eq_key, value = altered_eq)
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],
Expand Down
13 changes: 6 additions & 7 deletions epde/operators/multiobjective/variation.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,14 @@ def apply(self, objective : ParetoLevels, arguments : dict):
new_system_2 = deepcopy(crossover_pool[pair_idx, 1])
# new_system_1.reset_state(False); new_system_2.reset_state()

new_system_1, new_system_2 = self.suboperators['chromosome_crossover'].apply(objective = (new_system_1, new_system_2),

new_system_1, new_system_2 = self.suboperators['chromosome_crossover'].apply(objective = (new_system_1, new_system_2),
arguments = subop_args['chromosome_crossover'])

if len(new_system_1.vars_to_describe) > 1 and np.random.random() < 0.2:
key = np.random.choice(new_system_1.vars_to_describe)
temp = deepcopy(new_system_1.vals.chromosome[key])
new_system_1.vals.chromosome[key] = new_system_2.vals.chromosome[key]
new_system_2.vals.chromosome[key] = temp
# if len(new_system_1.vars_to_describe) > 1 and np.random.random() < 0.2:
# key = np.random.choice(new_system_1.vars_to_describe)
# temp = deepcopy(new_system_1.vals.chromosome[key])
# new_system_1.vals.chromosome[key] = new_system_2.vals.chromosome[key]
# new_system_2.vals.chromosome[key] = temp

offsprings.extend([new_system_1, new_system_2])

Expand Down