KF Basics - Part 2
Probabilistic Generative Laws
1st Law:
The belief representing the state
represents the measurement the motion command the state (can be the position, velocity, etc) of the robot or its environment at time t.
‘If we know the state
Therefore the law now holds as:
2nd Law:
If
The filter works in two parts:
Conditional dependence and independence example:
Let’s say you flip two fair coins
A - Your first coin flip is heads
B - Your second coin flip is heads
C - Your first two flips were the same
A and B here are independent. However, A and B are conditionally dependent given C, since if you know C then your first coin flip will inform the other one.
A box contains two coins: a regular coin and one fake two-headed coin ((P(H)=1). I choose a coin at random and toss it twice. Define the following events.
A= First coin toss results in an H.
B= Second coin toss results in an H.
C= Coin 1 (regular) has been selected.
If we know A has occurred (i.e., the first coin toss has resulted in heads), we would guess that it is more likely that we have chosen Coin 2 than Coin 1. This in turn increases the conditional probability that B occurs. This suggests that A and B are not independent. On the other hand, given C (Coin 1 is selected), A and B are independent.
Bayes Rule:
Posterior =
Here,
Posterior = Probability of an event occurring based on certain evidence.
Likelihood = How probable is the evidence given the event.
Prior = Probability of the just the event occurring without having any evidence.
Marginal = Probability of the evidence given all the instances of events possible.
Example:
1% of women have breast cancer (and therefore 99% do not). 80% of mammograms detect breast cancer when it is there (and therefore 20% miss it). 9.6% of mammograms detect breast cancer when its not there (and therefore 90.4% correctly return a negative result).
We can turn the process above into an equation, which is Bayes Theorem. Here is the equation:
Bayes Filter Algorithm
The basic filter algorithm is:
for all
end.
Bayes filter localization example:
from IPython.display import Image
Image(filename="bayes_filter.png",width=400)

Given - A robot with a sensor to detect doorways along a hallway. Also, the robot knows how the hallway looks like but doesn’t know where it is in the map.
Initially(first scenario), it doesn’t know where it is with respect to the map and hence the belief assigns equal probability to each location in the map.
The first sensor reading is incorporated and it shows the presence of a door. Now the robot knows how the map looks like but cannot localize yet as map has 3 doors present. Therefore it assigns equal probability to each door present.
The robot now moves forward. This is the prediction step and the motion causes the robot to lose some of the information and hence the variance of the gaussians increase (diagram 4.). The final belief is convolution of posterior from previous step and the current state after motion. Also, the means shift on the right due to the motion.
Again, incorporating the measurement, the sensor senses a door and this time too the possibility of door is equal for the three door. This is where the filter’s magic kicks in. For the final belief (diagram 5.), the posterior calculated after sensing is mixed or convolution of previous posterior and measurement. It improves the robot’s belief at location near to the second door. The variance decreases and peaks.
Finally after series of iterations of motion and correction, the robot is able to localize itself with respect to the environment.(diagram 6.)
Do note that the robot knows the map but doesn’t know where exactly it is on the map.
Bayes and Kalman filter structure
The basic structure and the concept remains the same as bayes filter for Kalman. The only key difference is the mathematical representation of Kalman filter. The Kalman filter is nothing but a bayesian filter that uses Gaussians.
For a bayes filter to be a Kalman filter, each term of belief is now a gaussian, unlike histograms. The basic formulation for the bayes filter algorithm is:
Kalman Gain
Where x is posterior and
Therefore the mean of the posterior is given by:
In this form it is easy to see that we are scaling the measurement and the prior by weights:
The weights sum to one because the denominator is a normalization term.
We introduce a new term,
where
The variance in terms of the Kalman gain:
Kalman Filter - Univariate and Multivariate
Prediction
Correction
The details will be different than the univariate filter because these are vectors and matrices, but the concepts are exactly the same:
Use a Gaussian to represent our estimate of the state and error
Use a Gaussian to represent the measurement and its error
Use a Gaussian to represent the process model
Use the process model to predict the next state (the prior)
Form an estimate part way between the measurement and the prior
References:
Roger Labbe’s repo on Kalman Filters. (Majority of text in the notes are from this)
Probabilistic Robotics by Sebastian Thrun, Wolfram Burgard and Dieter Fox, MIT Press.