Multivariate Gaussian Distribution
The bell curve in many dimensions at once: a center plus a covariance matrix that stretches the contours into tilted ellipses and sets the ruler for distance.
Why Does This Exist?
Data rarely arrives one number at a time. A sensor reports position and velocity together, a model embeds a word as hundreds of coordinates, a filter tracks a whole state vector. The general joint law of a vector is taught in multivariate distributions: one rule weighing every combination, organized by a mean vector and a covariance matrix. That page is the family; this page is its most-used member.
The Gaussian earns its own page because it is the only joint law fully described by those two summaries. Give it a mean vector and a covariance matrix and every marginal, every conditional, and every contour is fixed, with closed forms throughout. That is why Kalman filters track Gaussians, why variational methods fit Gaussians first, and why central limit theorem averages converge to one.
The one idea you need first
A random vector stacks several random variables into , and its joint law answers combination questions. The mean vector collects the centers , and the covariance matrix collects the pairwise leans , built from the averaging in expectation, variance and covariance. The Gaussian is the special case where these two objects are the entire distribution.
Think of It Like This
An archery target printed on stretched rubber
Take a round archery target: concentric circles around a bullseye, with rings marking one, two and three standard deviations. Now stretch the rubber sheet wider in one direction than the other, then twist it 45 degrees and pin it down. The circles become tilted ellipses, but the bullseye stays the bullseye and the rings still mark the same probabilities.
The bullseye is the mean vector : where the cloud centers. The stretch plus twist is the covariance matrix : variances set how far each axis stretches, covariance sets the twist. A point on the first ellipse is one Mahalanobis unit out no matter which direction it lies in, exactly as every point on the original first circle was one standard deviation out.
The analogy stops where shape stops. Rubber stretches a circle into exactly one ellipse family, and the Gaussian likewise produces only ellipses. Real data forms bananas, rings and separate clusters that no amount of stretching a circle will match. When the contours need more than one center, reach for a mixture, not a bigger ellipse.
How It Actually Works
Write the density for with mean vector and covariance matrix :
In plain words: is the center of the cloud, is its shape and tilt, sets the normalizing volume, and the exponent measures squared distance in the curved ruler defines. Every symbol is used below, none is decorative.
Three readings of that practitioners actually use:
- Variances on the diagonal set the spread along each axis. Standard deviations are their square roots.
- Covariances off the diagonal set the tilt. Divided by both standard deviations they become correlations in , which speak strength instead of units.
- Eigen-structure sets the ellipse axes. The eigenvectors of point along the ellipse axes and the square roots of the eigenvalues are the half-lengths of the 1-sigma contour.
The exponent has its own name because it is used constantly. The Mahalanobis distance is : Euclidean distance after whitening by . Contours of equal density are contours of equal Mahalanobis distance, which is why the diagram draws ellipses and labels one of them .
Worked example
Take with and .
Variances are and , so each standard deviation is . Covariance divided by gives correlation : a clear rising tilt. Determinant , so and the inverse is . Eigenvalues are and since the trace is and , so the 1-sigma ellipse has half-lengths along and along : a 45-degree tilt, exactly as drawn.
Test the point with displacement :
so : the point sits exactly on the 1-sigma contour, which is why the diagram places it at the tip of the major axis. Its density is .
Marginals and conditionals fall out without integration. Each marginal is Gaussian: and . Given , the conditional is , since the conditional mean is and the conditional variance is . Conditioning shrinks the variance from to because part of is explained by .
Code
The snippet evaluates the worked fixture directly: squared Mahalanobis distance and density at , with no library beyond NumPy.
import numpy as np
mu = np.array([0.0, 0.0])Sigma = np.array([[5.0, 3.0], [3.0, 5.0]])x = np.array([2.0, 2.0])
dx = x - muinv = np.linalg.inv(Sigma)m2 = float(dx @ inv @ dx)dens = float(np.exp(-0.5 * m2) / (2 * np.pi * np.sqrt(np.linalg.det(Sigma))))
print(round(m2, 4)) # -> 1.0print(round(dens, 4)) # -> 0.0241One and , matching the hand calculation. The dx @ inv @ dx line is the Mahalanobis form; everything else is the normalizer.
Watch Out For
Fitting one Gaussian to data with two centers
A single Gaussian has one , so on bimodal data the fitted mean lands between the clusters where no data lives. The classic case is two well-separated blobs: the maximum-likelihood center sits in the empty middle, the covariance inflates to cover both, and the density peaks exactly where the data is absent. Samples from the fit then look nothing like the training set, and downstream thresholds built from the contours misfire.
The symptom is a mean with low data density around it and residuals that cluster rather than scatter. The fix is a mixture with one component per center, or a check before fitting: if a histogram or a 2-D scatter shows two humps, do not fit one bell. The diagram's limit line states the same boundary: one Gaussian cannot fit separate clusters.
Inverting a singular or near-singular covariance
When two features are nearly perfectly correlated, rows of nearly repeat and approaches zero. The inverse then explodes: tiny measurement noise in multiplies into enormous Mahalanobis distances, densities swing wildly, and np.linalg.inv may warn or return garbage. Duplicated columns, one-hot groups with a dropped-category bug, or more dimensions than samples all create this.
The symptom is a determinant near zero, a condition number in the millions, or Mahalanobis distances that change drastically when one sample is removed. The fixes in order: remove the duplicated feature, add a small jitter to the diagonal (), or work with the pseudo-inverse and a rank check. Never trust a density whose normalizer divides by a near-zero determinant.
The Quick Version
- The multivariate Gaussian is the joint law fully described by a mean vector and a covariance matrix .
- Diagonal entries of set axis spreads; off-diagonals set tilt; correlation rescales tilt into .
- Contours of equal density are ellipses of equal Mahalanobis distance .
- With , correlation is , the determinant is , and sits exactly at with density about .
- Marginals and conditionals of a Gaussian are Gaussian, with conditioning shrinking variance, here from to .
- One Gaussian cannot fit separate clusters, and a near-singular breaks the inverse, so check modality and the determinant before trusting a fit.