# Bayes Filter

A Bayes filter is a recursive algorithm that uses Bayes Rule to perform State Estimation.

This was encountered when learning about F1TENTH. Then learned more about this through CS287. Really useful for example to do Localization. Fully understand reading Kalman Filter book.

### Kalman Filter Book

Learned about a discrete Bayes filter first, to then understand Kalman Filter afterwards.

We have two fundamental equations for discrete bayes: $x=x∗f_{x}(∙)predict step$ $x=∥L⋅x∥update step$

- $f_{x}(∙)$ is the state propagation function for $x$
- $∗$ is a Convolution
- $L$ is the likelihood function, $∥∥$ because we are taking the norm

The 2 Major Steps

Prediction

- uses the system model to predict the state of the system based on the previous state estimate and the control inputs to the system

Update

- uses the current measurement to correct the previous state estimate, and produce a new, more accurate state estimate

Important terminology:

- Prior $x$ (prediction)
- Computed after the predict step
- Essentially predicting the state purely on your control input, you aren’t measuring anything

- Posterior $x$ (estimated state)
- Computed from the update step
- this is refining your estimate based on the new measurements that has come in, which is why it’s called the behavior: new probability given data

Why do we need both predict and update steps?

If we only form estimates from the measurement (update step) then the prediction will not affect the result. If we only form estimates from the prediction (predict step) then the measurement will be ignored.

- If this is to work we need to take some kind of
blend of the prediction and measurement.

Here is an example of where you are continually predicting, without making updates. Your belief just ends up converging to no state. This is because you’re not actually using your measurements.

The update step is actually the more crucial component. Predict step is fairly straghtforward.

So how does the update step look like?

How to think of likelihood

Think of likelihood as just your state probability distribution (non-normalized) with your sensor data. Your measurements directly measure state.

- Input is optional and depends on situation, else the predict step is simply setting the prior as 1

Example

For a moving robot, the control input is in the predict step, and the the odometry measurement (wheel enocders) is in the update step

An example for discrete bayes (see chapter 2 for full example)

### CS287

Given:

- Stream of observations $z$ and action data $u$
- Sensor model $P(z∣x)$
- Action model $P(x_{′}∣u,x)$
- Prior probability of the system state $P(x)$

We want an estimate of the state $X$ of a dynamical system, essentially $P(x∣z)$, so we use Bayes Rule

We do doing using by updating the posterior of the state, which we call **belief**:

$Bel(x_{t})=P(x∣u_{1},z_{1},…,u_{t},z_{t})$

Bayes Filter allow us to recursively update our belief state using the equation $Bel(x_{t})=nP(z_{t}∣x_{t})∫P(x_{t}∣u_{t},x_{t−1})Bel(x_{t−1})dx_{t−1}$ where

- $n$ is the normalization constant, to make sure everything adds up to 1
- $p(z_{t}∣x_{t})$ is the observation Likelihood sensor model
- Transition model, motion model (simulate noisy dynamics of particles based on control input)

Important

Bayes rule make use of the Markov Assumption.

Derivation from CS287

We can then come up with an algorithm to do this: