Sign in or create a free account to continue.

ROB-310 · Lesson 1 of 12 · 31 min

Uncertainty in robotics and probability review

A robot never knows exactly where it is. Its wheels slip, its encoders count in discrete ticks, its lidar returns are corrupted by dust and glass, its GNSS fix wanders by meters under trees, and the world itself changes as people walk past and doors open and close. A robot that ignores this uncertainty and trusts a single best guess will eventually drive into a wall when that guess turns out to be wrong. Probabilistic robotics takes the opposite view: the robot keeps track not of one estimate but of a probability distribution over everything it might need to know, updates that distribution as it moves and senses, and makes decisions that account for how confident it is. This course develops the tools that make this possible, from the Bayes filter through Kalman and particle filters to factor-graph smoothing, and ends with a complete localization design. This first lesson sets out where uncertainty comes from and reviews the probability that every later lesson uses.

Where uncertainty comes from

It helps to separate the sources of uncertainty, because each is handled differently. Sensor noise is the random scatter in measurements: a lidar range that reads 4.02 m, then 3.98 m, then 4.01 m for the same wall. Sensor limitations are systematic: a sonar cannot see a thin chair leg, a camera is blind in the dark, GNSS fails indoors. Actuation uncertainty comes from the gap between commanded and actual motion: a wheel commanded to turn 1 radian may turn 0.98 radians because of slip, backlash or uneven floors. Model uncertainty arises because every model of a robot or its environment is an approximation, from the assumed wheel radius to the map of the building. Finally, the world is dynamic: furniture moves, people appear, lighting changes. A probabilistic estimator models all of these as random variables with distributions, and its output is a belief, a distribution that summarizes what the robot knows.

The payoff is robustness. A robot that knows its position estimate has a standard deviation of 2 cm can safely pass through a doorway 10 cm wider than itself; one whose uncertainty has grown to 30 cm should slow down, look for landmarks, or ask for help. Probabilistic estimates also let a robot combine sensors sensibly: a precise but occasionally wrong sensor and a noisy but reliable one can be weighted according to their known uncertainties, so that the combination is better than either alone.

Random variables and distributions

A random variable X is a quantity whose value is uncertain, described by a probability distribution. For a discrete variable, such as which of ten corridor cells the robot is in, the distribution is a probability mass function p(x) with \( \sum_x p(x) = 1 \). For a continuous variable, such as the robot's x coordinate, it is a probability density function p(x) with \( \int p(x)\,dx = 1 \); probabilities come from integrating the density over an interval, and the density itself can exceed 1. Two summaries matter most. The mean or expected value is

\[\mu = E[X] = \int x\,p(x)\,dx\]

and the variance, which measures spread, is

\[\sigma^2 = E[(X - \mu)^2] = E[X^2] - \mu^2\]

The standard deviation σ has the same units as X and is the number engineers usually quote: 'the position is known to about 3 cm'. Expectation is linear, so \( E[aX + b] = aE[X] + b \), and variance scales with the square of a constant, \( \text{Var}(aX + b) = a^2\text{Var}(X) \). These two rules, applied to vectors, give the prediction step of the Kalman filter.

Worked problem

Mean and variance of a discrete belief

A robot believes it is in corridor cell 2 with probability 0.2, cell 3 with probability 0.5 and cell 4 with probability 0.3. Cells are 1 m wide and indexed by their center position in meters. Find the mean position and its standard deviation.

Show solution
  1. Mean: \( \mu = 2(0.2) + 3(0.5) + 4(0.3) = 0.4 + 1.5 + 1.2 = 3.1 \) m.
  2. \( E[X^2] = 4(0.2) + 9(0.5) + 16(0.3) = 0.8 + 4.5 + 4.8 = 10.1 \).
  3. Variance: \( 10.1 - 3.1^2 = 10.1 - 9.61 = 0.49 \) m².
  4. Standard deviation: \( \sqrt{0.49} = 0.7 \) m.

Answer: The mean position is 3.1 m with a standard deviation of 0.7 m. The mean need not be the most likely cell: here the most probable cell is 3 but the mean is pulled toward 4 by the larger probability on that side.

The Gaussian distribution

The Gaussian, or normal, distribution is the workhorse of estimation. In one dimension its density is

\[p(x) = \frac{1}{\sqrt{2\pi\sigma^2}}\exp\left(-\frac{(x - \mu)^2}{2\sigma^2}\right)\]

written \( X \sim \mathcal{N}(\mu, \sigma^2) \). About 68 % of the probability lies within one standard deviation of the mean, 95.4 % within two and 99.7 % within three, figures worth memorizing because they turn a reported σ into an intuitive range. Gaussians are popular for three reasons. Many physical noise sources are approximately Gaussian, because they are the sum of many small independent effects (the central limit theorem). A Gaussian is completely described by its mean and variance, so an estimator only has to track two numbers per variable. And Gaussians stay Gaussian under linear transformations and when combined by Bayes' rule with Gaussian measurements, which is exactly why the Kalman filter is exact for linear systems. Their weakness is that they are unimodal: a Gaussian cannot represent 'the robot is either at the north door or the south door', which is why lessons 2 and 8 introduce histogram and particle representations.

Left panel: three one-dimensional Gaussian curves centered at the same mean with standard deviations of 0.5, 1 and 2; the narrow curve is tall and the wide one is low and broad. Shaded bands mark one, two and three standard deviations on the middle curve. Right panel: a scatter of two-dimensional samples with a tilted ellipse drawn around them, its long axis running from lower left to upper right, showing positive correlation between x and y.
One-dimensional Gaussians of different spread, and a two-dimensional Gaussian with correlated components drawn as a covariance ellipse

Multivariate Gaussians and covariance

A robot's state is a vector, such as \( \mathbf{x} = [x, y, \theta]^{\mathsf{T}} \) for a planar mobile robot. The multivariate Gaussian generalizes the bell curve:

\[p(\mathbf{x}) = \frac{1}{\sqrt{(2\pi)^n\det\boldsymbol{\Sigma}}}\exp\left(-\tfrac{1}{2}(\mathbf{x} - \boldsymbol{\mu})^{\mathsf{T}}\boldsymbol{\Sigma}^{-1}(\mathbf{x} - \boldsymbol{\mu})\right)\]

The covariance matrix Σ is symmetric and positive definite. Its diagonal entries are the variances of each component; the off-diagonal entry \( \Sigma_{ij} = E[(x_i - \mu_i)(x_j - \mu_j)] \) is the covariance between components i and j. Dividing by the standard deviations gives the correlation coefficient \( \rho_{ij} = \Sigma_{ij}/(\sigma_i\sigma_j) \), between −1 and 1. Correlation matters enormously in robotics: after a robot drives forward while slightly uncertain about its heading, its sideways position error is strongly correlated with its heading error, because a heading error is what caused the sideways drift. A filter that ignored that correlation would make poor use of a later heading measurement, which should also correct the sideways position.

Surfaces of constant density are ellipsoids, \( (\mathbf{x} - \boldsymbol{\mu})^{\mathsf{T}}\boldsymbol{\Sigma}^{-1}(\mathbf{x} - \boldsymbol{\mu}) = c \). The quantity on the left is the squared Mahalanobis distance, the distance from the mean measured in standard deviations along each principal direction; it reappears in lesson 9 for rejecting outlier measurements. In two dimensions, the ellipse axes point along the eigenvectors of Σ and have half-lengths \( \sqrt{c\lambda_i} \), where \( \lambda_i \) are the eigenvalues. For two dimensions, the ellipse with c = 5.99 contains 95 % of the probability, and c = 2.30 contains about 68 %.

Worked problem

Drawing a covariance ellipse

A robot position estimate has covariance \( \boldsymbol{\Sigma} = \begin{bmatrix} 0.05 & 0.03 \\ 0.03 & 0.05 \end{bmatrix} \) m². Find the correlation coefficient and the semi-axes of the 95 % ellipse.

Show solution
  1. Standard deviations: \( \sigma_x = \sigma_y = \sqrt{0.05} = 0.224 \) m; correlation \( \rho = 0.03/0.05 = 0.6 \).
  2. Eigenvalues of a matrix with equal diagonal a and off-diagonal b are a ± b: \( \lambda_1 = 0.08 \), \( \lambda_2 = 0.02 \) m², with eigenvectors along the 45° and 135° lines.
  3. 95 % semi-axes: \( \sqrt{5.99 \times 0.08} = 0.69 \) m along 45°, and \( \sqrt{5.99 \times 0.02} = 0.35 \) m along 135°.

Answer: The components are positively correlated with ρ = 0.6, and the 95 % ellipse is tilted at 45° with semi-axes of 0.69 m and 0.35 m. Reporting only \( \sigma_x \) and \( \sigma_y \) would hide the fact that the robot is twice as uncertain along the diagonal as across it.

Joint, marginal and conditional probability

Three operations on distributions are used constantly. The joint distribution p(x, y) gives the probability of both values together. The marginal distribution of x is obtained by summing or integrating out the other variable, \( p(x) = \int p(x, y)\,dy \); this is the law of total probability, and it is exactly what the prediction step of every filter does when it integrates over the previous state. The conditional distribution of x given that y is known is

\[p(x \mid y) = \frac{p(x, y)}{p(y)}\]

so that \( p(x, y) = p(x \mid y)p(y) \). Two variables are independent when \( p(x, y) = p(x)p(y) \), meaning knowing y tells you nothing about x. They are conditionally independent given z when \( p(x, y \mid z) = p(x \mid z)p(y \mid z) \). Conditional independence, not full independence, is the assumption that makes robot estimation tractable: two lidar readings taken from the same pose are not independent (both depend on where the robot is), but given the pose they can often be treated as independent, because their remaining errors come from separate noise. For Gaussians, marginalizing simply means dropping rows and columns of the mean and covariance, and conditioning has a closed form that the Kalman update uses.

Bayes' rule

Rearranging the definition of conditional probability gives Bayes' rule, the engine of all probabilistic estimation:

\[p(x \mid z) = \frac{p(z \mid x)\,p(x)}{p(z)} = \eta\,p(z \mid x)\,p(x)\]

Here x is something the robot wants to know, such as its position, and z is a measurement. The prior p(x) is the belief before the measurement. The likelihood p(z | x) is the sensor model: how probable this measurement would be if the state were x. The posterior p(x | z) is the updated belief. The denominator p(z) does not depend on x and is usually written as a normalizer η, computed at the end by making the posterior sum or integrate to 1. The beauty of Bayes' rule is that it inverts the direction of reasoning: sensor manufacturers and engineers can describe p(z | x), how a sensor responds to a known world, and Bayes' rule turns that into p(x | z), what the world is likely to be given the reading.

Worked problem

Bayes rule with a door sensor

A robot is in front of a door with prior probability 0.3. Its door detector reports "door" with probability 0.9 when a door is present and with probability 0.2 when no door is present (a false alarm). The detector reports "door". What is the posterior probability that the robot is at a door?

Show solution
  1. Unnormalized posterior for door: \( 0.9 \times 0.3 = 0.27 \).
  2. Unnormalized posterior for no door: \( 0.2 \times 0.7 = 0.14 \).
  3. Normalizer: \( \eta = 1/(0.27 + 0.14) = 1/0.41 \).
  4. Posterior: \( 0.27/0.41 = 0.659 \).

Answer: The probability of being at a door rises from 0.3 to 0.66. A second independent "door" reading would raise it to \( 0.9 \times 0.659/(0.9 \times 0.659 + 0.2 \times 0.341) = 0.897 \). Each reading multiplies the odds by the likelihood ratio 0.9/0.2 = 4.5.

Sampling a two-dimensional Gaussian and checking its covariance ellipse
import numpy as np
rng = np.random.default_rng(7)
# a 2-D position estimate: sample it and check the sample statistics
mu = np.array([2.0, 1.0])
S = np.array([[0.05, 0.03], [0.03, 0.05]])
X = rng.multivariate_normal(mu, S, size=20000)
print("sample mean:", np.round(X.mean(axis=0), 3))
print("sample covariance:\n", np.round(np.cov(X.T), 4))
# fraction inside the 95 % ellipse (squared Mahalanobis distance < 5.99)
d = X - mu
m2 = np.einsum('ij,jk,ik->i', d, np.linalg.inv(S), d)
print(f"inside 95 % ellipse: {np.mean(m2 < 5.99):.3f}")
lam, V = np.linalg.eigh(S)
print("semi-axes of 95 % ellipse (m):", np.round(np.sqrt(5.99*lam), 3))
Output
sample mean: [2.003 1.002]
sample covariance:
 [[0.05   0.0299]
 [0.0299 0.0494]]
inside 95 % ellipse: 0.950
semi-axes of 95 % ellipse (m): [0.346 0.692]

The sample statistics reproduce the mean and covariance, and almost exactly 95 % of the samples fall inside the ellipse with squared Mahalanobis distance below 5.99, confirming the ellipse semi-axes found by hand. Simulations like this one, with a seeded random number generator so that results are reproducible, are the standard way to check estimation code: if a filter claims a 95 % ellipse, roughly 95 % of the true states in a simulation should lie inside it.

Notation for the rest of the course

The course uses the notation of the probabilistic robotics literature. The state at time t is \( x_t \), the control applied between t − 1 and t is \( u_t \), and the measurement taken at time t is \( z_t \). The sequence of all measurements up to time t is written \( z_{1:t} \). The belief is the posterior over the current state given all data, \( bel(x_t) = p(x_t \mid z_{1:t}, u_{1:t}) \), and the predicted belief before incorporating the latest measurement is \( \overline{bel}(x_t) = p(x_t \mid z_{1:t-1}, u_{1:t}) \). Two models describe the robot and its sensors: the motion model \( p(x_t \mid x_{t-1}, u_t) \), covered in lesson 3, and the measurement model \( p(z_t \mid x_t) \), covered in lesson 4. Every filter in this course is a particular way of representing beliefs and computing them from these two models.

Common mistakes

  • MistakeReporting only per-axis standard deviations

    InsteadReport the full covariance; correlations change how later measurements correct the estimate.

  • MistakeTreating a density value as a probability

    InsteadProbabilities come from integrating a density over a region; density values can exceed 1.

  • MistakeAssuming measurements from the same pose are fully independent

    InsteadAssume conditional independence given the state, and check it, since shared errors break it.

  • MistakeUsing a Gaussian for a belief with two distinct hypotheses

    InsteadUse a histogram, mixture or particle representation for multimodal beliefs.

  • MistakeForgetting to normalize after applying Bayes' rule

    InsteadDivide by the sum or integral so that the posterior is a valid distribution.

Summary and key terms

  • Robots face uncertainty from sensor noise and limits, actuation errors, model approximations and a changing world.
  • A probabilistic estimator tracks a belief, a distribution over the state, rather than a single guess.
  • The mean and covariance summarize a distribution; variance scales with the square of a constant multiplier.
  • Gaussians are fully described by mean and covariance and stay Gaussian under linear maps and Bayesian updates.
  • Covariance ellipses show spread and correlation; their axes come from the eigenvectors and eigenvalues of Σ.
  • Marginalization integrates out variables and conditioning restricts to known values; conditional independence keeps problems tractable.
  • Bayes' rule turns a sensor model p(z | x) and a prior p(x) into a posterior p(x | z).
Belief
The robot's probability distribution over its state given all data so far.
Probability density function
A function whose integral over a region gives the probability of that region.
Covariance matrix
A symmetric matrix of variances and covariances describing the spread of a random vector.
Correlation coefficient
Covariance divided by the product of standard deviations, between −1 and 1.
Mahalanobis distance
Distance from the mean scaled by the covariance, measured in standard deviations.
Marginal distribution
The distribution of some variables after integrating out the others.
Conditional independence
Independence of two variables once a third is known.
Prior
The belief before incorporating a new measurement.
Likelihood
The probability of a measurement given a state, p(z | x).
Posterior
The belief after incorporating a measurement by Bayes' rule.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. A belief puts 0.25 on x = 1 and 0.75 on x = 5. Find the mean.

    Show answer

    \( 0.25 + 3.75 = 4 \).

  2. Find the variance of that belief.

    Show answer

    \( E[X^2] = 0.25 + 18.75 = 19 \); variance \( 19 - 16 = 3 \).

  3. If σ = 2 cm, what range holds about 95 % of a Gaussian estimate?

    Show answer

    The mean ± 4 cm.

  4. X has variance 4. What is the variance of 3X + 1?

    Show answer

    \( 9 \times 4 = 36 \).

  5. Σ has variances 0.04 and 0.09 and covariance 0.03. Find ρ.

    Show answer

    \( 0.03/(0.2 \times 0.3) = 0.5 \).

  6. Which eigenvector of Σ gives the long axis of the ellipse?

    Show answer

    The one with the largest eigenvalue.

  7. What c gives a 95 % ellipse in two dimensions?

    Show answer

    5.99 (chi-square with 2 degrees of freedom).

  8. Prior 0.5, likelihoods 0.8 (true) and 0.1 (false). Find the posterior.

    Show answer

    \( 0.4/(0.4 + 0.05) = 0.889 \).

  9. What does marginalizing a Gaussian over one variable do to Σ?

    Show answer

    It deletes that variable's row and column.

  10. Name the two models every filter in this course needs.

    Show answer

    The motion model and the measurement model.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz