Kalman Filter Interview
By: Harveen Singh Chadha
Tags: Artificial Intelligence, Kalman Filter, Udacity, Self Driving Cars, Robotics

Larry: What is a Kalman Filter?

Me: A Kalman Filter is a tool that helps to predict values.

Larry: Well that is cool! Means it is something sort of an astrologer?

Me: Well, not quite. It is an iterative mathematical process that uses a set of equations and consecutive data inputs to estimate the values we are interested in associated with the object quickly. Basically it is all quick mathematics!

Larry: I was not that good in Mathematics! Maybe this sounds a little bit absurd to me. Can you please go on?

Me: Okay the first thing, kalman filters work with gaussians or normal distribution.

Larry: Normal Distribution?

Me: In a continuous graph data can be spread out in different ways: Either it can be spread to the left, or to the right or jumbled up.

Figure 1. Example of left skewed and right skewed distribution (image source)

But there are many cases where data tends to be around a cental value with no bias left or right and the resulting distribution is called a normal distribution or a gaussian or a bell’s curve.

Figure 2. Example of a normal distribution, looks like a bell hence bell curve. (image source)

Larry: Got it! As you pointed out this is a continuous curve and not a discrete valued. How do I find out say the probability of getting a 5 on a roll of dice?

Me: Well, Good question, but to represent such distributions like probability of getting a dice we use binomial distribution as it is discrete valued. Here in normal distribution you need to define a range. Say, what is the probability of getting rain between 4.5 to 5.5 cm. So in this case we have a normal distribution, we mark the points and we calculate the area under these points which gives us the probability.

Larry: Oh! So the area of complete graph will be 1 as the probability can have a maximum value of 1?

Me: Absolutely right, additionally the mean, median and mode all are equal in case of this distribution.

Larry: But you did not represented the Gaussian in mathematical terms?

Me: So, to define a Gaussian, we have basically two things- mean and variance.

Mean(μ) you obviously know, Variance(σ²) basically tells how much the numbers are spread out and how far are they from mean. Standard Deviation(σ) is just the square root of Variance(σ²) given by formula-:

Larry: So how is a Gaussian related to Kalman Filter?

Me: Hmm! A Gaussian in a Kalman Filter represents the predicted value with noise/error/uncertainty in our prediction often known as the variance. The predicted value is centered around the mean with the width of the Gaussian denoting the uncertainty in our value. Basically it tells how much sure we are of a certain value to be true. More the width of the Gaussian denotes more uncertainty.

Larry: Ohk! You played a bit of polymorphism game here. You mentioned earlier that it is an iterative process?

Me: Yup, It is basically a two step process-

1. Predict

2. Update

In Predict we just predict the new value called predicted value based on the initial value and then predict the uncertainty/error/variance in our prediction according to the various process noises present in the system.

In Update, we take in account the actual measurement coming from the device and we call this as measured value. Here we calculate the difference between our predicted value and measured value and then decide which value to keep by calculating the Kalman Gain. We then calculate the new value and new uncertainty/error/variance based on our decision made by Kalman Gain. These calculated values will finally be the predictions done by our Kalman Filter in iteration 1.

The output of the update step is again fed into the Predict State and the cycle goes on until the error/uncertainty between our predicted and actual values tends to converge to zero.

Larry: Well, that was pretty fast. Can you please explain in terms of any example or a flowchart?

Me: Ok, so from now on these notations will be followed:

x -> Mean

P -> Variance

Figure 3. A Rough Flowchart for Kalman Filter

Larry: Seems Intuitive! But what the hell is Kalman Gain?

Me: Kalman Gain is a parameter which decides how much weight should be given to predicted value and measured value. It is a parameter that decides whether our actual value is close to predicted value or measured value.

Larry: But how does it know how to trust either the predicted value or actual value?

Me: It checks the uncertainty/error my friend.

K = Error In Prediction / (Error in Prediction + Error in Measurement)

The value of the K ranges from 0 to 1. If we have a large error in measurement, K is nearer to 0,this means our predicted value is close to actual value. If we have a large error in prediction, K is closer to 1, this means our measured value is closer to actual value.

Larry: Ok, Agreed! I am getting excited now. Can you please elaborate on the equations now?

Me: Sure. I will write it down for you differently for the prediction and update step. Remember these equations are for 2D space.

Figure 4. Equations for Predict Step