06 · Estimating a Density in Many Dimensions

We know what a multivariate Gaussian is. Now fit one. The maximum likelihood estimator is the sample covariance and the derivation is three lines — and then it collapses, because in almost every application that matters there are fewer samples than variables. This note is about what you do next: impose structure, estimate the inverse rather than the thing itself, and watch every classical method run into the same wall. It ends with the honest verdict on why an entire decade of statistics could not solve this and deep learning did.

1. The estimator, and its three-line derivation

Let \(x_1,\dots,x_n\) be i.i.d. draws from \(\mathcal{N}_p(\mu,\Sigma)\). The log-likelihood is

\[ \ell(\mu,\Sigma) = -\frac{n}{2}\log\det\Sigma - \frac12 \sum_{i=1}^{n}(x_i-\mu)^{\!\top}\Sigma^{-1}(x_i-\mu) + \text{const}. \]

Differentiating in \(\mu\) gives \(\hat\mu = \bar x\), exactly as in one dimension. For \(\Sigma\) the clean route is to reparametrise by the precision matrix \(\Theta = \Sigma^{-1}\) and use the trace trick — a scalar equals its own trace, and the trace is cyclic:

\[ \sum_i (x_i-\bar x)^{\!\top}\Theta(x_i-\bar x) = \sum_i \operatorname{tr}\!\big(\Theta (x_i-\bar x)(x_i-\bar x)^{\!\top}\big) = n\operatorname{tr}(\Theta S), \]

where

\[ S = \frac1n \sum_{i=1}^{n} (x_i - \bar x)(x_i - \bar x)^{\!\top} \]

is the sample covariance. The log-likelihood becomes, up to constants,

\[ \boxed{\;\ell(\Theta) = \frac{n}{2}\Big(\log\det\Theta - \operatorname{tr}(S\Theta)\Big).\;} \]

This is concave in \(\Theta\) (\(\log\det\) is concave on positive definite matrices, the trace term is linear), so setting the gradient to zero is enough. Using \(\partial \log\det\Theta/\partial\Theta = \Theta^{-1}\) and \(\partial \operatorname{tr}(S\Theta)/\partial\Theta = S\):

\[ \Theta^{-1} - S = 0 \quad\Longrightarrow\quad \hat\Sigma = S . \]

The MLE of the covariance is the sample covariance, with divisor \(n\) rather than \(n-1\) — biased, exactly as in the univariate case. And since maximum likelihood is invariant under reparametrisation, the MLE of the correlation matrix is the sample correlation matrix: standardise \(S\) by its own diagonal.

Two things to notice, because both matter in a moment. The likelihood depends on the data only through \(\bar x\) and \(S\) — they are sufficient. And written in \(\Theta\), the problem is a concave maximisation, which is what will later let us bolt a penalty onto it and still have something solvable.

2. Where it collapses: \(n < p\)

The estimator is a formula, so it always returns something. Whether that something is usable is another matter.

\(S\) is a sum of \(n\) rank-one matrices, and centring costs one more degree of freedom, so

\[ \operatorname{rank}(S) \;\le\; \min(n-1,\; p). \]

If \(n \le p\) then \(S\) is singular: \(\det S = 0\), \(S^{-1}\) does not exist, and the fitted density does not exist either — the formula in note 05 divides by \((\det\Sigma)^{1/2}\). Maximum likelihood has not given a bad answer; it has given a degenerate one, a Gaussian concentrated on the \((n-1)\)-dimensional subspace the data happens to span.

Numerically, with \(p = 8\) and \(n = 5\): \(\operatorname{rank}(S) = 4\), and \(\det S\) comes out around \(-10^{-62}\) — a number whose sign is wrong, which is what floating-point arithmetic does with a determinant that is exactly zero.

The counting explains why this is the normal case, not a corner case. A full \(\Sigma\) costs \(p(p+1)/2\) parameters, plus \(p\) for the mean:

\(p\) free parameters samples you would like
10 65 hundreds
100 5,150 tens of thousands
784 (an MNIST digit) 308,504 millions
20,000 (human genes) 200,030,000 —
ImportantThe motivating example: gene regulatory networks

Measure the expression of \(p \approx 20{,}000\) genes across \(n \approx 200\) tissue samples. You want to know which genes regulate which — that is a question about the dependence structure of a \(20{,}000\)-dimensional distribution, estimated from two hundred points.

There are two hundred million covariance parameters and two hundred observations. This is not a hard estimation problem; as stated it is not an estimation problem at all. Without further assumptions the data cannot identify the answer, and no cleverness recovers information that was never collected.

\(n \ll p\) is the typical regime in genomics, neuroimaging, finance and text — not the exception.

3. Estimate the precision, not the covariance

The move that rescues this is to change the target. Instead of estimating \(\Sigma\) and inverting it, estimate \(\Theta = \Sigma^{-1}\) directly. Three reasons, and the third is the real one.

It is the natural parameter. We already saw the likelihood is concave in \(\Theta\) and linear in \(S\). Penalised versions stay convex.

Inverting a bad estimate is worse than estimating the inverse. Small eigenvalues of \(S\) — and when \(n < p\), some are exactly zero — become enormous eigenvalues of \(S^{-1}\). Inversion amplifies precisely the directions the data constrains least.

Zeros in \(\Theta\) mean conditional independence. This is the fact that makes the whole programme work. For a Gaussian,

\[ \boxed{\;\Theta_{ij} = 0 \quad\Longleftrightarrow\quad X_i \perp\!\!\!\perp X_j \;\big|\; X_{\setminus\{i,j\}}. \;} \]

More precisely, the partial correlation — the correlation between \(X_i\) and \(X_j\) once every other variable has been regressed out — is read straight off the precision matrix:

\[ \rho_{ij \,\mid\, \text{rest}} \;=\; \frac{-\Theta_{ij}}{\sqrt{\Theta_{ii}\Theta_{jj}}}. \]

An example worth carrying. Take three variables with an AR(1) correlation structure, \(\operatorname{corr}(X_i,X_j) = 0.6^{|i-j|}\):

\[ \Sigma = \begin{pmatrix} 1 & 0.6 & 0.36 \\ 0.6 & 1 & 0.6 \\ 0.36 & 0.6 & 1\end{pmatrix}, \qquad \Theta = \Sigma^{-1} = \begin{pmatrix} 1.5625 & -0.9375 & 0 \\ -0.9375 & 2.125 & -0.9375 \\ 0 & -0.9375 & 1.5625 \end{pmatrix}. \]

\(\Theta_{13} = 0\) exactly, and direct computation confirms \(\operatorname{Cov}(X_1, X_3 \mid X_2) = 0\). But the marginal correlation between \(X_1\) and \(X_3\) is \(0.36\), comfortably non-zero. The dependence is real; it is simply entirely mediated by \(X_2\). Covariance sees the association; precision sees whether it is direct.

NoteThe Gaussian graphical model

Draw a graph on \(p\) nodes with an edge between \(i\) and \(j\) whenever \(\Theta_{ij} \ne 0\). That graph is the conditional independence structure of the distribution — the Markov graph. For gene networks this is exactly the object of interest: an edge means “these two genes are associated even after accounting for all others”, which is the closest observational data gets to direct regulation.

The idea dates to Dempster’s covariance selection (1972). What changed in the 2000s was the ability to fit it when \(p \gg n\).

Sparsity as the assumption. A biologist will tell you each gene is regulated by a handful of others, not by twenty thousand. So assume most \(\Theta_{ij}\) are zero, and estimate under that assumption. Penalise with an \(\ell_1\) norm, which sets coefficients exactly to zero rather than merely shrinking them:

\[ \hat\Theta = \arg\max_{\Theta \succ 0}\; \Big\{ \log\det\Theta - \operatorname{tr}(S\Theta) - \lambda \textstyle\sum_{i\ne j} |\Theta_{ij}| \Big\}. \]

This is the graphical lasso (Yuan & Lin 2007; Banerjee et al. 2008; Friedman, Hastie & Tibshirani 2008). It is concave-plus-concave, so it is a convex problem with a unique solution — and crucially, for \(\lambda > 0\) the solution is positive definite even when \(S\) is singular. The penalty repairs the rank deficiency. A closely related route is neighbourhood selection (Meinshausen & Bühlmann 2006): run a lasso regression of each variable on all the others and patch the supports together.

The tuning parameter \(\lambda\) buys sparsity with bias, and choosing it is its own literature.

4. The other structural assumptions

Sparsity of \(\Theta\) is one prior belief. It is not the only reasonable one, and the right one depends on what the coordinates are.

Assumption Structure imposed When it is reasonable
Sparse precision most \(\Theta_{ij} = 0\) networks; few direct interactions
Banded / tapered \(\Sigma_{ij} \approx 0\) for \(|i-j|\) large coordinates have an order — time, position along a genome
Thresholded small entries of \(S\) set to zero many negligible marginal associations
Shrinkage \(\hat\Sigma = (1-\alpha)S + \alpha\, \tau I\) no structural belief, just want invertibility
Factor model \(\Sigma = BB^{\!\top} + D\), \(B\) tall and thin a few latent drivers — finance, psychometrics
Low-rank + sparse \(\Sigma = L + S\) latent factors and local interactions
Isotropic / diagonal \(\Sigma = \sigma^2 I\) or diagonal the crude default; independence assumed

Shrinkage deserves a line of its own: the Ledoit–Wolf estimator (2004) mixes \(S\) with a scaled identity and chooses the mixing weight to minimise expected squared error. It assumes nothing about structure, always produces an invertible matrix, and is the sensible default when you have no scientific reason to prefer a shape. Banding and thresholding with rate guarantees are due to Bickel and Levina (2008).

The common thread. Every one of these replaces “estimate \(p(p+1)/2\) numbers” with “estimate far fewer, having assumed the rest away”. The assumption is doing the work. Its content is not statistical but scientific, and if it is wrong the estimate is confidently wrong.

5. One Gaussian is not enough: mixtures and EM

Real data is not unimodal. The next model up is a mixture of Gaussians:

\[ p(x) = \sum_{k=1}^{K} \pi_k\, \mathcal{N}(x; \mu_k, \Sigma_k), \qquad \pi_k \ge 0, \ \textstyle\sum_k \pi_k = 1, \]

which is exactly the latent-variable construction of note 03 — draw a component \(z \sim \text{Categorical}(\pi)\), then draw \(x \mid z \sim \mathcal{N}(\mu_z,\Sigma_z)\), then forget \(z\). Mixtures are dense in a useful sense: with enough components you can approximate essentially any density.

The log-likelihood now contains a log of a sum, which does not separate, and there is no closed form. The standard tool is expectation–maximisation, which alternates:

  • E-step — compute the responsibility of component \(k\) for point \(i\), which is a posterior over the latent label by Bayes’ rule: \[ \gamma_{ik} = \frac{\pi_k\,\mathcal{N}(x_i;\mu_k,\Sigma_k)}{\sum_{m}\pi_m\,\mathcal{N}(x_i;\mu_m,\Sigma_m)}; \]
  • M-step — refit each component as if the responsibilities were the labels: \(\hat\pi_k = \frac1n\sum_i \gamma_{ik}\), \(\hat\mu_k = \frac{\sum_i \gamma_{ik}x_i}{\sum_i \gamma_{ik}}\), and similarly a responsibility-weighted covariance.

EM is coordinate ascent on a lower bound of the log-likelihood — the same ELBO that will reappear when we derive the diffusion training objective. It therefore increases the likelihood at every step, and converges to a stationary point.

WarningTwo failure modes worth knowing

Local optima. EM converges to a stationary point, not the global maximum, and different initialisations give different answers. Restart it.

The likelihood is unbounded. Put one component’s mean exactly on a data point and shrink its variance: the density at that point diverges, and so does the likelihood. At \(\sigma = 10^{-4}\) the peak density is already \(\approx 4000\). There is no maximum likelihood estimator for a Gaussian mixture — the supremum is \(+\infty\), attained by a degenerate spike. What EM finds is a well-behaved local maximum, and implementations add a variance floor or a prior to stay away from the cliff.

And the counting problem has not gone away: \(K\) full covariances cost \(K \cdot p(p+3)/2\) parameters. For MNIST with \(K=10\) that is over three million.

6. Give up on parameters: kernel density estimation

The nonparametric alternative makes no assumption about shape at all. Put a small bump on every observation and add them up:

\[ \hat p_h(x) = \frac{1}{n h^p} \sum_{i=1}^{n} K\!\left(\frac{x - x_i}{h}\right). \]

In one dimension this is excellent and its theory is complete. The bandwidth \(h\) trades bias against variance, and with the optimal choice the mean integrated squared error decays like

\[ \text{MISE} \;\asymp\; n^{-4/(p+4)} \]

for a second-order kernel and a twice-differentiable density. Read the exponent. At \(p=1\) it is \(n^{-4/5}\), nearly the parametric \(n^{-1}\). As \(p\) grows it approaches \(n^{0}\) — no convergence at all.

Invert it and ask how many samples you need to match, in \(p\) dimensions, the accuracy that \(n = 100\) buys in one:

\(p\) samples required
1 100
2 251
5 ~4,000
10 ~400,000
20 ~\(4 \times 10^{9}\)
50 ~\(4 \times 10^{21}\)
100 ~\(4 \times 10^{41}\)

Interactive — The KDE Lab builds the estimate one kernel at a time, then lets you sweep \(h\) against a three-component Gaussian mixture and watch it fail in both directions. Its third panel plots the integrated squared error against \(h\): the curve is U-shaped, and its minimum slides left as \(n\) grows, which is \(h^\star \propto n^{-1/5}\) made visible.

At \(p = 100\) — still a small problem by modern standards — the requirement exceeds the number of atoms in the observable universe by a wide margin. This is not an artefact of KDE. It is a minimax lower bound: over the class of smooth densities, no estimator does better than \(n^{-2s/(2s+p)}\) for smoothness \(s\). The obstruction is information-theoretic, not algorithmic.

ImportantThe curse of dimensionality, stated plainly

Local methods need neighbours, and in high dimension nothing has any. To capture a fraction \(f\) of the data in a hypercube you need side length \(f^{1/p}\): at \(p = 100\), capturing 1% of the data requires a cube spanning \(0.01^{1/100} = 0.955\) of the range of every coordinate. A “local” neighbourhood is nearly the entire space, so local averaging averages over everything and estimates nothing.

Every classical density estimator is local averaging in some disguise. They all inherit this.

7. Another route entirely: be Bayesian

Everything so far produces a point estimate — one matrix, one mixture. The Bayesian alternative refuses to pick: put a prior on the parameters, condition on the data, and report the whole posterior.

Conjugacy makes the Gaussian case exact. With an inverse-Wishart prior \(\Sigma \sim \mathcal{IW}(\Psi,\nu)\), the posterior is again inverse-Wishart,

\[ \Sigma \mid x_{1:n} \;\sim\; \mathcal{IW}\big(\Psi + nS,\; \nu + n\big), \]

and the posterior mean \((\Psi + nS)/(\nu + n - p - 1)\) is a shrinkage estimator — the sample covariance pulled toward the prior scale \(\Psi\). Compare §4: this is Ledoit–Wolf shrinkage, arrived at from a different direction.

Look at what that fixes. When \(n < p\), \(nS\) is singular. But \(\Psi\) is positive definite, so \(\Psi + nS\) is positive definite too, and the posterior is proper whenever \(\nu > p-1\). With \(p=8\), \(n=5\): the scatter matrix has rank 4, the posterior scale has rank 8, and the posterior mean is positive definite. The prior repairs the rank deficiency — not by penalising, but by supplying the information the data lacks. Which is exactly what a penalty does too, and that is not a coincidence:

NotePenalties are log-priors

Maximising \(\log p(\text{data} \mid \theta) - \lambda \|\theta\|_1\) is maximising \(\log p(\text{data}\mid\theta) + \log p(\theta)\) for a Laplace prior. The graphical lasso is the MAP estimate under a Laplace prior on the off-diagonal entries of \(\Theta\). Every penalty in §3–§4 has a prior behind it: ridge is Gaussian, lasso is Laplace, and the modern shrinkage priors — spike-and-slab, horseshoe — have no penalty analogue at all, which is part of their appeal.

Sparsity, done properly. A spike-and-slab prior puts an atom at zero on each \(\Theta_{ij}\), so the posterior assigns genuine probability to each graph. Instead of one estimated network you get a distribution over networks, and the posterior inclusion probability of an edge is a direct answer to “is this regulatory link real?”.

Nonparametric Bayes. A Dirichlet process mixture of Gaussians is a mixture with infinitely many components, of which finitely many are ever used. It removes the need to choose \(K\) in §5 — the number of clusters is inferred rather than tuned.

The cost is computation. Outside conjugate cases the posterior is intractable, so it is explored by Markov chain Monte Carlo: construct a chain whose stationary distribution is the posterior and run it. Gibbs sampling for conditionally conjugate blocks, Metropolis–Hastings in general, Hamiltonian Monte Carlo and NUTS when gradients are available. Variational inference is the cheaper approximation, trading exactness for speed.

WarningWhat Bayes buys, and what it does not

Buys: honest uncertainty. A credible interval on every entry of \(\Theta\), a posterior probability for every edge, automatic regularisation, and no cross-validation for \(\lambda\) — give it a hyperprior and integrate it out. For a scientific question like “which of these edges would survive more data?” this is the right tool and the penalised point estimate simply cannot answer.

Does not buy: escape from the curse. MCMC mixes slowly in high dimension, the space of graphs is combinatorial, and convergence is genuinely hard to certify. At \(p = 20{,}000\) it is not a contender. The difficulty has moved from statistics to computation, but it has not gone away.

TipMCMC is closer to this course than it looks

An MCMC sampler draws from a distribution it can only evaluate up to a normalising constant — which is precisely the obstacle that makes density estimation hard. One such sampler, Langevin dynamics, updates

\[ x \;\leftarrow\; x + \tfrac{h}{2}\,\nabla_x \log p(x) + \sqrt h\,\boldsymbol\varepsilon, \qquad \boldsymbol\varepsilon \sim \mathcal{N}(0,I), \]

Here \(h>0\) is the step size. Notice what the update needs: only \(\nabla_x \log p(x)\), the score. The normalising constant differentiates away. This is the same score that appeared in note 01 via Tweedie’s formula, and the same object Module 4 will learn from data.

Score-based generative models are, genealogically, MCMC with a learned score. The line from this section to the end of the course is short.

8. Sampling without estimating the density

Notice what the MCMC of §7 quietly achieved. It produced draws from a posterior nobody could write down, and at no point did it build an estimate of that posterior. That distinction is the hinge of this whole note: estimating a density and sampling from one are different problems, and the second is very often the easier of the two. Generation only ever needed the second.

Two classical algorithms make the point, and both need the target only up to a normalising constant — which is exactly the part that is unobtainable.

Rejection sampling: propose, then judge

Pick a proposal \(q\) you can sample, and a constant \(M\) with \(p(x) \le M\,q(x)\) for every \(x\). Then repeat: draw \(x \sim q\) and \(u \sim \mathrm{Uniform}(0,1)\), and accept \(x\) if

\[ u \;<\; \frac{p(x)}{M\,q(x)} . \]

Accepted draws are distributed exactly as \(p\) — not approximately. The proof is one line: the pair \((x, u\,M q(x))\) is uniform under the envelope \(Mq\), and accepting keeps precisely those falling under \(p\), so the survivors are uniform under \(p\), whose \(x\)-marginal is \(p\). The acceptance rate is \(1/M\).

The Bayesian case is the tidy one. Take the prior as the proposal and note that the posterior is \(p(x) \propto q(x) L(x)\) for a likelihood \(L\). If \(L\) is bounded then \(M = \max L / Z\) works, the ratio collapses, and the rule becomes

\[ \text{accept with probability } \frac{L(x)}{\max L} . \]

No normalising constant, no evidence integral, no density estimate — just the likelihood evaluated at a point.

WarningThe envelope must actually exist

It is easy to write down a proposal for which no valid \(M\) exists. Take target \(\mathcal{N}(-1,1)\) and proposal \(\mathcal{N}(0,1)\): the ratio is

\[ \frac{p(x)}{q(x)} = e^{-x-\frac12} \;\xrightarrow[x\to-\infty]{}\; \infty , \]

so \(\sup_x p/q = \infty\) and rejection sampling is simply unavailable. A proposal must have heavier tails than the target in every direction. Shifting a Gaussian is not enough; you have to widen it.

And then the usual wall. Take target \(\mathcal{N}(0,I_d)\) with a proposal \(\mathcal{N}(0,\sigma^2 I_d)\), \(\sigma > 1\). The optimal constant is \(M = \sigma^{d}\), so the acceptance rate is \(\sigma^{-d}\):

\(d\) rate at \(\sigma = 1.1\) rate at \(\sigma = 1.5\)
1 0.91 0.67
10 0.39 0.017
100 \(7 \times 10^{-5}\) \(2 \times 10^{-18}\)

A proposal ten percent too wide is already useless at \(d = 100\). Rejection sampling is exact and, in high dimension, exactly worthless.

MCMC: stop proposing from scratch, and walk

The fix is to stop drawing independently and instead move from where you already are. Gibbs sampling draws each coordinate from its conditional given the others; Metropolis–Hastings proposes a local step and accepts with a ratio. Both need \(p\) only through ratios, so the constant cancels again.

What you buy is that the samples are no longer wasted. What you pay is that they are no longer independent — consecutive draws are correlated, and the chain must run a while before its distribution resembles the target at all.

That last phrase deserves to be taken literally. For Gibbs on a standard bivariate normal with correlation \(\rho\), the \(x\)-coordinate is exactly an AR(1) process with coefficient \(\rho^2\), and the law of the chain at step \(t\) started from \(x_0\) is available in closed form:

\[ \boxed{\;x_t \mid x_0 \;\sim\; \mathcal{N}\big(\rho^{2t} x_0,\; 1 - \rho^{4t}\big).\;} \]

The mean decays geometrically toward \(0\) and the variance climbs toward \(1\). So there is not one distribution here but a sequence of them, \(p_0, p_1, p_2, \dots\), flowing toward \(p_\infty\). Burn-in is the interval over which that flow is still visibly incomplete, and the lag-1 autocorrelation \(\rho^2\) is why a strongly correlated target mixes slowly.

Interactive — The Sampling Lab runs both algorithms: darts under an envelope for rejection, and for Gibbs a staircase walk, a trace plot, and 4,000 parallel chains whose histogram at step \(t\) is drawn against the exact \(p_t\) above.

TipA chain is a time series, and its law obeys a PDE

\(p_t \to p_\infty\) is the discrete-time shadow of the Fokker–Planck equation of Module 5, which describes exactly this: how a density evolves under stochastic dynamics. The continuous-time version of the walk is Langevin dynamics, and as §7 noted it needs only the score \(\nabla_x \log p\).

A diffusion model is this picture used deliberately. Its forward process is a chain run in the easy direction — toward a known Gaussian, no learning required. Its reverse process is the same flow run backwards, which is the hard direction and the one worth a semester.

The proposal is a generator; the test is a discriminator

Look at rejection sampling structurally rather than procedurally. It has exactly two components: something that produces candidates, and something that judges them. That is the architecture of a generative adversarial network, with the proposal in the role of the generator and the acceptance test in the role of the discriminator.

The parallel is not a loose analogy — both are density-ratio methods. The optimal discriminator for a GAN with generator distribution \(p_g\) is

\[ D^{*}(x) = \frac{p_{\text{data}}(x)}{p_{\text{data}}(x) + p_g(x)} = \frac{r(x)}{1 + r(x)}, \qquad r = \frac{p_{\text{data}}}{p_g}, \]

a strictly increasing function of the ratio \(r\). Rejection sampling accepts with probability \(p(x)/(M q(x))\) — the same ratio, differently scaled. Both machines run on \(p/q\); they differ in what they know about it and what they do with it.

rejection sampling GAN
Generator the proposal \(q\) a learned network
Discriminator \(p(x)/Mq(x)\), computed exactly a learned network estimating \(r\)
Density ratio known — both densities can be evaluated estimated from samples alone
Rejected mass discarded becomes gradient: it says where to move
Output exact draws from \(p\) approximate draws, improving

The decisive difference is in the row about rejected mass. Rejection sampling throws a dart away and learns nothing; a GAN turns every failure into a signal telling the generator which way to go. That is what makes one method collapse in high dimension and the other not.

ImportantThe real limitation, in both classical methods

In rejection sampling the proposal \(q\) is chosen for convenience. In Metropolis–Hastings the proposal kernel is chosen for convenience. In Gibbs the “proposal” is whatever conditionals happen to be tractable. In every case a human picks a distribution because it is easy to sample, and then hopes it resembles the target — and in high dimension it does not, which is precisely the \(\sigma^{-d}\) table above.

Modern generative models remove that choice: the proposal is learned. A GAN learns a generator, a flow learns an invertible map, and a diffusion model learns a reverse process. Each replaces a hand-picked proposal with one fitted to the data.

A diffusion model goes one step further and dispenses with the judge entirely. Because the forward process is a sequence of small Gaussian steps, each reverse step is nearly Gaussian and can be matched directly — there is nothing to accept or reject. The convenience-chosen proposal, the wasted draws, and the adversarial referee all disappear at once. That is the destination of this course.

9. Where this sits in the landscape

Everything above is unsupervised: there are no labels, only \(x\)’s, and the goal is the distribution itself. It is worth naming what else lives here and what lives next door, because the difficulty is not the same.

Other unsupervised problems. Clustering — partition the data, which is a Gaussian mixture with hard assignments (\(k\)-means is EM with spherical components and responsibilities rounded to 0/1). Dimension reduction — PCA is the factor model of §4 read as an estimator; manifold learning is its nonlinear cousin. Latent variable modelling — factor analysis, topic models, and eventually VAEs. Anomaly detection — density estimation with a threshold on the output.

Supervised problems, by contrast, estimate a conditional: regression wants \(\mathbb{E}[y \mid x]\), classification wants \(\mathbb{P}(y \mid x)\). These are easier, and it is worth being precise about why: you need one number per input rather than a normalised function over the whole space, there is a label telling you when you are wrong, and you never have to compute a normalising constant. A classifier can be excellent while knowing nothing about \(p(x)\).

This course stays in unsupervised density estimation, because generation demands the full distribution. You cannot sample from a conditional mean.

10. Why this was hard, and what actually solved it

Roughly 2000–2010 was an extraordinarily active decade on precisely this problem. Sparsity, \(\ell_1\) penalties, oracle inequalities, minimax rates over structured classes, the graphical lasso, compressed sensing. It produced beautiful and permanent mathematics, and it did not produce a model that can generate a photograph.

Why not. The classical programme’s answer to \(n \ll p\) was: impose structure you can write down and verify. Sparse. Banded. Low-rank. Those are strong assumptions, deliberately simple so that theorems are provable and parameters interpretable. But the structure in a natural image is not sparsity in pixel covariance. It is edges composing into textures composing into objects — a deep, nonlinear, compositional structure that no one can write as a constraint on a matrix. Classical methods were limited not by their estimators but by the poverty of the structures they could express.

What deep learning changed — four moves, none of which is “more data” alone:

  1. Learn the structure instead of assuming it. A network’s layers are a parametrisation of compositional structure. You do not have to know the shape of the dependence; you fit it.
  2. Stop evaluating the density. KDE estimates \(p(x)\) at points, and that is what the curse taxes. Modern generative models never do. A GAN or a flow learns a map from noise to data; a diffusion model learns the score \(\nabla_x \log p(x)\). Learning a map is a supervised-flavoured regression problem, and it dodges the normalising constant entirely.
  3. Exploit the manifold. Real data occupies a thin, curved, low-dimensional subset of its ambient space. That is exactly the singular case of note 05 where the density does not exist — fatal for classical estimation, harmless for a model that only has to produce samples on the manifold.
  4. Amortise. Parameters are shared across all inputs by a single network, so the parameter count grows with model size rather than with \(p^2\).

The two-point model of note 01 is the seed of this: it never wrote down \(p_\text{data}\): it learned the map \(\mathbb{E}[x_0 \mid x_\sigma]\) and integrated.

TipWhat statistics still has that deep learning does not

The honest accounting runs both ways. Ask a diffusion model which genes regulate which and it has no answer — it produces samples, not a graph, and offers no \(p\)-value, no confidence set, no testable conditional independence. The graphical lasso answers exactly that question, with guarantees.

They optimise different objectives. Statistics wanted interpretable, verifiable structure in a regime with almost no data. Deep learning wanted samples that look right, given a great deal of it. Deep learning did not solve the classical problem; it found a version of the problem where the curse of dimensionality is not the binding constraint, and solved that instead.

Knowing which question you are asking is the whole skill.

11. The bridge: from describing to comparing

Every method above tried to write down \(p_\text{data}\) — as a Gaussian, a sparse graphical model, a mixture, a sum of kernels, a posterior. All of them hit the same wall from different sides.

So change the question. And the surprise is that we have already been asking the new one without noticing.

Maximum likelihood was always a comparison. Take the average log-likelihood and let \(n\) grow; by the law of large numbers it converges to an expectation under the true distribution:

\[ \frac1n \sum_{i=1}^{n} \log p_\theta(x_i) \;\xrightarrow[n\to\infty]{}\; \mathbb{E}_{p_\text{data}}\big[\log p_\theta(X)\big]. \]

Now add and subtract \(\mathbb{E}_{p_\text{data}}[\log p_\text{data}(X)]\):

\[ \mathbb{E}_{p_\text{data}}\big[\log p_\theta\big] = \underbrace{-\,H(p_\text{data})}_{\text{does not involve } \theta} \;-\; \mathrm{KL}\big(p_\text{data} \,\|\, p_\theta\big). \]

The entropy term is a constant as far as \(\theta\) is concerned. Therefore

\[ \boxed{\;\arg\max_\theta \ \text{likelihood} \;=\; \arg\min_\theta \ \mathrm{KL}\big(p_\text{data} \,\|\, p_\theta\big).\;} \]

(Check it numerically: over a grid of candidate means, average log-likelihood plus KL is constant to sampling error, and the two optima coincide exactly.)

Fitting was never “describe the data”. It was “get close to the data distribution”. We just never had to name the notion of closeness, because likelihood chose one for us.

Naming it is the pivot, because it exposes a choice we did not know we were making. If “fit” means “make \(p_\theta\) close to \(p_\text{data}\)”, then: close in what sense? And some senses do not require a density at all — which is exactly the escape route, since the density is the thing we cannot get.

Three ways KL specifically fails us.

  1. It needs densities. \(\mathrm{KL}(p\|q) = \int p \log(p/q)\) is meaningless unless both have densities. On a manifold — the situation of §8 and of real image data — \(p_\text{data}\) has no density with respect to Lebesgue measure, and the definition does not apply.
  2. Disjoint supports send it to infinity. If \(p_\theta\) puts no mass where \(p_\text{data}\) lives, \(\mathrm{KL} = \infty\). Two distributions on nearby but non-overlapping manifolds are infinitely far apart no matter how nearly they touch — and infinity has no useful gradient. A model initialised anywhere sensible gets no signal telling it which way to move.
  3. It is asymmetric, and the two orders behave differently: \(\mathrm{KL}(p_\text{data}\|p_\theta)\) is mode-covering and punishes missing mass; \(\mathrm{KL}(p_\theta\|p_\text{data})\) is mode-seeking and punishes spurious mass. Neither is “the” distance.

What we want instead is a comparison that stays finite between distributions with disjoint support, and degrades gracefully as they separate — one that measures how far the mass must move, not whether the supports overlap. That is the Wasserstein distance, and it is the reason WGAN replaced the original GAN objective.

TipWhat the next note does

It turns out the sensible comparisons fall into two families, meeting in almost one place:

  • \(f\)-divergences — KL, reverse KL, Jensen–Shannon, \(\chi^2\), total variation. Built by integrating a convex function of the density ratio, so they all need densities and all suffer failure (1) and (2) above.
  • Integral probability metrics — Wasserstein, MMD, total variation. Built by maximising a difference of expectations over a class of test functions, so they need only the ability to draw samples.

Total variation is the one distribution in both families. Wasserstein is an IPM and is not an \(f\)-divergence — which is precisely why it survives disjoint supports where every \(f\)-divergence saturates.

That is note 07. Once you can measure the gap between two distributions without writing either of them down, you can train a generative model — and the rest of this course is the construction of one particular, very well-behaved way of doing so.

12. Where each piece returns

From this note Where it reappears
\(\ell(\Theta) = \log\det\Theta - \operatorname{tr}(S\Theta)\) the Gaussian KL formula in note 07
Latent variable + marginalise the ELBO, and the diffusion training objective
EM as bound optimisation the variational lower bound of Module 3
Curse of dimensionality why we learn a score instead of a density
Langevin / MCMC with a score Module 4: score matching, and Module 5’s SDEs
\(p_t \to p_\infty\) for a chain the Fokker–Planck equation of Module 5
Proposal as generator, test as discriminator GANs, and why diffusion needs neither
Penalties are log-priors the ELBO’s prior term, read the same way
Manifold / singular covariance why \(p(x)\) is the wrong object for images
“Compare, don’t describe” note 07, and the whole of Modules 3–6

The segue is §11: if estimating \(p_\text{data}\) directly is hopeless, stop describing distributions and start comparing them. That is note 07.

Exercises

  1. Derive \(\hat\mu = \bar x\) from \(\partial\ell/\partial\mu = 0\), and confirm it does not depend on \(\Sigma\).
  2. Verify the trace trick line by line for \(n=2\), \(p=2\).
  3. Show \(\operatorname{rank}(S) \le n-1\). (Hint: the centred vectors satisfy one linear constraint.)
  4. For the AR(1) example of §3, invert \(\Sigma\) by hand and confirm \(\Theta_{13} = 0\). Then compute \(\operatorname{Cov}(X_1,X_3 \mid X_2)\) from the block formula of note 05 and check the two agree.
  5. Construct a \(3\times3\) correlation matrix whose marginal correlations are all non-zero but whose precision matrix has a zero. What does the graph look like?
  6. Show the Gaussian mixture likelihood is unbounded: exhibit a parameter sequence sending it to \(+\infty\). Why does this not happen with a single Gaussian?
  7. Show \(k\)-means is EM for a mixture with \(\Sigma_k = \sigma^2 I\) in the limit \(\sigma \to 0\).
  8. Using MISE \(\asymp n^{-4/(p+4)}\), find the \(n\) needed at \(p = 30\) to match the accuracy of \(n = 1000\) at \(p = 2\). Comment.
  9. Show that the inverse-Wishart posterior scale \(\Psi + nS\) is positive definite whenever \(\Psi\) is, even if \(S\) is singular. What is the Bayesian analogue of “the penalty repaired the rank deficiency”?
  10. Show the graphical lasso is the MAP estimate under a Laplace prior on the off-diagonal entries of \(\Theta\). What prior gives ridge?
  11. Prove \(\arg\max_\theta \mathbb{E}[\log p_\theta] = \arg\min_\theta \mathrm{KL}(p_\text{data}\|p_\theta)\), and say exactly where you used that the entropy does not depend on \(\theta\).
  12. Let \(p = \delta_0\) and \(q = \delta_\varepsilon\) be point masses. Compute \(\mathrm{KL}(p\|q)\) and the Wasserstein-1 distance as \(\varepsilon \to 0\). Which one is useful for gradient descent, and why?
  13. Write the Langevin update for \(p = \mathcal{N}(\mu,\sigma^2)\) explicitly. Confirm the normalising constant never appears.
  14. Prove that accepted draws in rejection sampling have law exactly \(p\). (Hint: \((x, uMq(x))\) is uniform under the envelope.)
  15. Show that for target \(\mathcal{N}(0,I_d)\) and proposal \(\mathcal{N}(0,\sigma^2 I_d)\) with \(\sigma>1\), the smallest valid constant is \(M = \sigma^{d}\). At what \(d\) does \(\sigma = 1.2\) become unusable?
  16. Explain why \(\mathcal{N}(0,1)\) cannot be a rejection proposal for \(\mathcal{N}(-1,1)\), and give one that can.
  17. For Gibbs on the bivariate normal, derive \(x_t \mid x_0 \sim \mathcal{N}(\rho^{2t}x_0, 1-\rho^{4t})\) and the lag-1 autocorrelation \(\rho^2\).
  18. Show the optimal GAN discriminator is \(r/(1+r)\) with \(r = p_\text{data}/p_g\), and say what rejection sampling knows about \(r\) that a GAN does not.
  19. A \(p=50\) dataset has \(n=40\) samples. Which estimator from §4 would you choose and why? What scientific claim does your choice commit you to?