Skip to content

Add radar example to test Kalman filter#785

Open
ThreeMonth03 wants to merge 1 commit into
solvcon:masterfrom
ThreeMonth03:add_kf_test
Open

Add radar example to test Kalman filter#785
ThreeMonth03 wants to merge 1 commit into
solvcon:masterfrom
ThreeMonth03:add_kf_test

Conversation

@ThreeMonth03
Copy link
Copy Markdown
Collaborator

@ThreeMonth03 ThreeMonth03 commented May 16, 2026

For issue #685, to validate the implementation of Kalman filter algorithm, @j8xixo12 finds a real example from kalmanfilter.net .

This pull request add the website example to test Kalman filter.

Copy link
Copy Markdown
Collaborator Author

@ThreeMonth03 ThreeMonth03 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yungyuc @j8xixo12 @xingularity Please take a look. Thanks.

Comment on lines +181 to +183
array_type const & q, // FIXME: NOLINT(modernize-pass-by-value)
array_type const & r, // FIXME: NOLINT(modernize-pass-by-value)
array_type const & p, // FIXME: NOLINT(modernize-pass-by-value)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To determine the covariance matrix at the beginning, I create new constructor in KalmanFilter.

Comment thread tests/test_linalg.py
Comment on lines +411 to +424
def test_kalmanfilter_net_radar_example(self):
# Reference: https://kalmanfilter.net/
dt = 5.0
x0 = np.array([10000.0, 200.0])
f = np.array([[1.0, dt],
[0.0, 1.0]])
h = np.eye(2)
p0 = np.array([[16.0, 0.0],
[0.0, 0.25]])
q = np.array([[6.25, 2.5],
[2.5, 1.0]])
r = np.array([[36.0, 0.0],
[0.0, 2.25]])
z1 = np.array([11020.0, 202.0])
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following testcase could be found in the reference.

Comment thread tests/test_linalg.py
np.testing.assert_allclose(
kf.state.ndarray, x_pred_expected, atol=1e-12, rtol=0.0)
np.testing.assert_allclose(
kf.covariance.ndarray, p_pred_expected, atol=1e-12, rtol=0.0)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the atol here different from the one on line 454 ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error at line 454 is much bigger than line 445, so I set 1e-8 there. I would try to align the absolute difference (atol).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems you have increased the precision of the answer to reduce the error.

Copy link
Copy Markdown
Collaborator

@j8xixo12 j8xixo12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants