Great question! The Kalman Filter uses mathematical models to estimate the uncertainty of both its predictions and measurements, and then combines them optimally. Here's a simplified breakdown:
1. How It Quantifies Uncertainty
The Kalman Filter doesn’t guess or "know" uncertainty—it uses mathematical representations of uncertainty called covariance matrices. These matrices describe how much the system’s state (e.g., position, velocity) is expected to vary due to noise.
Key Concepts:
- Process Noise (Q): Represents the uncertainty in the system's dynamics (e.g., how unpredictable the cat’s movement is).
- If the cat can suddenly change direction, Q is large.
- If the cat moves smoothly, Q is small.
- Measurement Noise (R): Represents the uncertainty in the sensor readings (e.g., how inaccurate the sonar is).
- If the sonar is noisy, R is large.
- If the sonar is precise, R is small.
These values (Q and R) are defined by the user based on their knowledge of the system. The filter doesn’t "learn" them automatically—it uses them as inputs.
2. How It Decides What to Trust
The Kalman Filter uses a Kalman Gain (a mathematical value between 0 and 1) to determine how much to trust the prediction versus the measurement. Here’s how it works:
Step-by-Step:
-
Predict Step:
- The filter predicts the next state (e.g., the cat’s position) based on its previous state and a model of how the system behaves.
- It also predicts the uncertainty of this prediction (using Q).
-
Measure Step:
- The filter gets a new measurement (e.g., the sonar’s reading).
- It also knows the uncertainty of this measurement (using R).
-
Update Step (Kalman Gain):
- The filter calculates how much to adjust the prediction based on the measurement.
- If the prediction is very uncertain (high Q) or the measurement is very certain (low R), the filter will trust the measurement more.
- If the prediction is very certain (low Q) or the measurement is very uncertain (high R), the filter will trust the prediction more.
Mathematically:
Kalman Gain (K) = (Prediction Uncertainty) / (Prediction Uncertainty + Measurement Uncertainty)
- If K is close to 1, the filter trusts the measurement.
- If K is close to 0, the filter trusts the prediction.
3. Example: GPS in a Car
Imagine you’re driving and your GPS loses signal (no measurement).
- Prediction: The filter uses your last known position, speed, and direction (with process noise Q).
- Measurement: When the signal returns, the GPS gives a new position (with measurement noise R).
- The filter blends the two:
- If the GPS is accurate (low R), it updates your position sharply.
- If the GPS is noisy (high R), it keeps your predicted position closer to the last known state.
4. Why It Works
The Kalman Filter is a mathematical optimization that:
- Uses probabilistic models (like Gaussian distributions) to represent uncertainty.
- Combines predictions and measurements in a way that minimizes the overall error.
- Adapts dynamically as new data comes in.
In Summary
- The Kalman Filter doesn’t "know" uncertainty—it uses predefined noise parameters (Q and R) to model it.
- It uses the Kalman Gain to balance predictions and measurements based on their relative uncertainties.
- The result is a smarter, more accurate estimate than either the prediction or measurement alone.
Think of it like a self-correcting compass: it uses your best guess (prediction) and a shaky sensor (measurement) to give you a better direction.