1111# Function aliases for testing cases where parameters change the behavior in a big way
1212def iterated_first_order (* args , ** kwargs ): return first_order (* args , ** kwargs )
1313
14+ dt = 0.1
1415t = np .linspace (0 , 3 , 31 ) # sample locations, including the endpoint
1516tt = np .linspace (0 , 3 ) # full domain, for visualizing denser plots
16- ttt = np .linspace (0 , 3 , 201 ) # for testing jerk_sliding, which requires more points
1717np .random .seed (7 ) # for repeatability of the test, so we don't get random failures
1818noise = 0.05 * np .random .randn (* t .shape )
19- long_noise = 0.05 * np .random .randn (* ttt .shape )
2019
2120# Analytic (function, derivative) pairs on which to test differentiation methods.
2221test_funcs_and_derivs = [
@@ -53,7 +52,7 @@ def iterated_first_order(*args, **kwargs): return first_order(*args, **kwargs)
5352 (jerk , {'gamma' :10 }), (jerk , [10 ]),
5453 (iterative_velocity , {'num_iterations' :5 , 'gamma' :0.05 }), (iterative_velocity , [5 , 0.05 ]),
5554 (smooth_acceleration , {'gamma' :2 , 'window_size' :5 }), (smooth_acceleration , [2 , 5 ]),
56- (jerk_sliding , {'gamma' :1e2 , 'solver' : 'CLARABEL' }), (jerk_sliding , [1e2 ], {'solver' : 'CLARABEL' })
55+ (jerk_sliding , {'gamma' :1 , 'window_size' : 15 }), (jerk_sliding , [1 ], {'window_size' : 15 })
5756 ]
5857
5958# All the testing methodology follows the exact same pattern; the only thing that changes is the
@@ -186,11 +185,11 @@ def iterated_first_order(*args, **kwargs): return first_order(*args, **kwargs)
186185 [(0 , 0 ), (1 , 0 ), (0 , - 1 ), (1 , 0 )],
187186 [(1 , 1 ), (2 , 2 ), (1 , 1 ), (2 , 2 )],
188187 [(1 , 1 ), (3 , 3 ), (1 , 1 ), (3 , 3 )]],
189- jerk_sliding : [[(- 13 , - 14 ), (- 12 , - 13 ), (0 , - 1 ), (1 , 0 )],
190- [(- 12 , - 13 ), (- 12 , - 12 ), (0 , - 1 ), (0 , 0 )],
191- [(- 13 , - 14 ), (- 12 , - 13 ), (0 , - 1 ), (0 , 0 )],
192- [(- 1 , - 2 ), (0 , 0 ), (0 , - 1 ), (1 , 0 )],
193- [(0 , 0 ), (2 , 1 ), (0 , 0 ), (2 , 1 )],
188+ jerk_sliding : [[(- 15 , - 15 ), (- 16 , - 17 ), (0 , - 1 ), (1 , 0 )],
189+ [(- 14 , - 14 ), (- 14 , - 14 ), (0 , - 1 ), (0 , 0 )],
190+ [(- 14 , - 14 ), (- 14 , - 14 ), (0 , - 1 ), (0 , 0 )],
191+ [(- 1 , - 1 ), (0 , 0 ), (0 , - 1 ), (0 , 0 )],
192+ [(0 , 0 ), (2 , 2 ), (0 , 0 ), (2 , 2 )],
194193 [(1 , 1 ), (3 , 3 ), (1 , 1 ), (3 , 3 )]]
195194}
196195
@@ -210,16 +209,9 @@ def test_diff_method(diff_method_and_params, test_func_and_deriv, request): # re
210209 except : warn (f"Cannot import cvxpy, skipping { diff_method } test." ); return
211210
212211 # sample the true function and make noisy samples, and sample true derivative
213- if diff_method != jerk_sliding :
214- x = f (t )
215- x_noisy = x + noise
216- dxdt = df (t )
217- dt = t [1 ] - t [0 ]
218- else : # different density for jerk_sliding
219- x = f (ttt )
220- x_noisy = x + long_noise
221- dxdt = df (ttt )
222- dt = ttt [1 ] - ttt [0 ]
212+ x = f (t )
213+ x_noisy = x + noise
214+ dxdt = df (t )
223215
224216 # differentiate without and with noise, accounting for new and old styles of calling functions
225217 x_hat , dxdt_hat = diff_method (x , dt , ** params ) if isinstance (params , dict ) \
0 commit comments