Skip to content

Commit 6161d35

Browse files
authored
Merge pull request #151 from florisvb/kalman-variable-dt
Kalman variable dt
2 parents e4de566 + d06a564 commit 6161d35

11 files changed

Lines changed: 240 additions & 448 deletions

docs/source/kalman_smooth.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ kalman_smooth
88
.. autofunction:: pynumdiff.kalman_smooth.constant_velocity
99
.. autofunction:: pynumdiff.kalman_smooth.constant_acceleration
1010
.. autofunction:: pynumdiff.kalman_smooth.constant_jerk
11-
.. autofunction:: pynumdiff.kalman_smooth.known_dynamics
11+
.. autofunction:: pynumdiff.kalman_smooth.kalman_filter
12+
.. autofunction:: pynumdiff.kalman_smooth.rts_smooth

examples/1_basic_tutorial.ipynb

Lines changed: 28 additions & 172 deletions
Large diffs are not rendered by default.

examples/2a_optimizing_parameters_with_dxdt_known.ipynb

Lines changed: 26 additions & 52 deletions
Large diffs are not rendered by default.

examples/2b_optimizing_parameters_with_dxdt_unknown.ipynb

Lines changed: 26 additions & 52 deletions
Large diffs are not rendered by default.

examples/3_automatic_method_suggestion.ipynb

Lines changed: 13 additions & 10 deletions
Large diffs are not rendered by default.

pynumdiff/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
from .smooth_finite_difference import meandiff, mediandiff, gaussiandiff, friedrichsdiff, butterdiff
77
from .polynomial_fit import splinediff, polydiff, savgoldiff
88
from .total_variation_regularization import tvrdiff, velocity, acceleration, jerk, iterative_velocity, smooth_acceleration, jerk_sliding
9-
from .kalman_smooth import rtsdiff, constant_velocity, constant_acceleration, constant_jerk, known_dynamics
9+
from .kalman_smooth import kalman_filter, rts_smooth, rtsdiff, constant_velocity, constant_acceleration, constant_jerk
1010
from .linear_model import spectraldiff, lineardiff, rbfdiff
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""This module implements Kalman filters
22
"""
3-
from ._kalman_smooth import rtsdiff, constant_velocity, constant_acceleration, constant_jerk, known_dynamics
3+
from ._kalman_smooth import kalman_filter, rts_smooth, rtsdiff, constant_velocity, constant_acceleration, constant_jerk

pynumdiff/kalman_smooth/_kalman_smooth.py

Lines changed: 104 additions & 127 deletions
Large diffs are not rendered by default.

pynumdiff/linear_model/_linear_model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,19 +238,19 @@ def rbfdiff(x, _t, sigma=1, lmbd=0.01):
238238
239239
:param np.array[float] x: data to differentiate
240240
:param float or array[float] _t: This function supports variable step size. This parameter is either the constant
241-
step size if given as a single float, or data locations if given as an array of same length as :code:`x`.
241+
:math:`\\Delta t` if given as a single float, or data locations if given as an array of same length as :code:`x`.
242242
:param float sigma: controls width of radial basis function
243243
:param float lmbd: controls strength of bias toward data
244244
245245
:return: tuple[np.array, np.array] of\n
246246
- **x_hat** -- estimated (smoothed) x
247247
- **dxdt_hat** -- estimated derivative of x
248248
"""
249-
if isinstance(_t, (np.ndarray, list)): # support variable step size for this function
249+
if np.isscalar(_t):
250+
t = np.arange(len(x))*_t
251+
else: # support variable step size for this function
250252
if len(x) != len(_t): raise ValueError("If `_t` is given as array-like, must have same length as `x`.")
251253
t = _t
252-
else:
253-
t = np.arange(len(x))*_t
254254

255255
# The below does the approximate equivalent of this code, but sparsely in O(N sigma), since the rbf falls off rapidly
256256
# t_i, t_j = np.meshgrid(t,t)

pynumdiff/polynomial_fit/_polynomial_fit.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def splinediff(x, _t, params=None, options={}, degree=3, s=None, num_iterations=
1111
1212
:param np.array[float] x: data to differentiate
1313
:param float or array[float] _t: This function supports variable step size. This parameter is either the constant
14-
step size if given as a single float, or data locations if given as an array of same length as :code:`x`.
14+
:math:`\\Delta t` if given as a single float, or data locations if given as an array of same length as :code:`x`.
1515
:param list params: (**deprecated**, prefer :code:`degree`, :code:`cutoff_freq`, and :code:`num_iterations`)
1616
:param dict options: (**deprecated**, prefer :code:`num_iterations`) an empty dictionary or {'iterate': (bool)}
1717
:param int degree: polynomial degree of the spline. A kth degree spline can be differentiated k times.
@@ -30,11 +30,11 @@ def splinediff(x, _t, params=None, options={}, degree=3, s=None, num_iterations=
3030
if 'iterate' in options and options['iterate']:
3131
num_iterations = params[2]
3232

33-
if isinstance(_t, (np.ndarray, list)): # support variable step size for this function
33+
if np.isscalar(_t):
34+
t = np.arange(len(x))*_t
35+
else: # support variable step size for this function
3436
if len(x) != len(_t): raise ValueError("If `_t` is given as array-like, must have same length as `x`.")
3537
t = _t
36-
else:
37-
t = np.arange(len(x))*_t
3838

3939
x_hat = x
4040
for _ in range(num_iterations):

0 commit comments

Comments
 (0)