Linear Algebra · Theory · M9
M9-T3 — Multivariate Gaussian Distributions
The Gaussian is the workhorse of robot estimation because it is closed under everything we do to it: linear maps, sums, marginals and conditionals stay Gaussian.
A mean vector and a covariance matrix completely specify a Gaussian. This lesson writes the density, explains where each piece comes from, and derives the conditional formula that is the heart of the Kalman filter: observing one part of the state updates the rest through the covariance.
Learning objectives
After this lesson, you should be able to:
- Write the multivariate Gaussian density and identify the roles of μ, Σ, the normalising constant and the quadratic form.
- Interpret level sets as ellipses and compute the probability mass inside a k-sigma ellipse.
- State and use the marginal and conditional distributions of a partitioned Gaussian.
- Sample from a Gaussian with the Cholesky factor of Σ.
Introduction and motivation
Almost every probabilistic robotics algorithm (EKF, UKF, pose-graph SLAM, Gaussian processes) represents beliefs as Gaussians. The reason is practical: operations the robot needs, such as predicting through a linear model, combining with a measurement, ignoring variables it does not care about, and conditioning on what it has observed, all keep the Gaussian form, so a belief is just a vector and a matrix. The conditional formula in particular is the Kalman update in disguise.
The intuition
A Gaussian cloud is the unit round cloud pushed through a linear map: stretched along the principal axes by the square roots of the eigenvalues, rotated, and shifted to the mean. Its density falls off with distance from the centre measured in units of the cloud itself (Mahalanobis distance), so points on the same ellipse have equal density. Looking at just some coordinates gives a Gaussian; fixing some coordinates and looking at the rest also gives a Gaussian.
Interactive figure. A Gaussian cloud with its one, two and three standard-deviation ellipses and a draggable test point. The readout gives the covariance, the eigenvalues, the Mahalanobis distance of the point and whether it lies inside the 95 percent ellipse. This figure needs JavaScript to be interactive.
Geometric and physical interpretation
Geometric view. The density is a bell-shaped hill over the plane whose horizontal slices are the ellipses (x − μ)ᵀΣ⁻¹(x − μ) = c; the peak sits above μ. The hill is wide where Σ has large eigenvalues and narrow where it has small ones, and its total volume is 1. Physical view. A robot belief with a long thin ellipse is sure of its position across the corridor and unsure along it, and the density reflects exactly that: probability concentrated in a thin strip.
The mathematics
- N(μ, Σ)
- the Gaussian with mean μ and covariance Σ (positive definite).
- n
- the dimension of x.
- d² = (x − μ)ᵀΣ⁻¹(x − μ)
- the squared Mahalanobis distance.
- x = (x₁; x₂)
- a partition of the vector, with μ = (μ₁; μ₂) and Σ = [[Σ₁₁, Σ₁₂], [Σ₂₁, Σ₂₂]].
The density
p(x) = (2π)^(−n/2) · det(Σ)^(−1/2) · exp( −½ (x − μ)ᵀ Σ⁻¹ (x − μ) )
What it means. The exponent is −½ times the squared Mahalanobis distance; the prefactor makes the total probability 1. The determinant is the volume scale of the ellipse: wider clouds have lower peaks.
Probability inside an ellipse
P( d² ≤ k² ) = 1 − e^(−k²/2) (n = 2), d² ~ χ²ₙ in general
What it means. The squared Mahalanobis distance of a Gaussian vector follows a chi-square distribution with n degrees of freedom. In 2D the 1σ, 2σ and 3σ ellipses contain 39 %, 86 % and 99 % of the probability, not 68, 95, 99.7 as in 1D.
Marginal and conditional
x₁ ~ N(μ₁, Σ₁₁) x₁ | x₂ ~ N( μ₁ + Σ₁₂Σ₂₂⁻¹ (x₂ − μ₂), Σ₁₁ − Σ₁₂Σ₂₂⁻¹Σ₂₁ )
What it means. The marginal is the sub-block. The conditional mean moves toward the observed x₂ in proportion to the correlation (the gain Σ₁₂Σ₂₂⁻¹), and the conditional covariance is always smaller than Σ₁₁ (a Schur complement).
Gaussian = exp(−½ Mahalanobis²) normalised. Level sets are ellipses. Marginals take sub-blocks; conditionals shift the mean by Σ₁₂Σ₂₂⁻¹(x₂ − μ₂) and subtract Σ₁₂Σ₂₂⁻¹Σ₂₁ from the covariance.
Step-by-step derivation: normalisation, probability in an ellipse and the conditional
- Standard case. For
μ = 0, Σ = Ithe density is(2π)^(−n/2) exp(−½‖x‖²), a product of n one-dimensional bells, each integrating to 1. - General case by a linear map. Let
x = μ + Lzwithz ~ N(0, I)andΣ = LLᵀ(Cholesky). The change of variables multiplies densities by1/|det L| = det(Σ)^(−1/2)and replaces‖z‖² = ‖L⁻¹(x − μ)‖²by(x − μ)ᵀΣ⁻¹(x − μ), giving the density above and explaining the normalisation factor. - Level sets. The density depends on x only through
d², so its level sets are the ellipsesd² = c, with axes along the eigenvectors of Σ (spectral theorem). - Probability in an ellipse.
d² = ‖z‖²is the sum of squares of n independent standard normals: chi-square with n degrees of freedom. For n = 2 its density is½e^(−s/2), soP(d² ≤ k²) = 1 − e^(−k²/2). For 95 %,k² = −2 ln 0.05 = 5.99,k = 2.448. - Marginal. Integrating out x₂ leaves x₁; because
x₁ = [I 0] xis a linear map of a Gaussian, it is Gaussian with meanμ₁and covariance[I 0]Σ[I 0]ᵀ = Σ₁₁. - Conditional. Write
x₁ = μ₁ + Σ₁₂Σ₂₂⁻¹(x₂ − μ₂) + r, wherer = x₁ − μ₁ − Σ₁₂Σ₂₂⁻¹(x₂ − μ₂)is the leftover part. ThenCov(r, x₂) = Σ₁₂ − Σ₁₂Σ₂₂⁻¹Σ₂₂ = 0: r is uncorrelated, hence (being jointly Gaussian) independent of x₂. So given x₂, x₁ is that shifted constant plus r, withCov(r) = Σ₁₁ − 2Σ₁₂Σ₂₂⁻¹Σ₂₁ + Σ₁₂Σ₂₂⁻¹Σ₂₂Σ₂₂⁻¹Σ₂₁ = Σ₁₁ − Σ₁₂Σ₂₂⁻¹Σ₂₁. - Link to Kalman. If x₂ is a measurement of x₁ (plus noise), the conditional mean formula is the Kalman update with gain
K = Σ₁₂Σ₂₂⁻¹and the conditional covariance is the posterior covarianceP − KSKᵀ(the last lesson of this module). - Sampling. Draw
z ~ N(0, I)and formx = μ + LzwithL = chol(Σ): the sample has covarianceLLᵀ = Σ.
Why Gaussians are everywhere. They are closed under linear maps (Ax ~ N(Aμ, AΣAᵀ), next lesson), sums of independent Gaussians, marginalisation and conditioning. The central limit theorem makes sums of many small independent errors approximately Gaussian, which is why sensor noise often is.
Not Gaussian. Outliers, multi-modal beliefs (symmetric corridors) and angles on a circle are not well modelled by a single Gaussian; robust losses, mixtures and particle filters take over.
A worked example: density, ellipse probabilities and a conditional
Let μ = (0, 0), Σ = [[4, 2], [2, 3]].
- Determinant and peak.
det Σ = 12 − 4 = 8. Peak density1/(2π√8) = 0.0563. - Density elsewhere.
Σ⁻¹ = (1/8)[[3, −2], [−2, 4]]. Atx = (2, 0):d² = 2·3·2/8 = 1.5, sop = 0.0563 exp(−0.75) = 0.0266. - Probabilities. Inside the 1σ, 2σ and 3σ ellipses:
1 − e^(−1/2) = 39.3 %,1 − e^(−2) = 86.5 %,1 − e^(−4.5) = 98.9 %. The 95 % ellipse hask = 2.448. - Marginal.
x₁ ~ N(0, 4),x₂ ~ N(0, 3): read the diagonal. - Conditional. Observe
x₂ = 3. The conditional mean of x₁ isΣ₁₂Σ₂₂⁻¹ x₂ = (2/3)·3 = 2; the variance drops from 4 to4 − 2·(1/3)·2 = 4 − 4/3 = 2.667. - Sampling.
L = chol Σ = [[2, 0], [1, 1.414]]andz = (1, 1)givesx = (2, 2.414);LLᵀ = [[4, 2], [2, 3]]✓.
Robotics application
SLAM and localisation. The belief of an EKF is exactly N(μ, Σ); conditioning on a LiDAR range changes the pose and every correlated landmark; see Bayesian estimation, probability and uncertainty and EKF-SLAM.
UAV state estimation. Navigation filters carry Gaussian beliefs over position, velocity, attitude error and biases; innovation gating uses the chi-square test above; see Gaussian distributions and covariance, Bayesian estimation and the error-state Kalman filter.
LiDAR registration. Normal-distributions transform (NDT) models each map cell as a Gaussian and scores points by the density; the score is a sum of exp(−d²/2) terms; see scan registration.
Mobile robots and manipulators. Sampling-based motion models (sampling a Gaussian over wheel odometry noise via the Cholesky factor) and sensor simulation both use x = μ + Lz; see robot motion models for navigation.
Engineering implications and limitations
Practical rules
- Work with log-density. The density underflows quickly in high dimensions. Use
−½(d² + ln det Σ + n ln 2π)and obtainln det Σas2 Σ ln Lᵢᵢfrom the Cholesky factor. - Never invert Σ explicitly. Solve with the Cholesky factor:
d² = ‖L⁻¹(x − μ)‖²by one triangular solve. - Use the right gate. A 2D 95 % gate is d² ≤ 5.99, not 4 (which is 2σ in 1D and only 86 % in 2D). Use chi-square quantiles for the dimension at hand.
- Check that Σ is positive definite before using it. A singular Σ has no density (use the information form or the pseudo-determinant).
- Sample via Cholesky, not by independent components. Sampling x and y separately ignores correlation.
- Respect the units in conditionals. Σ₁₂Σ₂₂⁻¹ converts units of x₂ into units of x₁; mixed units are fine, but the numbers must be consistent.
Limits
One Gaussian cannot represent two separate hypotheses or heavy tails. Nonlinear transformations of a Gaussian are not Gaussian (the next lesson shows the banana), so linearisation or sigma points are approximations.
Common misconceptions
“2σ always contains 95 %.”
Only in 1D. In 2D the 2σ ellipse contains 86.5 %; the 95 % ellipse is at k = 2.45.
“The peak density of a Gaussian is 1/√(2π).”
Only for unit variance in 1D. In general it is (2π)^(−n/2) det(Σ)^(−1/2): wider clouds have lower peaks.
“Conditioning on a measurement can only change the mean.”
It also reduces the covariance: Σ₁₁ − Σ₁₂Σ₂₂⁻¹Σ₂₁ ≤ Σ₁₁. Information never increases uncertainty.
“The marginals determine the joint Gaussian.”
They do not: the correlation is lost. Different joint covariances share the same marginals.
Engineering takeaways
- N(μ, Σ) has density (2π)^(−n/2) det(Σ)^(−1/2) exp(−½ d²), with d² the squared Mahalanobis distance.
- Level sets are ellipses with axes along the eigenvectors of Σ; in 2D, P(d² ≤ k²) = 1 − e^(−k²/2) (39 %, 86 %, 99 % for 1, 2, 3σ; 95 % at k = 2.45).
- Marginals read sub-blocks; the conditional x₁|x₂ has mean μ₁ + Σ₁₂Σ₂₂⁻¹(x₂ − μ₂) and covariance Σ₁₁ − Σ₁₂Σ₂₂⁻¹Σ₂₁.
- Sample with x = μ + Lz where Σ = LLᵀ; compute d² with a triangular solve.
- Gaussians are closed under linear maps, marginalisation and conditioning, which is why filters use them.
References and further reading
Primary papers and authoritative documentation.
- Barfoot, State Estimation for Robotics (author-hosted first edition, free to read): chapter 2.2, Gaussian probability density functions
- Mathematics for Machine Learning: chapter 6.5, Gaussian distribution and its marginals and conditionals
- UCSD ECE276A: Sensing and Estimation in Robotics: Gaussian models, conditioning and the Kalman filter
- Boyd and Vandenberghe, Introduction to Applied Linear Algebra (VMLS): statistics background and least squares; the site did not load when we last checked
Knowledge check
Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.
Question 1
For Σ = diag(1, 4) and μ = 0 compute the peak density and the density at (1, 2).
Explanation
det Σ = 4, peak = 1/(2π·2) = 0.0796. At (1, 2): d² = 1/1 + 4/4 = 2, so p = 0.0796·exp(−1) = 0.0293.
Question 2
With Σ = [[2, 1], [1, 1]], μ = 0, observe x₂ = 2. Find the conditional distribution of x₁.
Explanation
Σ₁₂Σ₂₂⁻¹ = 1/1 = 1, so the mean is 1·2 = 2. Variance Σ₁₁ − Σ₁₂Σ₂₂⁻¹Σ₂₁ = 2 − 1 = 1. So x₁ | x₂ = 2 ~ N(2, 1): the variance halved from 2 to 1.
Question 3
A 3D measurement residual has d² = 9.1. Is it inside the 95 % gate? (The chi-square 95 % value for 3 degrees of freedom is 7.81.)
Explanation
No: 9.1 > 7.81, so the residual is outside the 95 % ellipsoid and the measurement should be treated as an outlier (or the filter as over-confident) at that confidence level.
What’s next
Gaussians survive linear maps: if x ~ N(μ, Σ) and y = Ax then y ~ N(Aμ, AΣAᵀ). The next lesson makes that rule explicit, extends it to nonlinear functions through the Jacobian, and shows where the approximation breaks.
Related content
Nothing below is required to finish this lesson.
- BeforeM9-T2: Covariance Matrices
Compute and read a covariance matrix, including correlation and the ellipse it describes.
Get notified when the next lesson and new labs are released.
One email per new lesson or lab.