TuringLang / GeneralisedFilters.jl

Filtering and smoothing algorithms for state space models with analytic (or approximately/partially analytic) solutions
MIT License
0 stars 0 forks source link

Implemented wrapper for KalmanFilters.jl SRKF #5

Open THargreaves opened 3 weeks ago

THargreaves commented 3 weeks ago

A simple wrapper for the square-root Kalman filter from KalmanFilters.jl. Still a bit of a draft and lacking documentation. Will add when implementation details sorted out.

They implemented their algorithm in a very modular way so it was a breeze to write the wrapper. They also look pretty memory efficient and rely on low-level LAPACK operations so should be speedy. They also implement the Unscented KF but not the extended.

They do not compute the incremental marginal log-likelihood but this is easy since they return the innovation mean and covariance (the likelihood is the density of a Gaussian with these parameters at zero).

The one sticking point is that the QR decomposition they use for updating does not enforce positive diagonals for R so that this is not a valid Cholesky decomposition and logpdf(MvNormal(...), ...) fails. I have a hacky manual computation of the log density to handle this case for now but I've raised an issue here JuliaGNSS/KalmanFilters.jl#16.

There are still some minor performance improvements that could be made either in this repo or in the original depending on their needs. Specifically, it is not necessary to compute the Kalman gain since we have

x_post = x_pred - (Ksqrt(Y)) inv(sqrt(Y)) y_tilde

And Ksqrt(Y) and sqrt(Y) are contained in the QR decomposition output. Maybe there is a need for compute K directly though?

There are also algorithms for updating (x, P) as well as doing a joint time+measurement update that avoids a second QR decomposition—but that feels like an issue for way down the line. These algorithms should also be amenable to the GPU using batch LUs from CuSolver.