Kalman Filter
Ground truth: y = 1.0, generate noisy data.
1 | def generate_data(num=100): |
Assume we have the prediction model y = x (which means the signal is constant), and observation model is also set to y = x
1 | F = 1. |
Set variance and initial value:
1 | # prediction variance: Q, observation variance: R |
Applying the filter:
1 | for i in range(NUM): |
Here we tend to believe our observation, so the result:
If we tend to believe our model,
1 | # prediction variance: Q, observation variance: R |
KF is not sensitive to the initial value, we can set it very wrong.
1 | # initial value |
And it will be corrected very soon.
Finally, if the actual model is a bit more complicated, and our prediction model doesn’t match it at all:
1 | # truth y = x ** 2 |
KF can still improve the result a bit.