Skip to content

Commit ff0a97b

Browse files
committed
fixed bug in kalman
1 parent f8bc493 commit ff0a97b

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

pynumdiff/kalman_smooth/_kalman_smooth.py

Lines changed: 3 additions & 3 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_

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)