The Bayes Filter in Different Contexts
Bayes Filter
The Bayes Filter is a general algorithm for state estimation. A Kalman Filter, for example, is a specific implementation of the Bayes Filter and may be the most important algorithm in robotics. Due to the generality of the Bayes Filter, it was difficult for me to grasp the different applications. I've found that studying the implementation in different contexts helped me quite a bit. In this post, I'll cover two different scenarios where a Bayes Filter is useful: state estimation with a Hidden Markov Model (beginning with a regular Markov Model) and with an "Action Model".
Markov Model - Transitioning between states without observation
Our system can be in one of two states. The likelihood of transitioning to one state from another is summarized in a transition matrix:
If we're certain about the starting probability distribution (we know what state we're in), . We need to use the law of total probability to compute the probability of the next state or :
Equivalently:
This means is just the dot product of and the -th column of . Therefore, in general terms, we can compute by taking the dot product of and where is the transpose:
As , the distribution stops changing which gives us the steady-state distribution of the system. We can approximate the steady-state distribution by running the transition propagation algorithm many times, or exploit the fact that the distribution won't change as follows:
Therefore, the steady state distribution is just the eigenvector of for an eigenvalue .
Note that this is just a description of how the state would evolve without any observations that might help us refine our judgment. I haven't yet introduced the "hidden" aspect which lets us exploit observations -- so far it's just a Markov Model. At this point, the state at any timestep can be fully described by the starting state (which may be initialized using the steady-state distribution) and the transition matrix:
By computing this value for every state , we get the probability distribution of the state at time . This is what we want.
The markov model provides us a very clean method of representing the state of the system and how it evolves. It's all packaged up nicely. The action model is a bit less elegant, although it is more generally applicable.
Under the markov assumption, depends only on . However, in the above conditional probability, seems to depend on and . Because we don't know what will be, we must marginalize over all possible values of to express in a form which can be computed recursively and shows the Markov assumption more clearly. For the rest of this section, I won't show the explicit dependence on .
Oftentimes, the prior is also assumed implicitly:
I'll go with this notation because it's pretty clear that the recursion begins with . Finally, we can express the conditional in terms of the transition matrix:
Action Model -- Transitioning between states without observation
In the action model, our state is the position of a robot in a grid. We are given a list of actions over the timesteps along with probabilities related to how an action affects the state. This is known as the motion model, similar to in the hidden markov model. A robot can either move up, down, left, or right. It succeeds with probability and fails with probability . If the action would move the robot off the grid, it stays in place with absolute certainty ().
I think this approach lends itself more to a code implementation, although I won't get into those details in this post.
If our set of actions is , then our probability of interest is the state at time :
Once again, we can assume the prior implicitly: . Similar to the HMM, the dependence on the entire sequence of actions reflects the fact that there are many possible previous states given our model. If we knew the previous state, we could describe the current state just in terms of the previous state and the current action .
If we didn't know the previous state, we would marginalize over possible previous states:
To align more with the HMM notation, we could say that implicitly considers the current action and the same for the previous state, therefore expressing it as such:
However, it's convention to show that the distribution of the current state depends on the history of all previous states, so I will depart from the HMM notation from here on out. The idea is the exact same.
Including observations in the HMM estimate
Now let's say we have a set of observations which provide us some information about the probability (this matrix doesn't have to be square -- we can have more observation modalities than hidden states):
Now our state estimation objective must include the sequence of observations:
At this point, I think you get the idea about the notation basically being determined by clarity and preference, so I won't explain myself further.
If we knew the previous state, we could write . However, we must marginalize over all possible states of . I will use Bayes Rule in this derivation and the marginalization will appear.
Now observe this:
Replacing this in the original expression:
Defining a variable called will help simplify this expression. I'll also substitute and :
Finally, since the denominator doesn't depend on the state, we can consider this a normalizing factor to simplify. I'll come back to computing this later:
Including observations in the action model estimate
Now let's say we have a set of observations which provide us some information about the state. Maybe the points on the grid are painted either black or white and these values are known ahead of time. The sensor is noisy, correctly predicting the color with an accuracy of .9.
Our new state estimation objective:
Similar to before, I can calculate the normalizing factor as follows:
Substituting:
Since the denominator doesn't depend on the state, I'll let once again and substitute:
Since we don't have a clear definition for the transition (or motion model) and emission (sensor model), I will simply call create two functions and redefine in this context:
Finally, I will substite all these into the derived expression:
Finally, I will get to deriving . I'm only going to do it for the action model because they're basically the same, and I don't feel like doing the same thing twice!
I will include everything for a single Bayes filter in one equation because it's satisfying to look at. This means I'll have to rename variables to avoid overlap.
This is nice. Next stop, Kalman Filters. After that, Extended and Unscented Kalman Filters.