@@ -78,7 +78,7 @@ def apply(self, objective: Equation, arguments: dict, force_out_of_place: bool =
7878 discr_feats = np .dot (features , objective .weights_final [:- 1 ][objective .weights_internal != 0 ])
7979
8080 discr = (discr_feats + np .full (target .shape , objective .weights_final [- 1 ]) - target )
81- self .g_fun_vals = global_var .grid_cache .g_func . reshape ( - 1 )
81+ self .g_fun_vals = global_var .grid_cache .g_func_flat
8282 discr = np .multiply (discr , self .g_fun_vals )
8383 rl_error = np .linalg .norm (discr , ord = 2 )
8484
@@ -153,7 +153,10 @@ def apply(self, objective: Equation, arguments: dict, force_out_of_place: bool =
153153 objective .aic_calculated = True
154154
155155 data_shape = global_var .grid_cache .inner_shape
156- weights = calculate_weights (features , target , self .g_fun_vals , data_shape )
156+ if hasattr (objective , '_cached_sw_weights' ) and objective ._cached_sw_weights is not None :
157+ weights = objective ._cached_sw_weights
158+ else :
159+ weights = calculate_weights (features , target , self .g_fun_vals , data_shape )
157160 weights_arr = np .array (weights )
158161 std = weights_arr .std (axis = 0 , ddof = 1 )
159162 mu = weights_arr .mean (axis = 0 )
@@ -164,7 +167,6 @@ def apply(self, objective: Equation, arguments: dict, force_out_of_place: bool =
164167 cv [mu == 0 ] = 0.0 # Handle zero mean
165168
166169 total_lr = sum (cv [:- 1 ]) / len (data_shape )
167- # total_lr = sum(dim_results) / target_vals.ndim
168170
169171 objective .fitness_calculated = True
170172 objective .fitness_value = fitness_value
@@ -173,7 +175,7 @@ def apply(self, objective: Equation, arguments: dict, force_out_of_place: bool =
173175
174176 def get_g_fun_vals (self ):
175177 try :
176- self .g_fun_vals = global_var .grid_cache .g_func [global_var .grid_cache .g_func != 0 ].reshape (- 1 )
178+ self .g_fun_vals = global_var .grid_cache .g_func [global_var .grid_cache .g_func_mask ].reshape (- 1 )
177179 except AttributeError :
178180 self .g_fun_vals = None
179181
@@ -230,7 +232,7 @@ def apply(self, objective : SoEq, arguments : dict, force_out_of_place: bool = F
230232 grids = torch .stack ([grid .reshape (- 1 ) for grid in grids ], dim = 1 ).float ()
231233 solution = solution_nn (grids ).detach ().cpu ().numpy ()
232234 self .g_fun_vals = global_var .grid_cache .g_func
233-
235+
234236 if force_out_of_place :
235237 sum_err = 0
236238
@@ -306,10 +308,11 @@ def apply(self, objective: SoEq, arguments: dict, force_out_of_place: bool = Fal
306308 boundary_conditions = None , use_fourier = True )
307309
308310 _ , grids = global_var .grid_cache .get_all (mode = 'torch' )
309- grids = [grid [global_var .grid_cache .g_func != 0 ] for grid in grids ]
311+ g_mask = global_var .grid_cache .g_func_mask
312+ grids = [grid [g_mask ] for grid in grids ]
310313 grids = torch .stack ([grid .reshape (- 1 ) for grid in grids ], dim = 1 ).float ()
311314 solution = solution_nn (grids ).detach ().cpu ().numpy ()
312- self .g_fun_vals = global_var .grid_cache .g_func [global_var . grid_cache . g_func != 0 ]
315+ self .g_fun_vals = global_var .grid_cache .g_func [g_mask ]
313316
314317 if force_out_of_place :
315318 sum_err = 0
@@ -339,7 +342,10 @@ def apply(self, objective: SoEq, arguments: dict, force_out_of_place: bool = Fal
339342 # Calculate r-loss
340343 data_shape = global_var .grid_cache .inner_shape
341344 _ , target , features = eq .evaluate (normalize = True , return_val = False )
342- weights = calculate_weights (features , target , self .g_fun_vals , data_shape )
345+ if hasattr (eq , '_cached_sw_weights' ) and eq ._cached_sw_weights is not None :
346+ weights = eq ._cached_sw_weights
347+ else :
348+ weights = calculate_weights (features , target , self .g_fun_vals , data_shape )
343349 weights_arr = np .array (weights )
344350 std = weights_arr .std (axis = 0 , ddof = 1 )
345351 mu = weights_arr .mean (axis = 0 )
@@ -369,7 +375,7 @@ def feature_reshape(self, features_vals):
369375
370376 def get_g_fun_vals (self ):
371377 try :
372- self .g_fun_vals = global_var .grid_cache .g_func . reshape ( - 1 )
378+ self .g_fun_vals = global_var .grid_cache .g_func_flat
373379 except AttributeError :
374380 self .g_fun_vals = None
375381
0 commit comments