# TIL - Bayes Filters

** Published:**

I am doing a course in Robot Localisation and Mapping this semester which shall hopefully trigger a bunch of posts where I try to explain concepts in the course to myself. Here is the first in that series, Bayes Filter: the foundational algorithm for state estimation.

# Some context

We have a robot in some environment. This robot might have position (termed as pose) and the environment might have some configuation as well. This combination of the robot position plus the environment configuration is termed as a **state**. Now, the robot can perform some action, which may or may not change the state. The idea of robot performing an action is called a **control**. Finally, the robot can try to sense it’s environment and make some observations (take an image, report a lidar reading etc.) which is called a **measurement**.

Bayes filter (and consecutively many more things in SLAM in general) are an interplay of these states, measurements and controls. We assume that nothing is certain and hence completely work with probability distrubutions to make inferences. Our goal is to have some **belief** about the **state** of the robot given the measurements the robot is making.

# So, what is a Bayes Filter?

From what I understood so far, Bayes Filter is an algorithm/framework that let’s you calculate ( and progressively refine ) an estimate of the the state of a robot (plus environment) using the various controls that robot is executing and the measurements that the robot is noting. Just to fuel the imagination, controls can mean moving around, opening a door, picking an object etc. Similarly measurements can mean the odometry reading, pictures, lidar scans etc.

Let the random variable x represent the state of the system. This means, x is a probability distribution function that gives the probability associate with each possible state. Now, what we do in bayes filter is to start with some initialisation for x (generally a uniform probability distribution) and then we update x to incorporate our controls and measurements. states are defined at different discreet units of time. So we start with x_{0} and successively calculate x_{1}, x_{2} etc.

# Understanding the algorithm

Formally the algorithm is as follows

Algorithm Bayes_filter(bel(x_{t−1}), u_{t}, z_{t}):

- for all xt do
bel_hat(x _{t}) = Integral(p(x_{t}u _{t}, x_{t−1}) bel(x_{t−1}) dx_{t−1})bel(x _{t}) = η p(z_{t}x _{t}) bel_hat(x_{t})- endfor
- return bel(x
_{t})

So bel_hat is what we call the prediction. If we know the previous state and the control execute in this state, we can have a prediction for our current state. If you look at step 2, all we are doing is calculating is the expected value of the probability of each state. Whereas step 3 is an application of bayes rule, which incorporates our mearument in our calculation of belief.

Look at step 2 again. We are taking each possible state at time t-1 and multiplying the probability associated with being in that state with the probability that control u_{t} lead to a state transition from x_{t-1} to x_{t}

In step 3, we are calculating the probability of a particular state (x_{ t }) given the measurement ( z _{ t }) by using bayes rules.

# I am still a little hazy, how should I solidify what I understood

Nothing is better than an example. head over to section 2.4.2 in Probabilitic Robotics by Thrun et. al.