Skip to content

Commit 082941a

Browse files
authored
Merge pull request #121 from florisvb/examples-update
updated basic usage examples and caught and fixed a subtle variable alias bug I introduced last week in the kalman module
2 parents e483a7c + ff0a97b commit 082941a

3 files changed

Lines changed: 187 additions & 178 deletions

File tree

examples/1_basic_tutorial.ipynb

Lines changed: 170 additions & 161 deletions
Large diffs are not rendered by default.

pynumdiff/kalman_smooth/_kalman_smooth.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ def _kalman_forward_filter(xhat0, P0, y, A, C, Q, R, u=None, B=None):
3636
xhat_pre.append(xhat_) # the [n]th index holds _{n|n-1} info
3737
P_pre.append(P_)
3838

39-
xhat = xhat_ # handle missing data
40-
P = P_
41-
if not np.isnan(y[n]):
39+
xhat = xhat_.copy()
40+
P = P_.copy()
41+
if not np.isnan(y[n]): # handle missing data
4242
K = P_ @ C.T @ np.linalg.inv(C @ P_ @ C.T + R)
4343
xhat += K @ (y[n] - C @ xhat_)
4444
P -= K @ C @ P_
@@ -89,7 +89,7 @@ def _constant_derivative(x, P0, A, C, R, Q, forwardbackward):
8989
x_hat_forward = xhat_smooth[:, 0] # first dimension is time, so slice first element at all times
9090
dxdt_hat_forward = xhat_smooth[:, 1]
9191

92-
if not forwardbackward: # bound out here if not doing the same in reverse and then combining
92+
if not forwardbackward: # bounce out here if not doing the same in reverse and then combining
9393
return x_hat_forward, dxdt_hat_forward
9494

9595
xhat0[0] = x[-1] # starting from the other end of the signal

pynumdiff/tests/test_diff_methods.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,22 @@ def iterated_first_order(*args, **kwargs): return first_order(*args, **kwargs)
138138
[(1, 0), (2, 2), (1, 0), (2, 2)],
139139
[(1, 0), (3, 3), (1, 0), (3, 3)]],
140140
constant_velocity: [[(-25, -25), (-25, -25), (0, -1), (0, 0)],
141-
[(-5, -6), (-4, -4), (0, -1), (0, 0)],
142-
[(-1, -2), (0, 0), (0, 0), (1, 0)],
143-
[(0, -1), (1, 0), (0, -1), (1, 1)],
141+
[(-6, -6), (-5, -5), (0, -1), (0, 0)],
142+
[(-1, -2), (0, 0), (0, -1), (0, 0)],
143+
[(-1, -1), (1, 0), (0, -1), (1, 0)],
144144
[(1, 1), (2, 2), (1, 1), (2, 2)],
145145
[(1, 1), (3, 3), (1, 1), (3, 3)]],
146-
constant_acceleration: [[(-25, -25), (-25, -25), (0, 0), (1, 0)],
147-
[(-5, -5), (-3, -3), (0, 0), (1, 0)],
148-
[(-4, -4), (-2, -2), (0, 0), (1, 0)],
149-
[(0, -1), (1, 0), (0, 0), (1, 0)],
150-
[(1, 1), (3, 2), (1, 1), (3, 2)],
146+
constant_acceleration: [[(-25, -25), (-25, -25), (0, -1), (0, 0)],
147+
[(-5, -6), (-4, -5), (0, -1), (0, 0)],
148+
[(-5, -5), (-4, -4), (0, -1), (0, 0)],
149+
[(-1, -1), (0, 0), (0, -1), (0, 0)],
150+
[(1, 1), (2, 2), (1, 1), (2, 2)],
151151
[(1, 1), (3, 3), (1, 1), (3, 3)]],
152-
constant_jerk: [[(-25, -25), (-25, -25), (0, 0), (1, 0)],
153-
[(-5, -5), (-3, -3), (0, 0), (1, 0)],
154-
[(-4, -4), (-2, -2), (0, 0), (1, 0)],
155-
[(-1, -2), (1, 0), (0, 0), (1, 0)],
156-
[(1, 0), (2, 2), (1, 0), (2, 2)],
152+
constant_jerk: [[(-25, -25), (-25, -25), (0, -1), (0, 0)],
153+
[(-5, -5), (-4, -5), (0, -1), (0, 0)],
154+
[(-4, -5), (-3, -4), (0, -1), (0, 0)],
155+
[(-1, -2), (0, 0), (0, -1), (0, 0)],
156+
[(1, 0), (2, 1), (1, 0), (2, 1)],
157157
[(1, 1), (3, 3), (1, 1), (3, 3)]],
158158
velocity: [[(-25, -25), (-18, -19), (0, -1), (1, 0)],
159159
[(-12, -12), (-11, -12), (-1, -1), (-1, -2)],

0 commit comments

Comments
 (0)