Skip to the lesson
FixTheRobot Explore Robotics / Localization & SLAM / M2 Mathematical Foundations / M2-T4

Localization & SLAM · Theory · M2

M2-T4 — Probability and Uncertainty

A robot’s belief about where it is, with a number that says how much to trust it.

  • Lesson 4 of 7
  • Module 2: Mathematical Foundations
  • Theory
  • About 7 minutes to read

A pose estimate without an uncertainty is a guess with no error bars. SLAM works because it carries a covariance along with every estimate and uses it to decide how much each measurement should count. This lesson builds the vocabulary: random variables, Gaussians, covariance, ellipses and the one formula, Σ′ = JΣJᵀ, that propagates uncertainty through motion.

Learning objectives

After this lesson, you should be able to:

  • Describe a Gaussian by its mean and covariance and read a covariance matrix, including correlation.
  • Draw and interpret an uncertainty ellipse and say what probability it contains.
  • Propagate uncertainty through a function with Σ′ = JΣJᵀ and explain the linearisation assumption.
  • Explain why uncertainty grows when a robot moves and shrinks when it measures.

The intuition

Two surveyors report the same landmark. One says “12.1 m, give or take 1 cm”, the other “12.4 m, give or take 20 cm”. A sensible reader trusts the first. Uncertainty is the “give or take”: it is what lets you combine information, and it must be carried with every estimate or the combination is blind.

A robot treats its pose as a random variable: it has one true value that we do not know, and our knowledge is a probability distribution over it. The workhorse distribution is the Gaussian, the bell curve, because it is described by two things only (a centre and a spread), it stays Gaussian when you add or scale it, and it comes out of the central limit theorem when many small independent errors combine.

A covariance ellipseA tilted ellipse around a mean point. The long axis points at 45 degrees and is longer than the short axis, showing that the x and y errors are positively correlated. Σ = [ 0.04 0.03 ] [ 0.03 0.04 ] eigenvalues 0.07 and 0.01 semi-axes at 2σ: 0.53 m and 0.20 m long axis along 45°: x and y errors move together Probability inside the 2σ ellipse: about 86%
A 2D Gaussian drawn as the ellipse where its density has fallen to a fixed level. Positive correlation tilts the ellipse along the diagonal.

The mathematics

A Gaussian in n dimensions with mean μ and covariance Σ has density

Multivariate Gaussian
p(x)=exp⁡(−12(x−μ)⊤ Σ−1(x−μ))(2π)n det⁡ Σp(x)=\frac{\exp (-\tfrac{1}{2}(x-\mu )^{\top}\,\Sigma ^{-1}(x-\mu ))}{\sqrt{(2\pi )^{n}\,\det \,\Sigma }}
μ
the mean: the single best estimate, the centre of the bell.
Σ
the covariance matrix (n×n, symmetric, positive semi-definite). Diagonal entries are variances σ² (in squared units); off-diagonal entries say how two quantities vary together.
σ
the standard deviation, sqrt of a variance, in the same units as the quantity. About 68% of a 1D Gaussian lies within ±1σ and 95% within ±2σ.
ρ
the correlation, Σxy / (σx σy), between −1 and 1.

Reading an ellipse

The contour where the exponent equals −k²/2 is an ellipse whose axes follow the eigenvectors of Σ, with semi-axis lengths k·sqrt(λ), λ being the eigenvalues. The squared Mahalanobis distance d² = (x − μ)ᵀΣ⁻¹(x − μ) is chi-square distributed with n degrees of freedom. In 2D, the probability inside the 1σ ellipse (k = 1) is only about 39%, inside k = 2 about 86%, inside k = 3 about 99%. These are not the 68/95/99.7 of one dimension, a very common mistake.

Propagation through a function

If y = f(x) and x has covariance Σ, a first-order Taylor expansion gives

Linear error propagation
∑y≈J ∑x J⊤\sum _{y}\approx J\,\sum _{x}\,J^{\top}
J=∂f∂x evaluated at the meanJ=\frac{\partial f}{\partial x\,\text{evaluated at the mean}}

J is the Jacobian, the matrix of partial derivatives. If f also depends on a noisy input u with covariance Q, add G Q Gᵀ with G = ∂f/∂u. This is the single most used formula in the filters of Module 3. It is exact for linear f and a good approximation when the uncertainty is small compared with how curved f is.

Motion adds uncertainty (Σ grows through J Σ Jᵀ + G Q Gᵀ). A measurement removes it. SLAM is the balance between the two.

A worked example: one odometry step

A robot at pose (x, y, θ) = (0, 0, 0) has covariance Σ = diag(1e-4, 1e-4, 4e-4): σx = σy = 1 cm and σθ = 0.02 rad (1.15°). It drives d = 1 m forward. The pose update is f: x′ = x + d cos θ, y′ = y + d sin θ, θ′ = θ.

  1. Jacobian. ∂f/∂(x, y, θ) = [[1, 0, −d sin θ], [0, 1, d cos θ], [0, 0, 1]]. At θ = 0 and d = 1 this is [[1, 0, 0], [0, 1, 1], [0, 0, 1]].
  2. Propagate. Σ′ = J Σ Jᵀ. The x variance stays 1e-4. The y variance becomes 1e-4 + 1² · 4e-4 = 5e-4, so σy = 2.24 cm: more than double. The y and θ entries become correlated: Σ′yθ = 1 · 4e-4 = 4e-4.
  3. Interpret. A heading uncertainty of 0.02 rad turns into a sideways uncertainty of 0.02 m over one metre. After 10 m the same heading error gives σy ≈ 20 cm: the effect scales with distance, as in the lesson on why SLAM is hard. The correlation means that if you later learn the heading, you also learn something about y.
  4. An ellipse. For Σ = [[0.04, 0.03], [0.03, 0.04]] the eigenvalues are 0.07 (along 45°) and 0.01 (along 135°). With k = 2 the semi-axes are 2·sqrt(0.07) = 0.53 m and 2·sqrt(0.01) = 0.20 m. About 86% of the probability is inside.
  5. A measurement. A sensor that gives y to ±1 cm would shrink σy from 2.2 cm to about 0.9 cm, and, through the correlation, would also shrink σθ. That update is the subject of the Kalman filter.

The lab for this module asks you to propagate a pose covariance exactly like this, step after step, and to check it against a cloud of simulated robots.

Engineering implications and limitations

Practical lessons

  • Report units and frame. A covariance of position in the map frame is not a covariance in the robot frame; rotating the frame rotates the ellipse: Σ′ = R Σ Rᵀ.
  • Keep Σ symmetric and positive semi-definite. Round-off breaks both. Symmetrise (Σ ← (Σ + Σᵀ)/2) and check the smallest eigenvalue after long runs.
  • Do not confuse correlation with sloppiness. Off-diagonal terms carry information that makes the filter work. Throwing them away (a diagonal covariance) makes the filter overconfident.
  • Be consistent. A filter is consistent if the squared error normalised by Σ averages to the dimension (the NEES test). Overconfidence, where errors are bigger than Σ admits, is the usual cause of diverging SLAM.
  • Orientation uncertainty is not a plain covariance of angles in 3D: it is a small rotation vector in the tangent space (Module 4).

Limits

The Gaussian cannot represent two separate hypotheses (“I am in corridor A or corridor B”), a heavy tail, or a banana-shaped uncertainty that develops when a large heading error curves the position distribution. The linearisation behind Σ′ = JΣJᵀ fails when uncertainty is large against the curvature of f. Particle filters (Module 3) trade the Gaussian for a set of samples to handle exactly these cases.

Common misconceptions

“The 1σ ellipse contains 68% of the probability.”

That is the 1D figure. In 2D the 1σ ellipse contains about 39%; the 2σ ellipse about 86%.

“A bigger covariance means a worse estimate.”

A bigger covariance means more uncertainty, which may be honest. A small, wrong covariance is the dangerous case.

“Variance of a sum is the sum of variances.”

Only for uncorrelated quantities. In general var(a + b) = var a + var b + 2 cov(a, b).

“The covariance changes only when a measurement arrives.”

It grows with every motion step and shrinks at every measurement.

Engineering takeaways

  1. A Gaussian is fixed by its mean and covariance; the covariance diagonal gives variances and the off-diagonals give correlation.
  2. Uncertainty ellipses follow the eigenvectors of Σ; in 2D the 1σ and 2σ ellipses hold about 39% and 86% of the probability.
  3. Uncertainty propagates through a function by Σ′ = J Σ Jᵀ (plus noise terms): a first-order approximation.
  4. Motion grows uncertainty and measurement shrinks it; heading uncertainty grows into position uncertainty with distance.
  5. Keep covariances symmetric, positive semi-definite and honest: overconfidence breaks filters.

References and further reading

Primary papers and authoritative documentation.

Knowledge check

Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.

Question 1

A robot reports σx = 5 cm and σy = 5 cm with a correlation of 0.9. Is the uncertainty circular?

Explanation

No. A strong positive correlation makes the ellipse long along the diagonal and thin across it, even though the two variances are equal. The off-diagonal term carries the shape.

Question 2

After driving 10 m straight with a heading uncertainty of 0.02 rad that does not improve, what is the approximate sideways uncertainty from the heading alone?

Explanation

About 10 m × 0.02 rad = 0.2 m. Heading uncertainty is multiplied by distance, which is why it dominates position uncertainty on long runs.

Question 3

A teammate drops all off-diagonal terms from the pose covariance “to keep it simple”. What is the likely consequence for the filter?

Explanation

The filter becomes overconfident. The off-diagonal terms record how errors depend on each other, so dropping them makes later measurements appear to give more information than they do, and the estimate can diverge from the truth while claiming to be certain.

What’s next

A covariance is half of a belief. The next lesson shows how to update a belief when a measurement arrives: Bayes’ rule applied over and over.

Practice this lesson

Understand Pose Uncertainty

Propagate a pose covariance through odometry steps and a landmark update, and compare your ellipses with a Monte Carlo cloud.

Next lesson

M2-T5 — Bayesian Estimation

Derive the recursive Bayes filter: predict with the motion model, correct with the observation.

Nothing below is required to finish this lesson. The last 3 entries are lessons of other courses on this site that teach the background or go further.