-
Notifications
You must be signed in to change notification settings - Fork 61
Add radar example to test Kalman filter #785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -406,6 +406,61 @@ def sa_from_np(arr: np.ndarray, cls): | |
| raise ValueError("sa_from_np supports only 1D or 2D arrays") | ||
|
|
||
|
|
||
| class KalmanFilterRadarExampleTC(unittest.TestCase): | ||
|
|
||
| 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]) | ||
|
Comment on lines
+411
to
+424
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The following testcase could be found in the reference. |
||
|
|
||
| kf = mm.KalmanFilterFp64( | ||
| x=sa_from_np(x0, mm.SimpleArrayFloat64), | ||
| f=sa_from_np(f, mm.SimpleArrayFloat64), | ||
| h=sa_from_np(h, mm.SimpleArrayFloat64), | ||
| q=sa_from_np(q, mm.SimpleArrayFloat64), | ||
| r=sa_from_np(r, mm.SimpleArrayFloat64), | ||
| p=sa_from_np(p0, mm.SimpleArrayFloat64), | ||
| jitter=0.0, | ||
| ) | ||
|
|
||
| kf.predict() | ||
|
|
||
| x_pred_expected = np.array([11000.0, 200.0]) | ||
| p_pred_expected = np.array([[28.5, 3.75], | ||
| [3.75, 1.25]]) | ||
|
|
||
| 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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the atol here different from the one on line 454 ?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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).
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| kf.update(sa_from_np(z1, mm.SimpleArrayFloat64)) | ||
|
|
||
| x_update_expected = np.array([ | ||
| 11009.371124889283, | ||
| 201.42604074402126, | ||
| ]) | ||
| p_update_expected = np.array([ | ||
| [14.572187776793623, 1.4348981399468559], | ||
| [1.4348981399468559, 0.7074844995571303], | ||
| ]) | ||
|
|
||
| np.testing.assert_allclose( | ||
| kf.state.ndarray, x_update_expected, atol=1e-12, rtol=0.0) | ||
| np.testing.assert_allclose( | ||
| kf.covariance.ndarray, p_update_expected, atol=1e-12, rtol=0.0) | ||
|
|
||
|
|
||
| class TestKnownIssues603(unittest.TestCase): | ||
|
|
||
| @unittest.expectedFailure | ||
|
|
||
There was a problem hiding this comment.
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.