The Kalman Filter
Finally...
We've gotten to the Kalman Filter. Up to this point, I've covered markov models, hidden markov models and the problems that can be solved with them (filtering, smoothing, decoding, etc), Bayes filters, Linear Algebra, and the strategy for optimally combining estimators linearly. In this post, I will bring everything together with the Kalman Filter.
To put it concisely, the Kalman Filter is the optimal solution to the Bayes Filter for systems with linear dynamics and Gaussian Noise. What does this mean? Well let me review:
Markov Models, Hidden Markov Models, and the new Markov Decision Process (MDP)
An MDP describes a "stochastic dynamic system" -- a process where our state transitions from one to another depending on some control input, yet there is noise associated with the state transition. We are unsure of whether or not the stated control input will translate to the update in state that we are expecting. If our state transition dynamics are described by a function , the markov decision process can be represented mathematically as:
Since the transition is stochastic, not deterministic, the state transition can alternatively be represented as a probability distribution:
This situation is similar to the traditional Markov Model except that, for each control input, we have a separate transition matrix.
Lastly, since this situation describes the system modeled by the Kalman Filter, a linear stochastic system is formulated as follows:
Consider one more thing -- our observations in an HMM do not necessarily directly represent our state. It may be the case that our state is position and our GPS measures this position with some noice. However, it may be that the relation is less direct. What is the analogy for a more linear stochastic system? ** MORE ANALOGY **
Incorporating Gaussian Observations of a State Linearly
Imagine our sensor relates to the d-dimensional state through a linear function but it has some zero-mean Gaussian noise associated with it:
Notice the dimensionality of is but our state has dimension . Therefore, our matrix must have shape . Additionally, we have .
It's similar to how, in an HMM, our emission matrix may not be square. We could have more observations than state, or less.
New Estimate:
Substituting:
Covariance using independence assumption:
Now how can we minimize the trace of the covariance of the updated estimator with respect to ? My matrix calculus is not solid enough for this, so I'll have to take their word:
Now notice what happens if we set (the observation directly estimates state):
Substituting back into our previous formula:
Kalman Filter
Now that we know how to update an estimator using an observation which is a linear function of the hidden state, I can now introduce the Kalman Filter.
The system can be described as follows:
with and .
The first equation describes how the state evolves over time. As you can see, the future state without incoorporating observation is a linear function of the input. Since everything is linear, all states will be gaussians. Therefore, they can be described completely using the mean and covariance. As a result, we only need to figure out what the and are at each step.
The Kalman Filter proceeds in two distinct steps, similar to the Bayes Filter. First, the state is propoagated independently of any observations using our model of the system's dynamics. Next, when we get an observation, we update the state estimate. There's some notation I want to introduce to make this a bit clearer:
Therefore, given and we want to get . This requires us to first propagate to , and then factor observation .
Propagation
First, we want to find , or :
Observation
Now we have but need to update with our most recent observation.
So recall our formula from before:
Now we need to propagate the means:
Or we can used the condensed form for
Notice that we really have two different formulations of the Kalman Filter update step:
and
I generally favor the clarity of the second. It shows that we have some noisy estimate from our dynamics model and some noisy estimate from our sensor model , and we essentially want to update the estimate with this noisy observation. The way we do that is by taking the difference of our observation from what our dynamics model would have expected the observation to be (basically the new information added by our observation) and then scaling it by some factor related to both the covariance of the estimate and the observation. If we have a noisier observation, will be smaller.
By using the form or, equivalently, , we enforce that our estimated value is unbiased. Then, by minimizing the trace of the covariance of the new estimator with respect to , we find the optimal formulation for combining the estimate and observation.
I hope this is relatively intuitive by this point. Although the matrix calculus is a bit over my head, I think previous examples give sufficient understanding for why the Kalman Filter is the optimal linear estimator for a system with Gaussian noise.