@@ -48,6 +48,7 @@ def iterated_first_order(*args, **kwargs): return first_order(*args, **kwargs)
4848 (constant_jerk , {'r' :1e-4 , 'q' :10 }), (constant_jerk , [1e-4 , 10 ]),
4949 # TODO (known_dynamics), but presently it doesn't calculate a derivative
5050 ]
51+ diff_methods_and_params = [(constant_jerk , {'r' :1e-4 , 'q' :10 })]
5152
5253# All the testing methodology follows the exact same pattern; the only thing that changes is the
5354# closeness to the right answer various methods achieve with the given parameterizations. So index a
@@ -133,14 +134,14 @@ def iterated_first_order(*args, **kwargs): return first_order(*args, **kwargs)
133134 [(1 , 1 ), (2 , 2 ), (1 , 1 ), (2 , 2 )],
134135 [(1 , 1 ), (3 , 3 ), (1 , 1 ), (3 , 3 )]],
135136 constant_acceleration : [[(- 25 , - 25 ), (- 25 , - 25 ), (0 , 0 ), (1 , 0 )],
136- [(- 4 , - 4 ), (- 2 , - 3 ), (0 , 0 ), (1 , 0 )],
137- [(- 3 , - 3 ), (- 1 , - 2 ), (0 , 0 ), (1 , 0 )],
137+ [(- 5 , - 5 ), (- 3 , - 3 ), (0 , 0 ), (1 , 0 )],
138+ [(- 4 , - 4 ), (- 2 , - 2 ), (0 , 0 ), (1 , 0 )],
138139 [(0 , - 1 ), (1 , 0 ), (0 , 0 ), (1 , 0 )],
139140 [(1 , 1 ), (3 , 2 ), (1 , 1 ), (3 , 2 )],
140141 [(1 , 1 ), (3 , 3 ), (1 , 1 ), (3 , 3 )]],
141142 constant_jerk : [[(- 25 , - 25 ), (- 25 , - 25 ), (0 , 0 ), (1 , 0 )],
142- [(- 4 , - 4 ), (- 2 , - 3 ), (0 , 0 ), (1 , 0 )],
143- [(- 3 , - 3 ), (- 1 , - 2 ), (0 , 0 ), (1 , 0 )],
143+ [(- 5 , - 5 ), (- 3 , - 3 ), (0 , 0 ), (1 , 0 )],
144+ [(- 4 , - 4 ), (- 2 , - 2 ), (0 , 0 ), (1 , 0 )],
144145 [(- 1 , - 2 ), (1 , 0 ), (0 , 0 ), (1 , 0 )],
145146 [(1 , 0 ), (2 , 2 ), (1 , 0 ), (2 , 2 )],
146147 [(1 , 1 ), (3 , 3 ), (1 , 1 ), (3 , 3 )]]
@@ -174,18 +175,19 @@ def test_diff_method(diff_method_and_params, test_func_and_deriv, request): # re
174175 else diff_method (x_noisy , dt , params , options )
175176
176177 # check x_hat and x_hat_noisy are close to x and that dxdt_hat and dxdt_hat_noisy are close to dxdt
177- # print("]\n[", end="")
178+ if request . config . getoption ( "--bounds" ): print ("]\n [" , end = "" )
178179 for j ,(a ,b ) in enumerate ([(x ,x_hat ), (dxdt ,dxdt_hat ), (x ,x_hat_noisy ), (dxdt ,dxdt_hat_noisy )]):
179- # l2_error = np.linalg.norm(a - b)
180- # linf_error = np.max(np.abs(a - b))
181- # print(f"({l2_error},{linf_error})", end=", ")
182- # print(f"({int(np.ceil(np.log10(l2_error))) if l2_error > 0 else -25}, {int(np.ceil(np.log10(linf_error))) if linf_error > 0 else -25})", end=", ")
183-
184- log_l2_bound , log_linf_bound = error_bounds [diff_method ][i ][j ]
185- assert np .linalg .norm (a - b ) < 10 ** log_l2_bound
186- assert np .max (np .abs (a - b )) < 10 ** log_linf_bound
187- if 0 < np .linalg .norm (a - b ) < 10 ** (log_l2_bound - 1 ) or 0 < np .max (np .abs (a - b )) < 10 ** (log_linf_bound - 1 ):
188- print (f"Improvement detected for method { diff_method .__name__ } " )
180+ if request .config .getoption ("--bounds" ):
181+ l2_error = np .linalg .norm (a - b )
182+ linf_error = np .max (np .abs (a - b ))
183+ #print(f"({l2_error},{linf_error})", end=", ")
184+ print (f"({ int (np .ceil (np .log10 (l2_error ))) if l2_error > 0 else - 25 } , { int (np .ceil (np .log10 (linf_error ))) if linf_error > 0 else - 25 } )" , end = ", " )
185+ else :
186+ log_l2_bound , log_linf_bound = error_bounds [diff_method ][i ][j ]
187+ assert np .linalg .norm (a - b ) < 10 ** log_l2_bound
188+ assert np .max (np .abs (a - b )) < 10 ** log_linf_bound
189+ if 0 < np .linalg .norm (a - b ) < 10 ** (log_l2_bound - 1 ) or 0 < np .max (np .abs (a - b )) < 10 ** (log_linf_bound - 1 ):
190+ print (f"Improvement detected for method { diff_method .__name__ } " )
189191
190192 if request .config .getoption ("--plot" ) and not isinstance (params , list ): # Get the plot flag from pytest configuration
191193 fig , axes = request .config .plots [diff_method ] # get the appropriate plot, set up by the store_plots fixture in conftest.py
0 commit comments