Notes from Probabilistic Robotics
by Sebastian THRUN
Probabilistic Robotics by Sebastian Thrun aimed to teach me how to model uncertainty in robot perception and control using probabilistic techniques. It introduced me to Bayesian filters, Kalman filters, particle filters, and Markov decision processes. The book focused on decision-making, localization, mapping, and sensor fusion, all of which were crucial for navigating dynamic environments. I’m still not done reading it
Will Learn
- State Estimation
- Gaussian filter (Bayes Filter)
- Kalman filter
- Non parametricc filter
- Robot Localization
- MonteCarlo Localixzation
- SLAM
- Extended Information form Algorithm
- Markov Decision Process
Why Learn This?
Robotics? Robotics is increasingly becoming a software science, a distinct field due ti its increasing complexity. Its the understanding and making sense out of uncertainty. And this will deepen your knowledge of probability.
Notes
Introduction
- Prior - a distribution that represents the accumulated past . A uniform distribution prior = maximum uncertainty
- Belief from Bayes theorem is a probability distribution of the likelihood of each state against the possible existing state. where is the belief at state , is the prior at state is the internal state (measurement) represents noise from control action
- Posterior is the update prior upon incorperating observation.
Recursive State Estimation
- notations
- formal description of model
- Bayes filter
- Understand example given
- Read the Bayes filter formula proof
theorem of total probabilities
Note: Posterior probability distribution over X is given is the prior probability distribution (if is the pdf of X)
-
In robotics, this inverse probability is often coined “generative model,” since it describes, at some level of abstraction, how state variables X cause sensor measurements Y.
, usually called the Normalizer
-
The expectation is a linear function of a random variable. In particular, we have
so,
-
Another important characteristic of a random variable is its entropy. entropy will be used in robotic information gathering.
-
Conditional independence , does not neccessarily mean absolute independence . In special cases, however, conditional and absolute independence may coincide.
-
The robot pose is often referred to as kinematic state.
-
Control(motion) and Perception(measurement) are two complementary modular concepts used in robotics. Control performs actions on an evironment, and thereby distorting it due to inaccuracy of its actuator. Perception is the sensing and understanding of the environment. Its errors are primarily due to inaccurate sensor reading. Both are treated seperately to serve as a conceptual tool rather than distinction in space and time For example, Pathfinding is control and SLAM is Perception
-
The probability is the state transition probability. The probability is called the measurement probability.
-
It can be noticed that from tee formula of the belief, measurement of state t are needed for calculation of belief(aka correction) , however in reality, the measurement update is calculated using prior state measurement.
pseudo code
def bayes_filter(belief_x1, u_t, z_t): for x_t in states: posterior = p(x2 | u2, x1) measurement_update = integal(posterior * belief_x1) # corrected belief using generative model correction = normalizer * measurement_prob * measurement_update return correction
pseudo code 2
def bayes_filter(bef_x_prev, u_t, z_t): """ Parameters: - bef_x_prev: Belief at time t-1 (prior) - u_t: Action at time t - z_t: Observation at time t Returns: - bef_x_t: Updated belief at time t """ bef_x_t = {}
# Prediction Step (Motion Update) for x_t in states: # Compute prediction for x_t by marginalizing over x_{t-1} predicted_belief = sum( motion_model(x_t, u_t, x_prev) * bef_x_prev[x_prev] for x_prev in states )
# Measurement Update (Correction) measurement_prob = measurement_model(z_t, x_t) bef_x_t[x_t] = measurement_prob * predicted_belief
# Normalization normalizer = sum(bef_x_t.values()) for x_t in bef_x_t: bef_x_t[x_t] /= normalizer
return bef_x_t
NOTE
-
The Bayes filter makes a Markov assumption that specifies that the state is a complete summary of the past. This assumption implies the belief is sufficient to represent the past history of the robot. In robotics, the Markov assumption is usually only an approximation. There are conditions under which it is violated.
-
Since the Bayes filter is not a practical algorithm, in that it cannot be implemented on a digital computer, probabilistic algorithms use tractable approximations. Such approximations may be evaluated according to different criteria, relating to their accuracy, efficiency, and ease of implementation.
Example
Our illustration of the Bayes filter algorithm is based on a scenario, where a robot estimating the state of a door using its camera. To make this problem simple, let us assume that the door can be in one of two possible states, open or closed, and that only the robot can change the state of the door. Let us furthermore assume that the robot does not know the state of the door initially. Instead, it assigns equal prior probability to the two possible door states
Solution
-
the initial belief a door is closed open open is uniform
-
confusion matrix of sensor data conditioned on the ground truth. ie
Also the state transition probability table
Previous State | Action | New State | Probability |
---|---|---|---|
isOpen | push | isOpen | 1.0 |
isOpen | push | isClosed | 0.0 |
isClosed | push | isOpen | 0.8 |
isClosed | push | isClosed | 0.2 |
isOpen | do nothing | isOpen | 1.0 |
isOpen | do nothing | isClosed | 0.0 |
isClosed | do nothing | isOpen | 0.0 |
isClosed | do nothing | isClosed | 1.0 |
the predictive distribution.
.
So say the next action is a push,
So, the robot believes with accuracy that the door is closed. At first glance, this probability may appear to be sufficiently high to simply accept this hypothesis as the world state and act accordingly. However, such an approach may result in unnecessarily high costs. If mistaking a closed door for an open one incurs costs (e.g., the robot crashes into a door), considering both hypotheses in the decision making process will be essential, as unlikely as one of them may be.
Summary
Term | Mathematical Expression | Description |
---|---|---|
Posterior (Belief) | The updated belief after incorporating observations up to time . It reflects the most current state. | |
Predictive Distribution (Predicted Belief) | The prior prediction of the state at time , before incorporating the new observation at time . | |
Measurement Likelihood | The probability of observing given the state . It describes how likely the measurement is given the state. | |
State Transition Model | The dynamics model, describing how the state evolves from the previous state given control input . | |
Normalizing Constant (Marginal Likelihood) | The normalization factor that ensures the posterior is a valid probability distribution. Often calculated as | |
Prior Distribution | The distribution of the state at time before considering control input or measurements, typically used in Bayesian models. |
Gaussian Filters
What is canonical representation(natural representation) and moments representation?
The representation of a Gaussian by its mean and covariance is called the moments representation. the mean and covariance are the first and second moments of probability distribution
- The Kalman filter was invented in the 1950s by Rudolph Emil Kalman,
- Kalman filters is not applicable to discrete or hybrid state spaces but for continuous state spaces.
- In Kalman filters the state transition model is considered to be a multivariate guassian with the mean being and covariance of .
- The measurement probability must be linear in its arguments , where is the measurement noise with mean 0 and covariance ie has a mean of .
- The initial belief must be normal distributed. by and covariance .
Kalman Filter Algorithm
Given the following inputs:
- : State transition matrix
- : Control matrix
- : Measurement matrix
- : Process noise covariance
- : Measurement noise covariance
- : Previous state estimate
- : Previous state covariance estimate
- : Control input
- : Measurement
Step 1: Prediction
The predicted state estimate is:
The predicted covariance estimate is:
These variables are the moment representation of the predictive distribution of bayes filter,
Step 2: Update (Correction)
The Kalman Gain is:
The updated state estimate is:
The updated covariance estimate is:
Similarly these and are the moment representation of belief, akin to that in that of bayes filters of bayes filter
Return
- ,
def kalman_filter(A, B, C, R, Q, mu_prev, Sigma_prev, u, z): """ A: State transition matrix B: Control matrix C: Measurement matrix R: Process noise covariance Q: Measurement noise covariance mu_prev: Previous state estimate (mu_{t-1}) Sigma_prev: Previous state covariance estimate (Sigma_{t-1}) u: Control input (u_t) z: Measurement (z_t)
Returns: Updated state estimate and covariance (mu_t, Sigma_t) """
# **Prediction Step**
# Predicted state estimate (mu_t^pred) mu_pred = np.dot(A, mu_prev) + np.dot(B, u)
# Predicted covariance estimate (Sigma_t^pred) Sigma_pred = np.dot(np.dot(A, Sigma_prev), A.T) + R
# **Update Step**
# Compute Kalman Gain (K_t) K = np.dot(np.dot(Sigma_pred, C.T), np.linalg.inv(np.dot(np.dot(C, Sigma_pred), C.T) + Q))
# Update state estimate (mu_t) mu_t = mu_pred + np.dot(K, (z - np.dot(C, mu_pred)))
# Update covariance estimate (Sigma_t) Sigma_t = np.dot(np.eye(len(Sigma_pred)) - np.dot(K, C), Sigma_pred)
return mu_t, Sigma_t
Summary of Kalman Filter
-
Probably the best studied technique for implementing the Bayes filter is the Kalman Filter. Gaussians have two repesentation
- Canonical Representation
- Moments Representation (mean and variance)
-
Like the vanilla bayes filter, Kalman filter are represented by stochastic probabilies and beliefs
-
Unlike the vanilla bayes filter, the next state are predicted linearly from state vectors and control vector. ie .
-
Making the state transition distribution, , is a PDF function of the gaussian.
- Similary the measurement and state are linearly related. and its PDF is the measurement probability, .
-
The kalman filter algorithm :
- - prediction step for mean
- - prediction step for covar.
- - is the Kalman gain, mean-squared error formula
- - update step for mean
- - update step for covar.
- return
-
Complexity = approximately
-
Also a thing to always remember is in KF. the state tranistion probability, measurement update and the belief are assumed to be a perfect normal distribution ie — (at the very least considered so when used in the moments representation)
Extended Kalman Filters
In practice, the assumptions of linear stae transitions and linear measurements with added gaussian nose are rearely fulfilled. Fore example, a robot that moves with constant translational and rotational velocity typically moves on a circular trajectory which cannot be described by linear next state transitions.
Also, unlike in vanilla KF. our and are governed by non linear functions g
and h
.
Unfortunately with non-linear g
and h
, the belief is no longer a true gaussuan but an appoximation. Thus, the EKF inherits from the Kalman filter the basic representation, but it differs in that this belief is only approximate, not exact as was the case in Kalman filters.
The key idea underlying the EKF is linearization. Linearizatino approximated g
by a linear function that is tangent to g
at the mean of the Gaussian. There exist many techniques for linearizing non-linear functions. EKFs utilize (First order) Taylor expansion.
Extrapolation is achieved by a term proportional to the gradient of at and :
Note that is a matrix written as gaussian, the matrix is a Jacobian. the next stae probabilty is approximated as follows:
Why is known as a Jacobian
because it differs for different points in time. that is and .
The same method for state transition probability applies for measurement update and .
Algorithm
The Extended Kalman Filter algorithm :
- - prediction step for mean(state pred.)
- - prediction step for covariance
- - is the Kalman gain
- - update step for mean, (using meas. pred.)
- - update step for covariance
- return
Information Filter
The dual of Kalman filter is the information filter. Similar to KF and EKF, the belief is a guassian-ish.
Difference between K.F and I.F
Whereas in the Kalman filter family of algorithms, Gaussians are represented by their moments (mean, covariance), information filters represent Gaussians in their canonical representation, which is comprised of an information matrix and an information vector.
The information matrix, is the inverse of the covariance. and the information vector, is the product of the covariance inverse and the mean. So, it is easy to see that and are a complete parameterization of a Gaussian.
Why the canonical representation?
In many ways, the canonical representation is more elegant than the moments representation. In particular, the negative logarithm of the Gaussian (which plays an essential role in information theory) is a quadratic function in the canonical parameters and :
Here is a constant. The reader may notice that we cannot use the symbol to denote this constant, since negative logarithms of probabilities do not normalize to .
The negative logarithm of our distribution is quadratic in , with the quadratic term parameterized by and the linear term by . In fact, for Gaussians, must be positive semidefinite, hence is a quadratic distance function with mean .
This is easily verified by setting the first derivative of (3.73) to zero:
The matrix determines the rate at which the l function increases in the different dimensions of the variable . A quadratic distance that is weighted by a matrix is called Mahalanobis distance.
Information Filter Algorithm
The Information Filter algorithm :
- - predicted information matrix
- - predicted information state
- - update step for information matrix
- - update step for information state
- return
Just like in K.F.
Extended Information Filter
Just like EKF is to KF, EIF is to IF. It has g and h functions to represent non-linearities in state transition space and measurement posterior. but in this case they are matrices
Algorithm
The Information Filter algorithm :
- - predicted information matrix
- - predicted information state
- - update step for information matrix
- - update step for information state
- return
Advantages of IF Over KF
- Handling Global Uncertainty: Setting Ω=0\Omega = 0Ω=0 in the information filter represents complete uncertainty, whereas in the Kalman filter, this corresponds to an infinite covariance, which is problematic in robotics.
- Better for Sparse Measurements: Sensor measurements often provide information about only a subset of state variables. The information filter naturally handles this, while EKFs require special provisions.
- Numerical Stability: Information filters tend to be more numerically stable than Kalman filters in many applications.
- Efficient Multi-Robot Data Fusion:
- Multi-robot problems require decentralized sensor fusion, which is naturally supported by information filters.
- Bayesian integration of sensor data becomes simple addition in logarithmic form, which is commutative and allows integration in any order, with arbitrary delays.
- The Kalman filter can also do this, but with higher computational overhead.
Disadvantages of the EIF
- Matrix Inversions in Nonlinear Systems:
- The EIF requires matrix inversions in both the prediction and update steps.
- EKFs often avoid inverting matrices of comparable size, making them more computationally efficient.
- Higher Computational Cost in High-Dimensional State Spaces:
- The need for frequent matrix inversions makes EIF computationally inferior for large state spaces.
- This is a major reason why EKFs are more widely used than EIFs.
Summary Notes
- Updating a Kalman filter based on a control is computationally simple, whereas incorporating a measurement is more difficult. The opposite is the case for the information filter, where incorporating a measurement is simple, but updating the filter based on a control is difficult.
- For both KF and IF, to calcualate the correct posterior three assumptions are made. and if it meats these assumptions it is called a linear gaussian system.
- The initial belief is gaussian
- State Transition Probability is a PDF linear in its argument (, ) with added independent noise
- Measurement Probability is a PDF linear in its argument with added independent noise
- Both filters can be extended to non-linear problems. This is basically computed using the tangent of the non-linear function at the mean because tangents are linear, making them applicable. This is done using its Taylor expansion and the result of this expansion results in a Jacobian matrix.
- The accuracy of Taylor expansion depends on two factors
- Degree of non-linearlity (the smaller the better)
- Width of the posterior (the smaller the covariance the better)
- Extended Kalman filter is more popular and frequently used that Extended Information Filter
- One of the primary advantages of Gaussian filters is computational: The update requires time polynomial in the dimensionality of the state space. This is not the case of some of the techniques described in the next chapter. The primary disadvantage is their confinement to unimodal Gaussian distributions.
Non Parametric Filters
- Histogram Filter
- Particle Filter
Nonparametric filters do not rely on a fixed functional form of the posterior, such as Gaussians. Instead, they approximate posteriors by a finite number of values, each roughly corresponding to a region in state space. Both types of techniques, histograms and particle filters, do not make strong parametric assumptions on the posterior density. In particular, they are well-suited to represent complex multimodal beliefs. For this reason, they are often the method of choice when a robot has to cope with phases of global uncertainty, and when it faces hard data association problems that yield separate, distinct hypotheses.
Histogram Filter
Histogram filters decompose the state space into finitely many regions, and represent the cumulative posterior for each region by a single probability value. they are of two kinds;
- Discrete Bayes Filter — for discrete spaces
- Histogram Filters — for continuous spaces
The discrete Bayes filter algorithm is popular in many areas of signal processing (such as speech recognition — is it still used currently? ), where it is often referred to as the forward pass of a hidden Markov models