Implement SArray-Compatible Filtering #121
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes some small changes to the filtering interface to allow for full compatibility with SArrays for both closed-form filtering as well as simulation/sampling.
The initial plan we discussed for this approach was to implement a custom Gaussian container. I started this but realised I was running into a lot of edge-cases. Stuff like the computation of the auxiliary statistic (which uses
meanon the Gaussian predictive distribution), which would have required us to implement a fair amount of theDistributions.jlinterface.Instead, I thought as a near-term solution, it may be best to work around the limitations of
Distributions.jlby making a few changes, rather than trying to reinvent the wheel. In the future, if we decide there are large deviations from the interface that we need and have a clear idea how to implement our own interface, we can pick up that work then.The primary change of this PR is reverting to using
MvNormalfor the predictive and filtered distributions of the Kalman filter.To make this compatible with StaticArrays, we added a layer of abstraction
SSMProblems.simulate_from_distwhich we can intercept and generate a SArray sample.The only real consideration with
MvNormalis that it requires the covariance to be a PDMat. I.e. it will automatically compute the Cholesky for us which could be inefficient.It turns out though that this is actually an efficiency gain. I did a FLOPS analysis, and for all dimensions, when computing AΣA', it is faster to first compute the Cholesky of Σ then do B = AL, BB', using
PDMats.X_A_Xtthan to do the direct computation.The only issue I'm running into is during the backward recursion of the RTS smoother.
Σ_pred - Σ_backis always PD but can be singular if the system is not fully observed (e.g. only observe the position dimension). We don't need to invert this matrix so we could still do something likeX_A_Xtbut we need to be careful that round-off means the diagonals could become a tiny negative number. I'm not sure of the best way to handle this—just clip to zero?Any thoughts would be appreciated. I'm not dead set on this approach, so if I custom Gaussian is still preferred, I'm happy to go back to that.