filterpy icon indicating copy to clipboard operation
filterpy copied to clipboard

RTS smoother implementation bug?

Open nnop opened this issue 3 years ago • 1 comments

RTS implementation only use posterior outputs of Kalman filter. https://github.com/rlabbe/filterpy/blob/06bd64fbb50b70e8bfc2be180c8e0a2fedd087f0/filterpy/kalman/tests/test_rts.py#L43-L46

However, according to wikipedia, both posterior and prior of x and P should be used.

image

This seems a clear bug.

nnop avatar Dec 01 '21 03:12 nnop

I was also confused by this. However in the source code you can see that the prior is recomputed during the rts smoothing. The prior covariance is pP, which is calculated as followed: pP[k] = dot(dot(Fs[k], P[k]), Fs[k].T) + Qs[k] , which is equivalent to $P_{k+1|k} = F_kP_{k|k}F^T_k + Q_k$. The a-priori state estimate $\hat{x_{k|n}}$ is calculated with the code snippet dot(Fs[k], x[k])) (which is equal to $F \cdot X_{k|k} = X_{k+1|k}$).

So it is not a bug, the prior is just recalculated inside the rts_smoother function

KoertS avatar Nov 22 '23 13:11 KoertS