Repository navigation
fix: correct covariance computation in Ensemble Kalman Filter - #1528
Open
Zero-State-Logic wants to merge 1 commit into
Open
Zero-State-Logic wants to merge 1 commit into
Zero-State-Logic wants to merge 1 commit into
Conversation
calc_covariance computed `px[:, i] - xEst`, subtracting a (4, 1) column vector from a 1-D (4,) particle. NumPy broadcasts these to a (4, 4) array instead of a per-particle residual, so the 3x3 result summed squared differences over all four state components (including the unrelated velocity) and filled every entry identically. The returned matrix was therefore not the position/orientation covariance, and the covariance ellipse drawn in the simulation was wrong (a degenerate, rank-1 shape). Take the first three components of both the particle and the ensemble mean explicitly, build the residual as a (3, 1) column, accumulate the proper outer product, and normalize by the actual ensemble size. Also add tests for this previously untested module: a regression test pinning the covariance for a known ensemble, a symmetry / PSD check, and a short simulation smoke test.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Reference issue
N/A — defect found by code review (no existing issue; the ensemble_kalman_filter module had no tests).
What does this implement/fix?
calc_covariancein Localization/ensemble_kalman_filter computedpx[:, i] - xEst, subtracting a (4, 1) column (xEst) from a 1-D (4,) particle. NumPy broadcasts these to a (4, 4) array instead of a per-particle residual, so the 3x3 result summed squared differences over all four state components (including the unrelated velocity) and filled every entry identically. The returned matrix was therefore not the position/orientation covariance, and the covariance ellipse drawn in the simulation was a degenerate (rank-1) shape.The fix takes the first three state components of both the particle and the ensemble mean explicitly, builds the residual as a (3, 1) column, accumulates the proper outer product, and normalizes by the ensemble size. Behavior of the real simulation call is unchanged except for the now-correct covariance.
Additional information
Verified with a known 2-particle ensemble: before, calc_covariance returned a constant matrix dominated by the velocity component; after, it matches the population covariance of [x, y, yaw]. The module had no test file, so this PR adds tests/test_ensemble_kalman_filter.py with a regression test (fails on the old code, passes on the new), a symmetry/PSD check, and a short simulation smoke test (run without animation).
CheckList