@@ -200,7 +200,11 @@ 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 .sqrt (np .mean (np .power (target_window , 2 )))))
203+ if np .isclose (np .sqrt (np .mean (np .power (_ , 2 ))), 0 , atol = 1e-10 ):
204+ window_stability = np .abs (np .std (target_window ))
205+ else :
206+ window_stability = np .abs (np .std (target_window ) / np .sqrt (np .mean (np .power (target_window , 2 ))))
207+ eq_window_weights .append (window_stability )
204208 lr = np .mean (eq_window_weights )
205209 else :
206210 features = self .feature_reshape (features_vals )
@@ -212,7 +216,11 @@ def apply(self, objective: Equation, arguments: dict, force_out_of_place: bool =
212216 estimator .fit (feature_window , target_window , sample_weight = self .g_fun_vals [start_idx :end_idx ])
213217 valuable_weights = estimator .coef_ [:- 1 ]
214218 eq_window_weights .append (valuable_weights )
215- eq_cv = np .array ([np .abs (np .std (_ ) / np .sqrt (np .mean (np .power (_ , 2 )))) for _ in zip (* eq_window_weights )])
219+ eq_cv = np .array ([
220+ np .abs (np .std (_ )) if np .isclose (np .sqrt (np .mean (np .power (_ , 2 ))), 0 , atol = 1e-10 )
221+ else np .abs (np .std (_ ) / np .sqrt (np .mean (np .power (_ , 2 ))))
222+ for _ in zip (* eq_window_weights )
223+ ])
216224 lr = eq_cv .mean ()
217225
218226 elif target_vals .ndim == 2 :
@@ -233,7 +241,11 @@ def apply(self, objective: Equation, arguments: dict, force_out_of_place: bool =
233241 target_window = target_vals [start_idx :end_idx , :].reshape (- 1 )
234242 else :
235243 target_window = target_vals [:, start_idx :end_idx ].reshape (- 1 )
236- eq_window_weights .append (np .abs (np .std (target_window ) / np .sqrt (np .mean (np .power (target_window , 2 )))))
244+ if np .isclose (np .sqrt (np .mean (np .power (_ , 2 ))), 0 , atol = 1e-10 ):
245+ window_stability = np .abs (np .std (target_window ))
246+ else :
247+ window_stability = np .abs (np .std (target_window ) / np .sqrt (np .mean (np .power (target_window , 2 ))))
248+ eq_window_weights .append (window_stability )
237249 lr += np .mean (eq_window_weights )
238250 else :
239251 features = self .feature_reshape (features_vals )
@@ -250,7 +262,11 @@ def apply(self, objective: Equation, arguments: dict, force_out_of_place: bool =
250262 estimator .fit (feature_window , target_window , sample_weight = self .g_fun_vals .reshape (* data_shape , - 1 )[:, start_idx :end_idx ].reshape (- 1 ))
251263 valuable_weights = estimator .coef_ [:- 1 ]
252264 eq_window_weights .append (valuable_weights )
253- eq_cv = np .array ([np .abs (np .std (_ ) / np .sqrt (np .mean (np .power (_ , 2 )))) for _ in zip (* eq_window_weights )])
265+ eq_cv = np .array ([
266+ np .abs (np .std (_ )) if np .isclose (np .sqrt (np .mean (np .power (_ , 2 ))), 0 , atol = 1e-10 )
267+ else np .abs (np .std (_ ) / np .sqrt (np .mean (np .power (_ , 2 ))))
268+ for _ in zip (* eq_window_weights )
269+ ])
254270 lr += eq_cv .mean ()
255271
256272 elif target_vals .ndim == 3 :
@@ -269,7 +285,11 @@ def apply(self, objective: Equation, arguments: dict, force_out_of_place: bool =
269285 target_window = target_vals [:, start_idx :end_idx , :].reshape (- 1 )
270286 else :
271287 target_window = target_vals [:, :, start_idx :end_idx ].reshape (- 1 )
272- eq_window_weights .append (np .abs (np .std (target_window ) / np .sqrt (np .mean (np .power (target_window , 2 )))))
288+ if np .isclose (np .sqrt (np .mean (np .power (_ , 2 ))), 0 , atol = 1e-10 ):
289+ window_stability = np .abs (np .std (target_window ))
290+ else :
291+ window_stability = np .abs (np .std (target_window ) / np .sqrt (np .mean (np .power (target_window , 2 ))))
292+ eq_window_weights .append (window_stability )
273293 lr += np .mean (eq_window_weights )
274294 else :
275295 features = self .feature_reshape (features_vals )
@@ -290,7 +310,12 @@ def apply(self, objective: Equation, arguments: dict, force_out_of_place: bool =
290310 estimator .fit (feature_window , target_window , sample_weight = self .g_fun_vals .reshape (* data_shape , - 1 )[:, :, start_idx :end_idx ].reshape (- 1 ))
291311 valuable_weights = estimator .coef_ [:- 1 ]
292312 eq_window_weights .append (valuable_weights )
293- eq_cv = np .array ([np .abs (np .std (_ ) / np .sqrt (np .mean (np .power (_ , 2 )))) for _ in zip (* eq_window_weights )])
313+ eq_cv = np .array ([
314+ np .abs (np .std (_ )) if np .isclose (np .sqrt (np .mean (np .power (_ , 2 ))), 0 , atol = 1e-10 )
315+ else np .abs (np .std (_ ) / np .sqrt (np .mean (np .power (_ , 2 ))))
316+ for _ in zip (* eq_window_weights )
317+ ])
318+
294319 lr += eq_cv .mean ()
295320
296321 objective .fitness_calculated = True
0 commit comments