Skip to main content
© 2026 ePowerAI — instrumented learning, no login required.
CoursesContact
ePOWERAI
CoursesContact
Week 6: Multivariate Gaussians
Prob & Stats
01Week 1: Probability Spaces and Events
02Week 2: Random Variables and Distributions
03Week 3: Expectation, Variance, and Covariance
04Week 4: Conditioning and Independence
05Week 5: Bayes' Rule and Generative Classification
06Week 6: Multivariate Gaussians
07Week 7: Laws of Large Numbers and the CLT
08Week 8: Point Estimation — Maximum Likelihood
09Week 9: Bayesian Estimation and MAP
10Week 10: Bias, Variance, and Uncertainty
11Week 11: Information Theory for ML
12Week 12: Exponential Families (lite)
13Week 13: Graphical Models (lite)
14Week 14: Capstone — Probabilistic Language of ML
Week 06· Prob & Stats· Foundations8 min read

Week 6: Multivariate Gaussians

Learning Outcomes
  • Write the multivariate Gaussian density and the role of μ\muμ and Σ\SigmaΣ
  • Extract marginals and state the conditional Gaussian formula at use-level
  • Explain why Σ\SigmaΣ must be PSD (link to Linear Algebra quadratic forms)
  • Whiten data with Σ−1/2\Sigma^{-1/2}Σ−1/2 intuition
Prerequisites

Required: Weeks 2–3 (random variables, expectation, variance, covariance). Linear Algebra (course index) — vectors, matrices, quadratic forms xTΣxx^T \Sigma xxTΣx, and the idea that a covariance matrix must be positive semidefinite.

Later use: Multivariate Gaussians underpin everything from Kalman filters to diffusion models to Gaussian processes. This week is the bridge from 1D probability to the multivariate language used throughout ML.

  • Also see: Robot Learning Week 2: Dynamics and State Estimation — Gaussians doing real work in a Kalman filter.

From 1D Normal to nD#

The univariate normal (Gaussian) X∼N(μ,σ2)X \sim \mathcal{N}(\mu, \sigma^2)X∼N(μ,σ2) has density:

f(x)=12πσ2exp⁡(−(x−μ)22σ2).f(x) = \frac{1}{\sqrt{2\pi\sigma^2}} \exp\left(-\frac{(x-\mu)^2}{2\sigma^2}\right).f(x)=2πσ2​1​exp(−2σ2(x−μ)2​).

A multivariate Gaussian (also called a multivariate normal) in Rd\mathbb{R}^dRd is parameterised by a mean vector μ∈Rd\mu \in \mathbb{R}^dμ∈Rd and a covariance matrix Σ∈Rd×d\Sigma \in \mathbb{R}^{d \times d}Σ∈Rd×d:

f(x)=1(2π)d/2∣Σ∣1/2exp⁡(−12(x−μ)TΣ−1(x−μ)).f(x) = \frac{1}{(2\pi)^{d/2} |\Sigma|^{1/2}} \exp\left(-\frac{1}{2}(x-\mu)^T \Sigma^{-1}(x-\mu)\right).f(x)=(2π)d/2∣Σ∣1/21​exp(−21​(x−μ)TΣ−1(x−μ)).

Notation: X∼N(μ,Σ)X \sim \mathcal{N}(\mu, \Sigma)X∼N(μ,Σ). The term (x−μ)TΣ−1(x−μ)(x-\mu)^T \Sigma^{-1}(x-\mu)(x−μ)TΣ−1(x−μ) is the Mahalanobis distance squared — it generalises the squared z-score (x−μ)2/σ2(x-\mu)^2 / \sigma^2(x−μ)2/σ2 to multiple dimensions.

Level sets are ellipsoids. The set of points where the density is constant satisfies (x−μ)TΣ−1(x−μ)=c2(x-\mu)^T \Sigma^{-1}(x-\mu) = c^2(x−μ)TΣ−1(x−μ)=c2 — an ellipsoid centred at μ\muμ. The shape and orientation of the ellipsoid are determined by Σ\SigmaΣ:

  • Diagonal Σ\SigmaΣ with equal entries: spherical level sets (isotropic).
  • Diagonal Σ\SigmaΣ with different entries: axis-aligned ellipses.
  • Non-diagonal Σ\SigmaΣ: tilted ellipses — the off-diagonal entries encode linear dependence between dimensions.

For d=1d=1d=1, Σ\SigmaΣ is just σ2\sigma^2σ2, and we recover the familiar bell curve.

Mean and Covariance#

A multivariate Gaussian shown as covariance ellipses with eigenvector axes

A multivariate Gaussian is a mean plus a covariance matrix, drawn as a family of ellipsoids. The eigenvectors of Σ\SigmaΣ give the axes of those ellipsoids and the eigenvalues give their lengths — the same spectral picture that whitening inverts.

The parameters μ\muμ and Σ\SigmaΣ are exactly the mean and covariance:

  • E[X]=μ\mathbb{E}[X] = \muE[X]=μ (an element-wise expectation: μi=E[Xi]\mu_i = \mathbb{E}[X_i]μi​=E[Xi​]).
  • Cov(X)=E[(X−μ)(X−μ)T]=Σ\mathrm{Cov}(X) = \mathbb{E}[(X-\mu)(X-\mu)^T] = \SigmaCov(X)=E[(X−μ)(X−μ)T]=Σ, where Σij=Cov(Xi,Xj)\Sigma_{ij} = \mathrm{Cov}(X_i, X_j)Σij​=Cov(Xi​,Xj​).

The covariance matrix is symmetric (Σ=ΣT\Sigma = \Sigma^TΣ=ΣT) and positive semidefinite (PSD): for any vector vvv, vTΣv≥0v^T \Sigma v \ge 0vTΣv≥0.

Why PSD? Consider the variance of the scalar vTX=∑iviXiv^T X = \sum_i v_i X_ivTX=∑i​vi​Xi​. This variance must be ≥0\ge 0≥0:

Var(vTX)=vTCov(X)v=vTΣv≥0.\mathrm{Var}(v^T X) = v^T \mathrm{Cov}(X) v = v^T \Sigma v \ge 0.Var(vTX)=vTCov(X)v=vTΣv≥0.

If Σ\SigmaΣ were not PSD, there would exist some linear combination of the XiX_iXi​ with negative variance — impossible. This connects to the Linear Algebra course: Σ\SigmaΣ is a symmetric PSD matrix, so its eigenvalues are all ≥0\ge 0≥0, and the condition number governs how "stretched" the ellipsoid is along each eigen-direction.

Correlation from covariance: The correlation matrix RRR has entries ρij=Σij/ΣiiΣjj\rho_{ij} = \Sigma_{ij} / \sqrt{\Sigma_{ii} \Sigma_{jj}}ρij​=Σij​/Σii​Σjj​​. Diagonal entries of RRR are always 1; off-diagonals are in [−1,1][-1, 1][−1,1].

Worked example — 2D Gaussian. Let

μ=(31),Σ=(4111).\mu = \begin{pmatrix} 3 \\ 1 \end{pmatrix}, \quad \Sigma = \begin{pmatrix} 4 & 1 \\ 1 & 1 \end{pmatrix}.μ=(31​),Σ=(41​11​).

Then Var(X1)=4\mathrm{Var}(X_1) = 4Var(X1​)=4, Var(X2)=1\mathrm{Var}(X_2) = 1Var(X2​)=1, Cov(X1,X2)=1\mathrm{Cov}(X_1, X_2) = 1Cov(X1​,X2​)=1, and the correlation is ρ=1/4⋅1=0.5\rho = 1 / \sqrt{4 \cdot 1} = 0.5ρ=1/4⋅1​=0.5. The ellipse is centred at (3,1)(3, 1)(3,1), stretched more horizontally (variance 4) than vertically (variance 1), and tilted because of the positive off-diagonal covariance.

Marginals and Conditionals#

Gaussians are closed under marginalisation and conditioning — if the joint is Gaussian, every marginal and conditional is also Gaussian. This is one reason Gaussians dominate statistical modeling.

Marginals#

If X∼N(μ,Σ)X \sim \mathcal{N}(\mu, \Sigma)X∼N(μ,Σ), then any subset of components is Gaussian. For a partition X=(Xa,Xb)X = (X_a, X_b)X=(Xa​,Xb​):

Xa∼N(μa,Σaa).X_a \sim \mathcal{N}(\mu_a, \Sigma_{aa}).Xa​∼N(μa​,Σaa​).

You simply extract the corresponding sub-vector of μ\muμ and sub-matrix of Σ\SigmaΣ. No integration required. The other variables are "marginalised out" automatically.

Conditionals#

Given X∼N(μ,Σ)X \sim \mathcal{N}(\mu, \Sigma)X∼N(μ,Σ) partitioned as (Xa,Xb)(X_a, X_b)(Xa​,Xb​), the conditional Xa∣Xb=xbX_a \mid X_b = x_bXa​∣Xb​=xb​ is:

Xa∣Xb=xb∼N ⁣(μa+ΣabΣbb−1(xb−μb),  Σaa−ΣabΣbb−1Σba).X_a \mid X_b = x_b \sim \mathcal{N}\!\left(\mu_a + \Sigma_{ab}\Sigma_{bb}^{-1}(x_b - \mu_b),\; \Sigma_{aa} - \Sigma_{ab}\Sigma_{bb}^{-1}\Sigma_{ba}\right).Xa​∣Xb​=xb​∼N(μa​+Σab​Σbb−1​(xb​−μb​),Σaa​−Σab​Σbb−1​Σba​).

Key observations:

  • The conditional mean is a linear function of the observed xbx_bxb​ — the "correction" ΣabΣbb−1(xb−μb)\Sigma_{ab}\Sigma_{bb}^{-1}(x_b - \mu_b)Σab​Σbb−1​(xb​−μb​) adjusts μa\mu_aμa​ based on how far xbx_bxb​ is from its mean, scaled by covariance structure.
  • The conditional covariance Σaa−ΣabΣbb−1Σba\Sigma_{aa} - \Sigma_{ab}\Sigma_{bb}^{-1}\Sigma_{ba}Σaa​−Σab​Σbb−1​Σba​ does not depend on the value xbx_bxb​. Conditioning always reduces (or leaves unchanged) variance — information never increases uncertainty.
  • The Schur complement Σaa−ΣabΣbb−1Σba\Sigma_{aa} - \Sigma_{ab}\Sigma_{bb}^{-1}\Sigma_{ba}Σaa​−Σab​Σbb−1​Σba​ is always PSD (smaller than Σaa\Sigma_{aa}Σaa​ in the Loewner order).

Special case — bivariate. For d=2d=2d=2 with correlation ρ\rhoρ:

X1∣X2=x2∼N ⁣(μ1+ρσ1σ2(x2−μ2),  σ12(1−ρ2)).X_1 \mid X_2 = x_2 \sim \mathcal{N}\!\left(\mu_1 + \rho\frac{\sigma_1}{\sigma_2}(x_2 - \mu_2),\; \sigma_1^2(1-\rho^2)\right).X1​∣X2​=x2​∼N(μ1​+ρσ2​σ1​​(x2​−μ2​),σ12​(1−ρ2)).

If ∣ρ∣=1|\rho| = 1∣ρ∣=1, the conditional variance shrinks to zero — knowing X2X_2X2​ determines X1X_1X1​ exactly. If ρ=0\rho = 0ρ=0, the conditional mean and variance are the marginal values (no information gained).

Whitening and Mahalanobis#

Whitening transforms correlated data into uncorrelated, unit-variance data. Given X∼N(μ,Σ)X \sim \mathcal{N}(\mu, \Sigma)X∼N(μ,Σ), the whitened variable is:

Z=Σ−1/2(X−μ)∼N(0,Id).Z = \Sigma^{-1/2}(X - \mu) \sim \mathcal{N}(0, I_d).Z=Σ−1/2(X−μ)∼N(0,Id​).

Σ−1/2\Sigma^{-1/2}Σ−1/2 is the inverse matrix square root — it exists because Σ\SigmaΣ is positive definite (invertible). If Σ\SigmaΣ is only PSD — for example a perfectly collinear data set — it is singular, and whitening is defined via the pseudo-inverse on the range space. After whitening, each component of ZZZ is independent standard normal.

The Mahalanobis distance between xxx and the distribution is:

DM(x)=(x−μ)TΣ−1(x−μ).D_M(x) = \sqrt{(x-\mu)^T \Sigma^{-1}(x-\mu)}.DM​(x)=(x−μ)TΣ−1(x−μ)​.

This is the Euclidean distance in the whitened space. It accounts for correlation and differing variances — a point far from the mean in a high-variance direction gets less "surprise penalty" than the same Euclidean distance in a low-variance direction. This is used in anomaly detection, clustering, and as a building block in Kalman filters.

Why Gaussians Dominate ML Modeling#

  • Central Limit Theorem (Week 7): sums of many independent random variables become approximately Gaussian — errors, noise, and aggregate quantities are often near-normal.
  • Closed under linear operations: if X∼N(μ,Σ)X \sim \mathcal{N}(\mu, \Sigma)X∼N(μ,Σ) and Y=AX+bY = AX + bY=AX+b, then Y∼N(Aμ+b,AΣAT)Y \sim \mathcal{N}(A\mu + b, A\Sigma A^T)Y∼N(Aμ+b,AΣAT). Linear transformations preserve Gaussianity.
  • Conjugacy (Week 9): a Gaussian prior with a Gaussian likelihood yields a Gaussian posterior — Bayesian updates stay in the same family.
  • Maximum entropy: among all distributions with a given mean and covariance, the Gaussian has the largest entropy — it is the "least informative" assumption consistent with those moments.
  • Limitations: real data is often heavier-tailed, multimodal, or bounded. But Gaussians remain the default building block because of their mathematical tractability.
Exercise · Multiple choice

Given Σ = [[4, 1], [1, 1]] for a 2D Gaussian. Is Σ a valid covariance matrix? (Hint: check if it's positive semidefinite.)

Yes — eigenvalues are both positive
No — off-diagonal is non-zero
Yes — any symmetric matrix is PSD
No — variance entries must be integers

Knowledge check#

Question 1 of 4

If X = (X₁, X₂) is jointly Gaussian, the marginal distribution of X₁ is:

Gaussian with mean μ₁ and variance Σ₁₁
Gaussian but its variance depends on X₂
Not necessarily Gaussian
Always standard normal

Browser lab#

Sample a 2D Gaussian, plot scatter with ellipse level curves, and show a conditional slice histogram.

python · runs in browser
import numpy as np
import matplotlib.pyplot as plt
from numpy.linalg import eigh

rng = np.random.default_rng(42)
n = 3000

mu = np.array([3.0, 1.0])
Sigma = np.array([[4.0, 1.0],
                   [1.0, 1.0]])

samples = rng.multivariate_normal(mu, Sigma, size=n)

def plot_ellipse(ax, mu, Sigma, n_std=2, **kwargs):
    vals, vecs = eigh(Sigma)
    theta = np.linspace(0, 2*np.pi, 200)
    circle = np.array([np.cos(theta), np.sin(theta)])
    ellipse = (vecs @ np.diag(np.sqrt(vals) * n_std)) @ circle + mu[:, None]
    ax.plot(ellipse[0], ellipse[1], **kwargs)

fig, axes = plt.subplots(1, 3, figsize=(14, 4.5))

ax = axes[0]
ax.scatter(samples[:800, 0], samples[:800, 1], alpha=0.3, s=5)
plot_ellipse(ax, mu, Sigma, n_std=1, color="tab:red", linewidth=2, label="1σ")
plot_ellipse(ax, mu, Sigma, n_std=2, color="tab:red", linewidth=1.5, linestyle="--", label="2σ")
ax.scatter(*mu, color="black", marker="x", s=80, label="μ")
ax.set_aspect("equal")
ax.set_xlabel("X₁"); ax.set_ylabel("X₂")
ax.set_title("Scatter + level sets")
ax.legend()

ax = axes[1]
cond_val = 3.0
near = samples[np.abs(samples[:, 0] - cond_val) < 0.2]
ax.hist(near[:, 1], bins=30, density=True, alpha=0.7, label=f"X₂ | X₁≈ {cond_val}")

# True conditional: X₂ | X₁ = x₁
rho = Sigma[0, 1] / np.sqrt(Sigma[0, 0] * Sigma[1, 1])
cond_mean = mu[1] + rho * np.sqrt(Sigma[1, 1] / Sigma[0, 0]) * (cond_val - mu[0])
cond_var = Sigma[1, 1] * (1 - rho**2)
x2_grid = np.linspace(mu[1] - 3, mu[1] + 3, 200)
cond_pdf = (1 / np.sqrt(2 * np.pi * cond_var)) * np.exp(-0.5 * (x2_grid - cond_mean)**2 / cond_var)
ax.plot(x2_grid, cond_pdf, "tab:red", linewidth=2, label="True conditional")
ax.set_title(f"Conditional X₂ | X₁ = {cond_val}")
ax.set_xlabel("X₂"); ax.legend()

ax = axes[2]
x1_marginal = np.linspace(mu[0] - 4, mu[0] + 4, 200)
marg_pdf = (1 / np.sqrt(2 * np.pi * Sigma[0, 0])) * np.exp(-0.5 * (x1_marginal - mu[0])**2 / Sigma[0, 0])
ax.hist(samples[:, 0], bins=50, density=True, alpha=0.5, label="Empirical marginal")
ax.plot(x1_marginal, marg_pdf, "tab:blue", linewidth=2, label="True marginal")
ax.set_title("Marginal X₁")
ax.set_xlabel("X₁"); ax.legend()

plt.tight_layout()
plt.show()

print(f"Sample mean: {samples.mean(axis=0)}")
print(f"Sample cov:\n{np.cov(samples.T)}")
print(f"Conditional X₂ | X₁=3: mean={cond_mean:.3f}, var={cond_var:.3f}")

print("Notice: E[X₂ | X₁ = 3] = 1.000 and Var = 0.750 match the Gaussian conditional — conditioning on one coordinate is linear.")

Further Reading#

  • Christopher M. Bishop, Pattern Recognition and Machine Learning (Springer, 2006) — §2.3 is the standard treatment of the multivariate Gaussian, marginals, and conditionals.
  • Kevin P. Murphy, Machine Learning: A Probabilistic Perspective (MIT Press, 2012) — Chapter 4 covers Gaussian models, covariance, and linear-Gaussian systems.
  • Kaare B. Petersen & Michael S. Pedersen, The Matrix Cookbook (free online) — the covariance and matrix-derivative identities used throughout.
← Previous
Week 5: Bayes' Rule and Generative Classification
Next →
Week 7: Laws of Large Numbers and the CLT
On this page
  • From 1D Normal to nD
  • Mean and Covariance
  • Marginals and Conditionals
  • Marginals
  • Conditionals
  • Whitening and Mahalanobis
  • Why Gaussians Dominate ML Modeling
  • Knowledge check
  • Browser lab
  • Further Reading