05 · The Multivariate Gaussian — A Working Reference
A standalone tutorial accompanying W03, and deliberately built as a reference rather than a narrative: the results you will keep needing, each with enough derivation to see why it is true. The organising fact is that the multivariate normal is closed under everything linear, which is why it is the only distribution this course ever propagates through a computation.
1. The definition, and the one-line reason for its shape
A random vector \(X \in \mathbb{R}^d\) is multivariate normal, written \(X \sim \mathcal{N}(\mu, \Sigma)\), when it has density
\[ p(x) \;=\; \frac{1}{(2\pi)^{d/2}\,(\det\Sigma)^{1/2}} \exp\!\Big(\!-\tfrac12 (x-\mu)^{\!\top}\Sigma^{-1}(x-\mu)\Big), \]
with \(\mu \in \mathbb{R}^d\) the mean vector and \(\Sigma\) a symmetric positive definite \(d \times d\) covariance matrix, \(\Sigma_{ij} = \operatorname{Cov}(X_i, X_j)\).
Everything in the exponent is the scalar
\[ \Delta^2(x) \;=\; (x-\mu)^{\!\top}\Sigma^{-1}(x-\mu), \]
the squared Mahalanobis distance — distance from the mean, measured in units of the spread in each direction. So the density depends on \(x\) only through \(\Delta^2\), and its level sets \(\{\Delta^2 = c\}\) are ellipsoids centred at \(\mu\), with axes along the eigenvectors of \(\Sigma\) and semi-axis lengths proportional to \(\sqrt{\lambda_i}\).
\((\det\Sigma)^{1/2}\) is the volume factor of the linear map that turns a round unit ball into that ellipsoid — see §4. The \((2\pi)^{d/2}\) is \(d\) copies of the univariate \(\sqrt{2\pi}\). Neither is arbitrary; both are forced by requiring \(\int p = 1\).
What it costs to go multivariate
A single Gaussian is \(\mathcal{N}(\mu,\sigma^2)\): two numbers. The \(d\)-dimensional version needs a mean vector and a covariance matrix, so the parameter count jumps from \(2\) to
\[ d + \binom{d+1}{2} \;=\; \frac{d(d+3)}{2}, \]
which for a \(784\)-pixel image is \(308{,}504\). Worth seeing where that growth comes from: not from the means, which contribute only \(d\), but from the covariance, which has to record how every coordinate co-varies with every other. This is the whole of the “high-dimensional density estimation is hard” problem in one line, and it is what motivates the structured and low-rank alternatives.
2. Identity covariance: the joint is a product
This is the fact worth internalising first. Take \(\mu = 0\) and \(\Sigma = I\). Then \(\det I = 1\), \(I^{-1} = I\), and \(x^\top x = \sum_i x_i^2\), so
\[ p(x) = \frac{1}{(2\pi)^{d/2}} e^{-\frac12 \sum_i x_i^2} = \prod_{i=1}^{d} \frac{1}{\sqrt{2\pi}} e^{-x_i^2/2} = \prod_{i=1}^{d} p(x_i). \]
The exponential turns a sum in the exponent into a product of factors, and each factor is a standard univariate normal. So \(\mathcal{N}(0, I)\) in \(d\) dimensions is nothing more than \(d\) independent standard normals stacked into a vector — there is no extra content in the multivariate object at all.
More generally, whenever \(\Sigma\) is diagonal, \(\Sigma = \operatorname{diag}(\sigma_1^2,\dots,\sigma_d^2)\), the same factorisation gives \(p(x) = \prod_i \mathcal{N}(x_i; \mu_i, \sigma_i^2)\): diagonal covariance means independent coordinates.
For a general joint distribution, zero correlation does not imply independence. What makes the implication valid here is joint normality. Gaussian marginals are not enough; the pair must be jointly Gaussian.
This is also why diffusion models add \(\mathcal{N}(0, \sigma^2 I)\) noise and never worry about the dimension: isotropic Gaussian noise is per-pixel independent noise, and the \(784\)-dimensional statement is \(784\) one-dimensional statements.
3. The results, in one table
Throughout, \(X \sim \mathcal{N}(\mu, \Sigma)\) in \(\mathbb{R}^d\).
| Result | Statement |
|---|---|
| Affine map | \(AX + b \sim \mathcal{N}(A\mu + b,\; A\Sigma A^{\!\top})\) for any \(A \in \mathbb{R}^{m\times d}\), \(b\in\mathbb{R}^m\) |
| Linear functional | \(a^{\!\top} X \sim \mathcal{N}(a^{\!\top}\mu,\; a^{\!\top}\Sigma a)\) — every projection is univariate normal |
| Characterisation | conversely, if \(a^{\!\top}X\) is univariate normal for every \(a\), then \(X\) is multivariate normal |
| Marginals | any subvector \(X_S \sim \mathcal{N}(\mu_S, \Sigma_{SS})\) — just delete the other rows and columns |
| Conditionals | Gaussian too; formula in §5 |
| Independent sum | \(X \perp Y\), \(Y \sim \mathcal{N}(\nu, T)\) \(\Rightarrow\) \(X + Y \sim \mathcal{N}(\mu+\nu,\; \Sigma + T)\) |
| Uncorrelated blocks | \(\Sigma_{12} = 0\) \(\Rightarrow\) \(X_1 \perp X_2\) (needs joint normality) |
| Whitening | \(\Sigma = LL^{\!\top}\) \(\Rightarrow\) \(L^{-1}(X - \mu) \sim \mathcal{N}(0, I)\) |
| Sampling | \(\mu + L\boldsymbol\varepsilon\) with \(\boldsymbol\varepsilon \sim \mathcal{N}(0,I)\) has law \(\mathcal{N}(\mu,\Sigma)\) |
| Mahalanobis | \((X-\mu)^{\!\top}\Sigma^{-1}(X-\mu) \sim \chi^2_d\) |
| Entropy | \(h(X) = \tfrac12 \log\!\big((2\pi e)^d \det\Sigma\big)\) nats |
| MGF | \(\mathbb{E}[e^{t^{\!\top}X}] = \exp\!\big(t^{\!\top}\mu + \tfrac12 t^{\!\top}\Sigma t\big)\) |
4. Linear transformations, which is the whole engine
The result. If \(X \sim \mathcal{N}(\mu,\Sigma)\) and \(Y = AX + b\), then
\[ \boxed{\;Y \sim \mathcal{N}\big(A\mu + b,\; A\Sigma A^{\!\top}\big).\;} \]
Why the mean and covariance are those. No normality needed for this part — it is just linearity of expectation and the definition of covariance:
\[ \mathbb{E}[Y] = A\,\mathbb{E}[X] + b = A\mu + b, \] \[ \operatorname{Cov}(Y) = \mathbb{E}\big[(Y - A\mu - b)(\cdot)^{\!\top}\big] = \mathbb{E}\big[A(X-\mu)(X-\mu)^{\!\top}A^{\!\top}\big] = A\Sigma A^{\!\top}. \]
Why the result is still Gaussian. That is the content, and it deserves more than one line. The argument runs through the moment generating function, so we build that first.
The moment generating function
For a random vector \(X\) in \(\mathbb{R}^d\), define
\[ M_X(t) \;=\; \mathbb{E}\big[e^{t^{\!\top}X}\big], \qquad t \in \mathbb{R}^d . \]
It is called moment generating because differentiating at the origin returns the moments. In one dimension, expanding \(e^{tX} = \sum_k t^k X^k / k!\) and differentiating term by term gives \(M^{(k)}(0) = \mathbb{E}[X^k]\). In \(d\) dimensions the same expansion gives
\[ \nabla M_X(0) = \mathbb{E}[X] = \mu, \qquad \nabla^2 M_X(0) = \mathbb{E}\big[XX^{\!\top}\big] = \Sigma + \mu\mu^{\!\top} . \]
So the MGF packages every moment into a single function of \(t\).
The property we actually need is stronger than that. It is the uniqueness theorem: if \(M_X(t) = M_Y(t)\) for all \(t\) in some open neighbourhood of the origin, then \(X\) and \(Y\) have the same distribution. The MGF does not merely summarise a law — it determines it. That is what licenses an argument of the form “compute an MGF, recognise it, conclude”.
The MGF characterises a distribution when it exists in a neighbourhood of \(0\), and not every distribution has one — \(\mathbb{E}[e^{tX}]\) is infinite for all \(t \ne 0\) for a Cauchy, and for all \(t > 0\) for a lognormal. The fix is the characteristic function \(\varphi_X(t) = \mathbb{E}[e^{i t^{\!\top}X}]\), which exists for every distribution because \(|e^{i\theta}| = 1\), and which satisfies the same uniqueness theorem. Every argument below goes through verbatim with \(\varphi\) in place of \(M\) and \(it\) in place of \(t\). For the Gaussian the MGF exists for all \(t \in \mathbb{R}^d\), so we may use the simpler object.
The MGF of a Gaussian
Take the scalar case first, \(X \sim \mathcal{N}(\mu,\sigma^2)\):
\[ M_X(t) = \int_{-\infty}^{\infty} e^{tx}\, \frac{1}{\sqrt{2\pi\sigma^2}}\, e^{-(x-\mu)^2/2\sigma^2}\, dx . \]
Everything is in the exponent, so complete the square there. Writing the two terms over a common denominator and grouping,
\[ tx - \frac{(x-\mu)^2}{2\sigma^2} \;=\; \underbrace{\mu t + \tfrac12 \sigma^2 t^2}_{\text{free of } x} \;-\; \frac{\big(x - \mu - \sigma^2 t\big)^2}{2\sigma^2} . \]
(Multiply out both sides to check it; the cross terms are what force the \(\tfrac12\sigma^2t^2\).) The first part comes outside the integral, and what is left is a Gaussian density with mean \(\mu + \sigma^2 t\) and variance \(\sigma^2\), which integrates to \(1\). Hence
\[ \boxed{\;M_X(t) = \exp\!\Big(\mu t + \tfrac12 \sigma^2 t^2\Big).\;} \]
Note the shape: the exponent is a quadratic in \(t\). Everything that follows is a consequence of that one fact.
Now \(d\) dimensions. For \(\boldsymbol\varepsilon \sim \mathcal{N}(0, I_d)\) the coordinates are independent standard normals, so the expectation factorises:
\[ M_{\boldsymbol\varepsilon}(t) = \mathbb{E}\Big[\textstyle\prod_i e^{t_i \varepsilon_i}\Big] = \prod_i \mathbb{E}\big[e^{t_i \varepsilon_i}\big] = \prod_i e^{t_i^2/2} = e^{\frac12 t^{\!\top}t} . \]
For general \(X \sim \mathcal{N}(\mu,\Sigma)\), factor \(\Sigma = LL^{\!\top}\) and substitute \(x = \mu + Lu\) in the defining integral. The Jacobian is the constant \(\det L\), which cancels against the \((\det\Sigma)^{1/2} = |\det L|\) in the normalising constant, and the quadratic form becomes \(u^{\!\top}u\). What remains is the standard-normal integral evaluated at \(L^{\!\top}t\):
\[ M_X(t) = e^{t^{\!\top}\mu}\, M_{\boldsymbol\varepsilon}\big(L^{\!\top}t\big) = e^{t^{\!\top}\mu}\, e^{\frac12 (L^{\!\top}t)^{\!\top}(L^{\!\top}t)} = \exp\!\Big(t^{\!\top}\mu + \tfrac12 t^{\!\top}LL^{\!\top}t\Big), \]
so
\[ \boxed{\;M_X(t) = \exp\!\Big(t^{\!\top}\mu + \tfrac12\, t^{\!\top}\Sigma\, t\Big).\;} \]
This is a change of variables inside an integral, not an appeal to the affine theorem — so there is no circularity in using it to prove that theorem next.
The affine theorem, one step at a time
Compute the MGF of \(Y = AX + b\) and see what it turns out to be.
\[ M_Y(t) \;=\; \mathbb{E}\big[e^{t^{\!\top}Y}\big] \;=\; \mathbb{E}\big[e^{t^{\!\top}(AX+b)}\big] \qquad\text{(definition, then substitute } Y) \]
\[ =\; e^{t^{\!\top}b}\; \mathbb{E}\big[e^{t^{\!\top}AX}\big] \qquad\text{($b$ is constant, so } e^{t^{\!\top}b} \text{ leaves the expectation)} \]
\[ =\; e^{t^{\!\top}b}\; \mathbb{E}\big[e^{(A^{\!\top}t)^{\!\top}X}\big] \qquad\text{(since } t^{\!\top}A = (A^{\!\top}t)^{\!\top}) \]
That third line is the move that makes the whole thing work: the matrix has been pushed off the random vector and onto the argument of the MGF. The expectation is now \(M_X\) evaluated at the point \(A^{\!\top}t\), and we know \(M_X\):
\[ =\; e^{t^{\!\top}b}\, \exp\!\Big((A^{\!\top}t)^{\!\top}\mu + \tfrac12 (A^{\!\top}t)^{\!\top}\Sigma\,(A^{\!\top}t)\Big) \qquad\text{(apply the Gaussian MGF)} \]
\[ =\; \exp\!\Big(t^{\!\top}b + t^{\!\top}\!A\mu + \tfrac12\, t^{\!\top}\!A\Sigma A^{\!\top} t\Big) \qquad\text{(transpose each piece)} \]
\[ =\; \exp\!\Big(t^{\!\top}\big(A\mu + b\big) + \tfrac12\, t^{\!\top}\big(A\Sigma A^{\!\top}\big) t\Big) \qquad\text{(collect the linear terms)} \]
Now read the answer. It has the form \(\exp\big(t^{\!\top}m + \tfrac12 t^{\!\top}S\,t\big)\) — a linear term plus a quadratic term, which is precisely the shape of a Gaussian MGF, with \(m = A\mu+b\) and \(S = A\Sigma A^{\!\top}\). By the uniqueness theorem, a distribution with that MGF is \(\mathcal{N}(A\mu+b, A\Sigma A^{\!\top})\). \(\square\)
What made it work. A Gaussian MGF is the exponential of a quadratic in \(t\). Substituting \(A^{\!\top}t\) into a quadratic yields another quadratic — that is the entire mechanism, and it is why the family is closed. Push a distribution whose MGF is not the exponential of a quadratic through the same steps and you land on a function of a different shape, which is a different family. Closure under linear maps is not a lucky property of the Gaussian; it is a restatement of the fact that its log-MGF is quadratic.
Sampling and whitening are this result, read in the two directions. Factor \(\Sigma = LL^{\!\top}\) (Cholesky, or \(\Sigma^{1/2}\) from the eigendecomposition). Then
- forward, \(\boldsymbol\varepsilon \sim \mathcal{N}(0,I) \Rightarrow \mu + L\boldsymbol\varepsilon \sim \mathcal{N}(\mu, LL^{\!\top}) = \mathcal{N}(\mu,\Sigma)\) — this is how you sample any Gaussian from standard noise;
- backward, \(X \sim \mathcal{N}(\mu,\Sigma) \Rightarrow L^{-1}(X-\mu) \sim \mathcal{N}(0,I)\) — this is whitening, and it is why one can always assume \(\mathcal{N}(0,I)\) without loss of generality.
Almost every operation in this course is linear: adding noise, taking a weighted average of a signal and noise, projecting, marginalising. The Gaussian family is closed under all of them, with the parameters transforming by a rule you can compute in closed form. Push almost any other family through a linear map and you leave the family and lose the closed form. That closure is the entire reason diffusion models are analytically tractable.
Degenerate case. If \(A\) has rank \(< d\) then \(A\Sigma A^{\!\top}\) is singular, \(\det = 0\), and the density formula of §1 breaks down — the law is still Gaussian, but it is concentrated on a lower-dimensional subspace and has no density with respect to Lebesgue measure on \(\mathbb{R}^m\). The demo’s singular preset shows the cloud collapsing to a line.
Interactive demo — The Gaussian Lab
5. Marginals and conditionals
Split \(X\) into blocks, and \(\mu, \Sigma\) to match:
\[ X = \begin{pmatrix} X_1 \\ X_2\end{pmatrix},\qquad \mu = \begin{pmatrix} \mu_1 \\ \mu_2\end{pmatrix},\qquad \Sigma = \begin{pmatrix} \Sigma_{11} & \Sigma_{12} \\ \Sigma_{21} & \Sigma_{22}\end{pmatrix}. \]
Marginal. \(X_1 \sim \mathcal{N}(\mu_1, \Sigma_{11})\). Note how easy this is: you delete the blocks belonging to \(X_2\). No integration is needed, because marginalising is the linear map \(X \mapsto \begin{pmatrix} I & 0\end{pmatrix}X\), and §4 already tells you the answer.
Conditional.
\[ X_1 \mid X_2 = x_2 \;\sim\; \mathcal{N}\Big(\underbrace{\mu_1 + \Sigma_{12}\Sigma_{22}^{-1}(x_2 - \mu_2)}_{\text{mean moves linearly in } x_2},\; \underbrace{\Sigma_{11} - \Sigma_{12}\Sigma_{22}^{-1}\Sigma_{21}}_{\text{variance does not depend on } x_2}\Big). \]
Two features are worth pausing on, because they are unusual and the course leans on both. The conditional mean is a linear function of what you observed — so the best predictor of \(X_1\) from \(X_2\) is linear, which is why linear regression is exactly right under joint normality and only an approximation otherwise. And the conditional variance does not depend on the observed value at all: you learn the same amount whatever \(x_2\) turns out to be.
In two dimensions with correlation \(\rho\) this reduces to: \(Y \mid X = x \sim \mathcal{N}(\rho x,\, 1-\rho^2)\) for standard marginals.
6. Sums, and why noise accumulates the way it does
If \(X \sim \mathcal{N}(\mu,\Sigma)\) and \(Y \sim \mathcal{N}(\nu,T)\) are independent, then \(X + Y \sim \mathcal{N}(\mu+\nu,\ \Sigma+T)\): means add, covariances add. (Independence is essential — without it the covariance of the sum picks up cross terms, \(\Sigma + T + \operatorname{Cov}(X,Y) + \operatorname{Cov}(Y,X)\).)
This is the whole of the course’s forward process. With \(x_0\) fixed and \(\boldsymbol\varepsilon \sim \mathcal{N}(0,I)\),
\[ x_\sigma = x_0 + \sigma \boldsymbol\varepsilon \;\sim\; \mathcal{N}(x_0,\ \sigma^2 I), \]
and composing two such steps gives \(\mathcal{N}(x_0, (\sigma_1^2 + \sigma_2^2)I)\): variances add, standard deviations do not. Noise accumulates like \(\sqrt{\sigma_1^2 + \sigma_2^2}\), which is the \(\sqrt{t}\) envelope of W01.
7. Where each result gets used
| Result | Where it appears |
|---|---|
| \(\Sigma = I\) factorises | isotropic noise; per-pixel independence in high dimension |
| \(\mu + L\boldsymbol\varepsilon\) sampling | drawing from any Gaussian given standard noise |
| Affine closure | every step of the forward process stays Gaussian |
| Variances add | the \(\sqrt{t}\) noise envelope; the VE schedule |
| Marginals are Gaussian | \(p(x_t \mid x_0)\) in closed form at any \(t\) |
| Conditional mean is linear | why the two-point posterior is tractable |
| Entropy formula | measuring how much a noising step destroys |
Exercises
- Verify directly from the density that \(\mathcal{N}(0, \sigma^2 I_d)\) factorises into \(d\) independent \(\mathcal{N}(0,\sigma^2)\) coordinates. Where exactly does the argument use that \(\Sigma\) is diagonal?
- Let \(X \sim \mathcal{N}(0, I_2)\) and \(A = \begin{pmatrix} 2 & 1 \\ 0 & 1\end{pmatrix}\). Compute the law of \(AX\). Sketch its one-\(\sigma\) ellipse and check it against Act II of the demo.
- Show that if \(X \sim \mathcal{N}(\mu,\Sigma)\) then \(a^{\!\top}X\) is univariate normal for every fixed \(a\), using §4 with \(A = a^{\!\top}\). Then explain why the converse (used as a definition of multivariate normality) is a strictly stronger statement than “every coordinate is normal”.
- For the bivariate case with \(\mu = 0\), \(\sigma_1 = \sigma_2 = 1\) and correlation \(\rho\), derive the conditional \(Y \mid X = x\) from the block formula of §5 and confirm you get \(\mathcal{N}(\rho x, 1-\rho^2)\).
- Two independent noising steps of size \(\sigma_1\) then \(\sigma_2\) are applied to a fixed \(x_0\). Show the result is the same in law as one step of size \(\sqrt{\sigma_1^2+\sigma_2^2}\). Why does this fail if the two noises are correlated?
- (Degeneracy.) Take \(A = \begin{pmatrix} 1 & 1 \\ 2 & 2\end{pmatrix}\) and \(X \sim \mathcal{N}(0,I_2)\). Compute \(A\Sigma A^{\!\top}\), show it is singular, and describe where the resulting law actually lives. Why does the density formula of §1 not apply?
- (Entropy.) Using \(h(X) = \tfrac12\log((2\pi e)^d \det\Sigma)\), show that an affine map \(X \mapsto AX + b\) with \(A\) square and invertible changes the entropy by exactly \(\log|\det A|\) — and explain why \(b\) does not appear.