@@ -52,7 +52,15 @@ def estimate_nr_full(input_data: InputData, working_dir: str):
5252 )
5353 input_data .save (os .path .join (working_dir , "input_data.h5" ))
5454
55- estimator .train_sequence (training_strategy = "NEWTON_EXACT" )
55+ estimator .train_sequence (training_strategy = [
56+ {
57+ "convergence_criteria" : "scaled_moving_average" ,
58+ "stopping_criteria" : 1e-10 ,
59+ "loss_window_size" : 10 ,
60+ "use_batching" : False ,
61+ "optim_algo" : "newton" ,
62+ },
63+ ])
5664
5765 return estimator
5866
@@ -68,23 +76,15 @@ def estimate_nr_batched(input_data: InputData, working_dir: str):
6876 )
6977 input_data .save (os .path .join (working_dir , "input_data.h5" ))
7078
71- estimator .train_sequence (training_strategy = "NEWTON_BATCHED" )
72-
73- return estimator
74-
75-
76- def estimate_nr_series (input_data : InputData , working_dir : str ):
77- estimator = Estimator (input_data , batch_size = 500 )
78- estimator .initialize (
79- working_dir = working_dir ,
80- save_checkpoint_steps = 20 ,
81- save_summaries_steps = 20 ,
82- export = ["a" , "b" , "mu" , "r" , "loss" ],
83- export_steps = 20
84- )
85- input_data .save (os .path .join (working_dir , "input_data.h5" ))
86-
87- estimator .train_sequence (training_strategy = "NEWTON_SERIES" )
79+ estimator .train_sequence (training_strategy = [
80+ {
81+ "convergence_criteria" : "scaled_moving_average" ,
82+ "stopping_criteria" : 1e-8 ,
83+ "loss_window_size" : 10 ,
84+ "use_batching" : True ,
85+ "optim_algo" : "newton" ,
86+ },
87+ ])
8888
8989 return estimator
9090
@@ -183,31 +183,6 @@ def test_newton_full(self):
183183 print ((estimator .a .values - self .sim .a .values ) / self .sim .a .values )
184184 print ((estimator .b .values - self .sim .b .values ) / self .sim .b .values )
185185
186- def test_newton_series (self ):
187- X = scipy .sparse .csr_matrix (self .sim .X )
188- design_loc = self .sim .design_loc
189- design_scale = self .sim .design_scale
190- idata = InputData .new (
191- data = X ,
192- design_loc = design_loc ,
193- design_scale = design_scale ,
194- )
195- wd = os .path .join (self .working_dir .name , "newton_full" )
196- os .makedirs (wd , exist_ok = True )
197-
198- t0 = time .time ()
199- pkg_constants .JACOBIAN_MODE = "analytic"
200- estimator = estimate_nr_series (idata , wd )
201- t1 = time .time ()
202- self ._estims .append (estimator )
203-
204- # test finalizing
205- estimator = estimator .finalize ()
206- print ("\n " )
207- print ("run time newton-rhapson series: " , str (t1 - t0 ))
208- print ((estimator .a .values - self .sim .a .values ) / self .sim .a .values )
209- print ((estimator .b .values - self .sim .b .values ) / self .sim .b .values )
210-
211186
212187if __name__ == '__main__' :
213188 unittest .main ()
0 commit comments