Skip to content

Commit 36d5b6a

Browse files
committed
feat: add UnscentedKalmanFilter, the Kalman filter that samples the model instead of differentiating it
The extended filter pushes the covariance through a Jacobian, a straight line drawn at one point, which needs the model to be differentiable, needs the derivative written out, and discards everything beyond first order. The unscented filter picks 2n + 1 sigma points whose mean and covariance are exactly those of the estimate, sends each through the real model and reads the new mean and covariance off where they land. The square root that spreads them is a Cholesky factor, so a step costs about what the extended filter does, with no Jacobian anywhere, and the result is right to second order. The defaults are alpha = 1, beta = 2, kappa = 0. The alpha = 1e-3 often quoted puts the sigma points almost on the mean and compensates with a central weight near minus a million, exact on paper and six digits lost in floating point. After an update the covariance P - K S K' is symmetrised explicitly, and a covariance that is no longer positive definite is refused with an ArithmeticException instead of being given a square root that does not exist. The innovation covariance is inverted with the existing matrix.InverseOfMatrix. Tests: the sigma points reproduce the mean and covariance of the estimate exactly, the mean and variance of x^2 come out exact where the extended filter misses both, a linear model agrees with the extended filter to 1e-9 over 500 steps, and a target seen only as a range is tracked without writing a derivative. Signed-off-by: alxkm <19151554+alxkm@users.noreply.github.com>
1 parent 550a7ed commit 36d5b6a

2 files changed

Lines changed: 847 additions & 0 deletions

File tree

0 commit comments

Comments
 (0)