Skip to content

Commit 21b0b5f

Browse files
authored
Merge pull request #175 from florisvb/nix-jerk-sliding
removed jerk_sliding
2 parents e817273 + 78644e2 commit 21b0b5f

5 files changed

Lines changed: 4 additions & 50 deletions

File tree

pynumdiff/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from warnings import warn
99
warn("tvrdiff, robustdiff, and lineardiff not available due to lack of convex solver. To use those, install CVXPY.")
1010
else: # executes if try is successful
11-
from .total_variation_regularization import tvrdiff, velocity, acceleration, jerk, smooth_acceleration, jerk_sliding
11+
from .total_variation_regularization import tvrdiff, velocity, acceleration, jerk, smooth_acceleration
1212
from .kalman_smooth import robustdiff, convex_smooth
1313
from .linear_model import lineardiff
1414

pynumdiff/optimize/_optimize.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from ..smooth_finite_difference import kerneldiff, mediandiff, meandiff, gaussiandiff, friedrichsdiff, butterdiff
1414
from ..polynomial_fit import polydiff, savgoldiff, splinediff
1515
from ..basis_fit import spectraldiff, rbfdiff
16-
from ..total_variation_regularization import tvrdiff, velocity, acceleration, jerk, iterative_velocity, smooth_acceleration, jerk_sliding
16+
from ..total_variation_regularization import tvrdiff, velocity, acceleration, jerk, iterative_velocity, smooth_acceleration
1717
from ..kalman_smooth import rtsdiff, constant_velocity, constant_acceleration, constant_jerk, robustdiff
1818
from ..linear_model import lineardiff
1919

@@ -110,7 +110,6 @@
110110
method_params_and_bounds[method] = method_params_and_bounds[meandiff]
111111
for method in [acceleration, jerk]: # Deprecated, redundant methods
112112
method_params_and_bounds[method] = method_params_and_bounds[velocity]
113-
method_params_and_bounds[jerk_sliding] = method_params_and_bounds[smooth_acceleration]
114113
for method in [constant_acceleration, constant_jerk]: # Deprecated, redundant methods
115114
method_params_and_bounds[method] = method_params_and_bounds[constant_velocity]
116115

pynumdiff/tests/test_diff_methods.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from ..linear_model import lineardiff
77
from ..basis_fit import spectraldiff, rbfdiff
88
from ..polynomial_fit import polydiff, savgoldiff, splinediff
9-
from ..total_variation_regularization import velocity, acceleration, jerk, iterative_velocity, smooth_acceleration, jerk_sliding
9+
from ..total_variation_regularization import velocity, acceleration, jerk, iterative_velocity, smooth_acceleration
1010
from ..kalman_smooth import rtsdiff, constant_velocity, constant_acceleration, constant_jerk, robustdiff
1111
from ..smooth_finite_difference import mediandiff, meandiff, gaussiandiff, friedrichsdiff, butterdiff
1212
# Function aliases for testing cases where parameters change the behavior in a big way, so error limits can be indexed in dict
@@ -57,7 +57,6 @@ def spline_irreg_step(*args, **kwargs): return splinediff(*args, **kwargs)
5757
(jerk, {'gamma':10}), (jerk, [10]),
5858
(iterative_velocity, {'num_iterations':5, 'gamma':0.05}), (iterative_velocity, [5, 0.05]),
5959
(smooth_acceleration, {'gamma':2, 'window_size':5}), (smooth_acceleration, [2, 5]),
60-
(jerk_sliding, {'gamma':1, 'window_size':15}), (jerk_sliding, [1], {'window_size':15}),
6160
(lineardiff, {'order':3, 'gamma':5, 'window_size':11, 'solver':'CLARABEL'}), (lineardiff, [3, 5, 11], {'solver':'CLARABEL'})
6261
]
6362

@@ -193,12 +192,6 @@ def spline_irreg_step(*args, **kwargs): return splinediff(*args, **kwargs)
193192
[(0, 0), (1, 0), (0, -1), (1, 0)],
194193
[(1, 1), (2, 2), (1, 1), (2, 2)],
195194
[(1, 1), (3, 3), (1, 1), (3, 3)]],
196-
jerk_sliding: [[(-25, -25), (-16, -17), (0, -1), (1, 0)],
197-
[(-14, -14), (-14, -14), (0, -1), (0, 0)],
198-
[(-14, -14), (-14, -14), (0, -1), (0, 0)],
199-
[(-1, -1), (0, 0), (0, -1), (0, 0)],
200-
[(1, 0), (2, 2), (1, 0), (2, 2)],
201-
[(1, 1), (3, 3), (1, 1), (3, 3)]],
202195
constant_velocity: [[(-25, -25), (-25, -25), (0, -1), (1, 1)],
203196
[(-4, -5), (-3, -3), (0, -1), (1, 1)],
204197
[(-3, -3), (0, 0), (0, -1), (1, 1)],
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""This module implements some common total variation regularization methods
22
"""
3-
from ._total_variation_regularization import tvrdiff, velocity, acceleration, jerk, jerk_sliding, smooth_acceleration, iterative_velocity
3+
from ._total_variation_regularization import tvrdiff, velocity, acceleration, jerk, smooth_acceleration, iterative_velocity

pynumdiff/total_variation_regularization/_total_variation_regularization.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -225,41 +225,3 @@ def smooth_acceleration(x, dt, params=None, options=None, gamma=None, window_siz
225225
x_hat = x_hat + x0
226226

227227
return x_hat, dxdt_hat
228-
229-
230-
def jerk_sliding(x, dt, params=None, options=None, gamma=None, solver=None, window_size=101):
231-
"""Use convex optimization (cvxpy) to solve for the jerk total variation regularized derivative in a
232-
sliding window.
233-
234-
:param np.array[float] x: data to differentiate
235-
:param float dt: step size
236-
:param params: (**deprecated**, prefer :code:`gamma`)
237-
:param dict options: (**deprecated**, prefer :code:`solver`) a dictionary consisting of {'solver': (str)}
238-
:param float gamma: the regularization parameter
239-
:param str solver: the solver CVXPY should use, 'MOSEK', 'CVXOPT', 'CLARABEL', 'ECOS', etc.
240-
In testing, 'MOSEK' was the most robust. If not given, fall back to CVXPY's default.
241-
:param int window_size: how wide to make the kernel
242-
243-
:return: - **x_hat** (np.array) -- estimated (smoothed) x
244-
- **dxdt_hat** (np.array) -- estimated derivative of x
245-
"""
246-
if params != None: # Warning to support old interface for a while. Remove these lines along with params in a future release.
247-
warn("`params` and `options` parameters will be removed in a future version. Use `gamma` " +
248-
"and `solver` instead.", DeprecationWarning)
249-
gamma = params[0] if isinstance(params, list) else params
250-
if options != None:
251-
if 'solver' in options: solver = options['solver']
252-
if 'window_size' in options: window_size = options['window_size']
253-
elif gamma == None:
254-
raise ValueError("`gamma` must be given.")
255-
256-
if len(x) < window_size or window_size < 15:
257-
warn("len(x) should be > window_size >= 15, calling standard jerk() without sliding")
258-
return tvrdiff(x, dt, 3, gamma, solver=solver)
259-
260-
if window_size % 2 == 0:
261-
window_size += 1 # has to be odd
262-
warn("Kernel window size should be odd. Added 1 to length.")
263-
ramp = window_size//5
264-
kernel = np.hstack((np.arange(1, ramp+1)/ramp, np.ones(window_size - 2*ramp), np.arange(ramp, 0, -1)/ramp))
265-
return utility.slide_function(tvrdiff, x, dt, kernel, 3, gamma, stride=ramp, solver=solver)

0 commit comments

Comments
 (0)