Chapter 7: The multivariate Gaussian

Previous: PS 06 Joint Distributions and Covariance | PS 00 Course Map | Next: PS 08 Law of Large Numbers and Central Limit Theorem

The big idea

The multivariate Gaussian is a bell-shaped cloud in many dimensions, completely described by a mean vector (where the cloud is) and a covariance matrix (its size, shape and tilt). Its contours are ellipses whose axes are the covariance’s eigenvectors. Its great practical virtue is that it stays Gaussian when you transform it linearly, look at part of it, or condition on part of it, and each of those operations has a simple closed formula. That is why it is the default model of uncertainty in robotics.

In this chapter you will learn to
  1. Read the multivariate Gaussian density and relate each part to the 1-D case.
  2. Use Mahalanobis distance to measure how surprising a point is.
  3. Draw the uncertainty ellipse from a covariance matrix.
  4. Compute linear transformations, marginals and conditionals of Gaussians.
  5. Sample from a Gaussian, and explain the reparameterization trick.
  6. Recognize when a Gaussian is the wrong model.
Before you start

You need the 1-D normal (PS 05 Continuous Random Variables), covariance matrices and (PS 06 Joint Distributions and Covariance), and the spectral theorem and positive definite matrices (LA 09 Symmetric and Positive Definite Matrices).


7.1 The density

Definition: multivariate Gaussian

A random vector has distribution if its density is

where is the mean and is a symmetric positive definite covariance matrix.

Compare with one dimension

The 1-D density is . Every piece has a matrix counterpart:

1-D-DRole
mean mean vector centre of the cloud
variance covariance matrix spread, shape and orientation
squared distance in standard deviations
size (volume) of the cloud

The structure is identical: a normalizing constant, then to the power of minus half a squared, standardized distance.

A special case: independent coordinates

If is diagonal, , then is diagonal too, and the exponent splits into a sum:

The density becomes a product of 1-D normal densities: the coordinates are independent. A diagonal covariance means independent components.


7.2 Mahalanobis distance

The quantity in the exponent has a name:

Definition: Mahalanobis distance

It is the distance from to the mean, measured in standard deviations along each direction of the cloud.

Why ordinary distance is not enough

Suppose a cloud is long and thin: wide in the -direction, narrow in . A point 3 units to the right of the centre is ordinary (the cloud extends that far). A point 3 units above the centre is extremely unusual (the cloud is thin in that direction). Both have Euclidean distance 3. The Mahalanobis distance tells them apart.

Worked example 7.1. , (standard deviation 3 in , 1 in ).

  • Point : . One standard deviation: ordinary.
  • Point : , so . Three standard deviations: rare.

Use: outlier rejection

A robot predicts where a landmark should appear, with some uncertainty . A measurement arrives. If its Mahalanobis distance from the prediction is too large (say, beyond 3), it is probably a false detection and is discarded. This is called gating, and it is standard in tracking and localization.


7.3 The geometry: uncertainty ellipses

Contours are ellipses

Points of equal density are points of equal Mahalanobis distance:

From LA 09 Symmetric and Positive Definite Matrices (section 9.5), these are ellipses in 2-D and ellipsoids in higher dimensions. Use the spectral decomposition :

Reading the ellipse
  • The axes of the ellipse point along the eigenvectors of .
  • The half-length of the 1-sigma ellipse along eigenvector is : the standard deviation in that direction.
  • The -sigma ellipse is times larger.

Worked example 7.2

Eigenvalues 3 and 1, with eigenvectors and .

  • Along the diagonal : standard deviation . The long axis.
  • Along the anti-diagonal : standard deviation . The short axis.

The cloud is tilted upward at . The correlation is , positive, matching the upward tilt.

Reading a covariance at a glance

Shape of the cloud
circle
diagonal, unequal entriesellipse aligned with the axes
positive off-diagonalellipse tilted upward (positive correlation)
negative off-diagonalellipse tilted downward (negative correlation)
nearly singularvery thin ellipse: the variables almost determine each other
How much probability is inside?

In 1-D, holds 68%. In 2-D, the 1-sigma ellipse holds only about 39%, and the 2-sigma ellipse about 86%. To contain 95% in 2-D you need about 2.45 sigma. In higher dimensions the numbers drop further. Do not reuse the 1-D rule for ellipses.


7.4 Property 1: linear transformations

Linear maps keep Gaussians Gaussian

If and , then

The mean and covariance formulas hold for any distribution (chapter 6). What is special is that is still Gaussian, so these two quantities describe it completely.

Worked example 7.3. in 2-D, with :

A round cloud becomes a tilted ellipse.

Worked example 7.4: sum of independent Gaussians. , independent. Then .


7.5 Property 2: marginals

Marginals of a Gaussian are Gaussian

To get the distribution of some of the coordinates, simply pick out the matching entries of and the matching block of . No integration needed.

Worked example 7.5.

  • .
  • .

(This is property 1 with a matrix that selects coordinates.)


7.6 Property 3: conditioning

The formulas

Split into two parts, (what you want to know) and (what you observe):

Conditioning a Gaussian

Given the observation , the distribution of is Gaussian with

Read the formulas slowly

These two lines are the Kalman filter in miniature, so they are worth understanding word by word.

The mean.

  • is the surprise: how far the observation is from what was expected.
  • is a gain: how much to move the estimate of per unit of surprise.
    • Large when and are strongly correlated ( large): the observation is informative.
    • Small when the observation itself is very noisy ( large): don’t trust it much.
  • The new mean is the old mean plus gain times surprise.

The covariance.

  • It shrinks: something is subtracted from . Observing a correlated quantity always reduces uncertainty.
  • It does not depend on the value of . How much you learn depends on how informative the sensor is, not on what it happened to read.

Worked example 7.6: two dimensions

with mean zero and . You observe .

Before: had mean 0, variance 2. After: mean 1, variance 1.5. The estimate moved halfway toward the observation (gain ) and the uncertainty dropped by a quarter.

Worked example 7.7: strong correlation

Same, but and :

High correlation means the observation pins down tightly.

Uncorrelated means independent (for Gaussians)

If , the gain is zero: observing tells you nothing about . So for jointly Gaussian variables, uncorrelated implies independent. This is special to the Gaussian. In general it is false (PS 06 Joint Distributions and Covariance, warning 1).


7.7 Sampling and the reparameterization trick

How to draw samples

To draw :

  1. Factor (Cholesky, LA 09 Symmetric and Positive Definite Matrices).
  2. Draw with independent standard normal entries: .
  3. Set .

Check with property 1: the mean is and the covariance is ✓.

The reparameterization trick

In machine learning we often want to differentiate through sampling: for example, adjust and to make sampled actions better. A random draw seems not to have a derivative.

The trick: write the sample as

where the randomness comes from a fixed source that does not depend on the parameters. Now is an ordinary differentiable function of and , and gradients flow through it: , .

Variational autoencoders and soft actor-critic (SAC) policies rely on this (Appendix - PPO SAC and Offline Learning).


7.8 The log-density and squared error

With , the first term is . So:

Gaussian likelihood = squared error

Maximizing a Gaussian log-likelihood with fixed variance is the same as minimizing squared error. That is where the mean squared error loss comes from (PS 09 Estimation and Maximum Likelihood).


7.9 What a Gaussian cannot do

One peak only

The mode-averaging problem

A robot must pass an obstacle. Half the demonstrations go left, half go right. Fit a single Gaussian to the steering commands: its mean is the average, straight ahead, straight into the obstacle. Its variance is large, but no sample from it reliably represents either good choice.

A Gaussian has one peak. When the data has several distinct good answers (multimodal data), a single Gaussian blends them into a bad one.

This is the core motivation for mixture models, diffusion policies and action chunking in robot learning (08 Diffusion and Flow Matching, 07 ACT and Action Sequences).

Other limits

  • Thin tails: outliers are far rarer under a Gaussian than in real data.
  • Symmetric: it cannot represent skewed quantities such as positive-only times.
  • Linear relationships only: conditioning formulas assume the dependence between variables is linear.

Summary

IdeaFormula or fact
density
Mahalanobis distance
ellipse axeseigenvectors of ; half-lengths
linear map
marginalpick out the block
conditional mean
conditional covariance
sampling,

Three facts to remember:

  1. Mean = where; covariance = shape and tilt; its eigenvectors are the ellipse axes.
  2. Conditioning moves the mean by gain × surprise and always shrinks the covariance.
  3. A Gaussian has one peak: it averages away multiple good answers.

Exercises

Part A: warm-up

A1. For , describe the 1-sigma ellipse.

A2. and . Find the mean and covariance of .

A3. From and , give the distribution of , and of . Is independent of ?

A4. Compute the Mahalanobis distance of from when .

Part B: core

B1. With zero means and , you observe . Find the conditional mean and variance of . Repeat for . What changes and what does not?

B2. For the same , compute the Mahalanobis distances of and . Both are at Euclidean distance . Explain the difference using the ellipse.

B3. A robot’s position estimate is m². A sensor measures for the -coordinate only, with noise variance , and reads . Model as jointly Gaussian and find the updated mean and variance of . (Hint: , .)

B4. Find a matrix so that with has covariance .

B5. Demonstrations steer either (left) or (right) with equal probability, with small noise. A single Gaussian is fitted. What are its mean and (approximately) standard deviation? What fraction of its samples fall between and , where the obstacle is?

Part C: explain and prove

C1. Show that if is diagonal, the multivariate Gaussian density is a product of 1-D normal densities.

C2. Explain why the conditional covariance can never be larger than (in 1-D: never larger as a number).

C3. Explain the reparameterization trick in your own words, and why it is needed to train a policy that outputs a mean and standard deviation.

Part D: practise with code

D1. Draw 2,000 samples from and plot them. Overlay the 1- and 2-sigma ellipses using the eigenvectors and eigenvalues. Count the fraction inside each (compare with 39% and 86%).

D2. Implement condition_gaussian(mu, Sigma, idx_obs, x_obs) returning the conditional mean and covariance. Test it on worked example 7.6.

D3. Generate the bimodal steering data of B5 (half from , half from ), fit a single Gaussian (sample mean and standard deviation), and plot the data histogram with the fitted density.


Where this is used

Next: PS 08 Law of Large Numbers and Central Limit Theorem: why averages settle down, and how fast.