Skip to content

Commit 9fbd087

Browse files
authored
Merge pull request #39 from Gromwud/main
New lr formula and sparsity initial value
2 parents b55c710 + fca92ce commit 9fbd087

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

epde/interface/equation_translator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def __init__(self, lp_terms : Union[list, tuple, dict], rp_term : Union[list, tu
216216
metaparameters={'terms_number': {'optimizable': False, 'value': len(term_list)},
217217
'max_factors_in_term': {'optimizable': False, 'value': max_factors}}
218218
for var_key in all_vars:
219-
metaparameters[('sparsity', var_key)] = {'optimizable': True, 'value': 1.}
219+
metaparameters[('sparsity', var_key)] = {'optimizable': True, 'value': 0.}
220220

221221

222222
self.equation = Equation(pool=pool, basic_structure=terms_aggregated,

epde/operators/common/fitness.py

Lines changed: 6 additions & 6 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-
eq_window_weights.append(np.abs(np.std(target_window) / np.mean(target_window)))
203+
eq_window_weights.append(np.abs(np.std(target_window) / np.sqrt(np.mean(np.power(target_window, 2)))))
204204
lr = np.mean(eq_window_weights)
205205
else:
206206
features = self.feature_reshape(features_vals)
@@ -212,7 +212,7 @@ def apply(self, objective: Equation, arguments: dict, force_out_of_place: bool =
212212
estimator.fit(feature_window, target_window, sample_weight=self.g_fun_vals[start_idx:end_idx])
213213
valuable_weights = estimator.coef_[:-1]
214214
eq_window_weights.append(valuable_weights)
215-
eq_cv = np.array([np.abs(np.std(_) / (np.mean(_) + 1e-12)) for _ in zip(*eq_window_weights)])
215+
eq_cv = np.array([np.abs(np.std(_) / np.sqrt(np.mean(np.power(_, 2)))) for _ in zip(*eq_window_weights)])
216216
lr = eq_cv.mean()
217217

218218
elif target_vals.ndim == 2:
@@ -233,7 +233,7 @@ def apply(self, objective: Equation, arguments: dict, force_out_of_place: bool =
233233
target_window = target_vals[start_idx:end_idx, :].reshape(-1)
234234
else:
235235
target_window = target_vals[:, start_idx:end_idx].reshape(-1)
236-
eq_window_weights.append(np.abs(np.std(target_window) / np.mean(target_window)))
236+
eq_window_weights.append(np.abs(np.std(target_window) / np.sqrt(np.mean(np.power(target_window, 2)))))
237237
lr += np.mean(eq_window_weights)
238238
else:
239239
features = self.feature_reshape(features_vals)
@@ -250,7 +250,7 @@ def apply(self, objective: Equation, arguments: dict, force_out_of_place: bool =
250250
estimator.fit(feature_window, target_window, sample_weight=self.g_fun_vals.reshape(*data_shape, -1)[:, start_idx:end_idx].reshape(-1))
251251
valuable_weights = estimator.coef_[:-1]
252252
eq_window_weights.append(valuable_weights)
253-
eq_cv = np.array([np.abs(np.std(_) / (np.mean(_) + 1e-12)) for _ in zip(*eq_window_weights)])
253+
eq_cv = np.array([np.abs(np.std(_) / np.sqrt(np.mean(np.power(_, 2)))) for _ in zip(*eq_window_weights)])
254254
lr += eq_cv.mean()
255255

256256
elif target_vals.ndim == 3:
@@ -269,7 +269,7 @@ def apply(self, objective: Equation, arguments: dict, force_out_of_place: bool =
269269
target_window = target_vals[:, start_idx:end_idx, :].reshape(-1)
270270
else:
271271
target_window = target_vals[:, :, start_idx:end_idx].reshape(-1)
272-
eq_window_weights.append(np.abs(np.std(target_window) / np.mean(target_window)))
272+
eq_window_weights.append(np.abs(np.std(target_window) / np.sqrt(np.mean(np.power(target_window, 2)))))
273273
lr += np.mean(eq_window_weights)
274274
else:
275275
features = self.feature_reshape(features_vals)
@@ -290,7 +290,7 @@ def apply(self, objective: Equation, arguments: dict, force_out_of_place: bool =
290290
estimator.fit(feature_window, target_window, sample_weight=self.g_fun_vals.reshape(*data_shape, -1)[:, :, start_idx:end_idx].reshape(-1))
291291
valuable_weights = estimator.coef_[:-1]
292292
eq_window_weights.append(valuable_weights)
293-
eq_cv = np.array([np.abs(np.std(_) / (np.mean(_) + 1e-12)) for _ in zip(*eq_window_weights)])
293+
eq_cv = np.array([np.abs(np.std(_) / np.sqrt(np.mean(np.power(_, 2)))) for _ in zip(*eq_window_weights)])
294294
lr += eq_cv.mean()
295295

296296
objective.fitness_calculated = True

0 commit comments

Comments
 (0)