Blog · updated 29 Oct 2026 · 39 min read

Generative models, one map: what each family can compute

The opener of a series that ends at one-step generators. What it means to learn a distribution; maximum likelihood as a KL divergence; change of variables and normalising flows; VAEs; GANs and their divergences, including MMD; energy-based models, the score and Langevin dynamics; autoregressive models. Every result derived step by step, and a flow, a VAE and a GAN trained on the same data to show how each one fails.

Contents
  1. Notation
  2. 1. What it means to learn a distribution
  3. Three things a model can be asked to do
  4. Maximum likelihood is a KL divergence
  5. Forward and reverse KL make different mistakes
  6. When the model cannot be evaluated
  7. 2. Pushing noise forward: change of variables
  8. 3. Normalising flows: exact likelihood, invertible maps
  9. 4. Latent variables and VAEs
  10. 5. GANs: learning a sampler with a classifier
  11. Divergences that see distance: Wasserstein and MMD
  12. 6. Energy-based models and the score
  13. 7. Autoregressive models
  14. 8. Same data, three families
  15. 9. The map, and where this series goes
  16. Questions
  17. References

A generative model turns noise into data. Below, Gaussian noise on the left is pushed through an invertible map into the plane on the right. Slide tt from 0 to 1 to apply the map, and hover over the right panel to see the density at a point computed from the formula this post derives:

What to try. At t=0t = 0 the map is the identity and the two panels agree. As tt grows, the grid on the right is stretched outwards, swirled and bent, and the two colours let you follow the upper and lower halves of the noise. The heat map is the density of x\boldsymbol{x}, computed from the change-of-variables formula: it stays high where the grid cells stay small and thins out where they grow. At the circled point, log⁡pz=−2.85\log p_{\boldsymbol{z}} = -2.85 and the map expands area there by e0.84≈2.3e^{0.84} \approx 2.3, so log⁡px=−2.85−0.84=−3.69\log p_{\boldsymbol{x}} = -2.85 - 0.84 = -3.69. Hover elsewhere to see the same bookkeeping.

This is the first post of a series on deep generative models: this map, then diffusion models, flow matching, and finally the one-step generators that are the newest part of the field. Each later post builds on what is set up here, so this one answers the questions that the others take for granted:

  1. What does it mean to learn a distribution, and how do you measure success when all you have is samples? (Section 1.)
  2. What can each family compute, a density, samples or the score, and at what cost? (Sections 2 to 7.)
  3. Why does each family fail the way it does? I trained a flow, a VAE and a GAN on the same data to show it. (Section 8.)
  4. Where do diffusion, flow matching and one-step generators fit? (Section 9.)

Every result has a folded proof in numbered steps. The shared example of the series is a ring of eight Gaussians in the plane, simple enough to see everything and hard enough that every family gets something wrong.

Notation

Plain italic letters are scalars, bold italic lower case are vectors, bold upright capitals are matrices.

SymbolMeaning
x∈Rd\boldsymbol{x} \in \mathbb{R}^d, pdatap_{\mathrm{data}}a data point and the data distribution
z∈Rk\boldsymbol{z} \in \mathbb{R}^k, p(z)p(\boldsymbol{z})noise or a latent variable, usually N(0,I)\mathcal{N}(\mathbf{0}, \mathbf{I})
pθp_\thetathe model distribution, with parameters θ\theta
ff, GθG_\thetaan invertible map (flow); a generator (sampler)
Jf(z)=∂f/∂z\mathbf{J}_f(\boldsymbol{z}) = \partial f/\partial\boldsymbol{z}the Jacobian matrix of ff
qϕ(z∣x)q_\phi(\boldsymbol{z} \mid \boldsymbol{x})an encoder: an approximate posterior over z\boldsymbol{z}
D(x)D(\boldsymbol{x})a GAN discriminator
Eθ(x)E_\theta(\boldsymbol{x}), ZθZ_\thetaan energy and its normalising constant
s(x)=∇xlog⁡p(x)\boldsymbol{s}(\boldsymbol{x}) = \nabla_{\boldsymbol{x}}\log p(\boldsymbol{x})the score
KL\mathrm{KL}, JS\mathrm{JS}, MMDk\mathrm{MMD}_kKullback–Leibler, Jensen–Shannon, maximum mean discrepancy

Later posts add time: t∈[0,1]t \in [0, 1] with data at t=0t = 0 and noise at t=1t = 1, a score s(x,t)\boldsymbol{s}(\boldsymbol{x}, t) and a velocity v(x,t)\boldsymbol{v}(\boldsymbol{x}, t).

1. What it means to learn a distribution

Three things a model can be asked to do

We have samples x1,…,xN\boldsymbol{x}_1, \dots, \boldsymbol{x}_N from an unknown pdatap_{\mathrm{data}}, and nothing else. A model pθp_\theta can be asked for three different things:

  • Sample: produce new x∼pθ\boldsymbol{x} \sim p_\theta. Image and audio generation need only this.
  • Evaluate: compute pθ(x)p_\theta(\boldsymbol{x}) at a given point. Compression, anomaly detection and model comparison need this.
  • Score: compute ∇xlog⁡pθ(x)\nabla_{\boldsymbol{x}}\log p_\theta(\boldsymbol{x}), the direction in which the density grows fastest. Diffusion models are built on it.

No family does all three cheaply. That single fact organises the whole field, and this post.

Maximum likelihood is a KL divergence

The standard way to fit pθp_\theta is to maximise the average log-likelihood of the data. It has a precise meaning.

Definition 1 (Kullback–Leibler divergence)

KL[p ∥ q]=Ex∼p[log⁡p(x)−log⁡q(x)]\mathrm{KL}[p \,\Vert\, q] = \mathbb{E}_{\boldsymbol{x} \sim p}\big[\log p(\boldsymbol{x}) - \log q(\boldsymbol{x})\big]. It is non-negative and zero only when p=qp = q (Gibbs’ inequality, proved in the sparse GP post, Section 2).

Proposition 1 (Maximum likelihood minimises the forward KL)

arg⁡max⁡θ Ex∼pdata[log⁡pθ(x)]=arg⁡min⁡θ KL[pdata ∥ pθ],\arg\max_\theta\ \mathbb{E}_{\boldsymbol{x} \sim p_{\mathrm{data}}}\big[\log p_\theta(\boldsymbol{x})\big] = \arg\min_\theta\ \mathrm{KL}\big[p_{\mathrm{data}} \,\Vert\, p_\theta\big],

and the average 1N∑nlog⁡pθ(xn)\frac1N\sum_n\log p_\theta(\boldsymbol{x}_n) is an unbiased estimate of the expectation on the left.

Proof

Step 1. Expand the KL. KL[pdata ∥ pθ]=Epdata[log⁡pdata(x)]−Epdata[log⁡pθ(x)]\mathrm{KL}[p_{\mathrm{data}} \,\Vert\, p_\theta] = \mathbb{E}_{p_{\mathrm{data}}}[\log p_{\mathrm{data}}(\boldsymbol{x})] - \mathbb{E}_{p_{\mathrm{data}}}[\log p_\theta(\boldsymbol{x})].

Step 2. The first term does not depend on θ\theta. It is minus the entropy of the data, a constant. So minimising the KL over θ\theta is the same as maximising the second expectation.

Step 3. The sample average. Each xn\boldsymbol{x}_n is drawn from pdatap_{\mathrm{data}}, so E[log⁡pθ(xn)]\mathbb{E}[\log p_\theta(\boldsymbol{x}_n)] equals the expectation, and so does the expectation of their average.

Two consequences matter for everything that follows. Maximum likelihood needs log⁡pθ(x)\log p_\theta(\boldsymbol{x}), so it needs a model that can evaluate. And it minimises the KL in one particular direction, which decides what kind of mistakes the model prefers.

Forward and reverse KL make different mistakes

KL[p ∥ q]\mathrm{KL}[p \,\Vert\, q] averages over pp. Wherever the data have mass and the model qq has almost none, log⁡(p/q)\log(p/q) is huge, so the fit spreads qq over all the data, even where that means putting mass between modes. The reverse divergence KL[q ∥ p]\mathrm{KL}[q \,\Vert\, p] averages over the model instead: it punishes the model for putting mass where the data have none, so it prefers to sit inside one mode. Fit a single Gaussian qq to two modes and watch both:

With the modes close together (separation ±1\pm1), both fits are almost the same wide Gaussian. Pull them apart. At ±2\pm2 the maximum-likelihood fit has mean −0.40-0.40 and standard deviation 2.022.02: it covers both modes, and puts most of its mass in the empty middle. The reverse-KL fit sits exactly on the larger mode (mean −2.00-2.00, standard deviation 0.500.50) and ignores the other one.

Proposition 2 (The forward-KL Gaussian matches moments)

Among Gaussians q=N(μ,σ2)q = \mathcal{N}(\mu, \sigma^2), KL[p ∥ q]\mathrm{KL}[p \,\Vert\, q] is minimised by the mean and variance of pp: μ=Ep[x]\mu = \mathbb{E}_p[x] and σ2=Var⁡p[x]\sigma^2 = \operatorname{Var}_p[x].

Proof

Step 1. Only the cross term depends on qq. KL[p ∥ q]=const−Ep[log⁡q(x)]\mathrm{KL}[p \,\Vert\, q] = \text{const} - \mathbb{E}_p[\log q(x)].

Step 2. Write out the Gaussian log-density. −Ep[log⁡q(x)]=12log⁡(2πσ2)+Ep[(x−μ)2]2σ2-\mathbb{E}_p[\log q(x)] = \tfrac12\log(2\pi\sigma^2) + \frac{\mathbb{E}_p[(x - \mu)^2]}{2\sigma^2}.

Step 3. Split the square. With m=Ep[x]m = \mathbb{E}_p[x] and v=Var⁡p[x]v = \operatorname{Var}_p[x], Ep[(x−μ)2]=v+(m−μ)2\mathbb{E}_p[(x - \mu)^2] = v + (m - \mu)^2, because the cross term 2(m−μ)Ep[x−m]2(m - \mu)\mathbb{E}_p[x - m] is zero.

Step 4. Minimise over μ\mu. Only (m−μ)2(m - \mu)^2 depends on μ\mu, so μ=m\mu = m.

Step 5. Minimise over σ2\sigma^2. The objective is now 12log⁡(2πσ2)+v/(2σ2)\tfrac12\log(2\pi\sigma^2) + v/(2\sigma^2). Its derivative in σ2\sigma^2 is 12σ2−v2σ4\frac{1}{2\sigma^2} - \frac{v}{2\sigma^4}, which is zero at σ2=v\sigma^2 = v, and the second derivative there is 12v2>0\frac{1}{2v^2} > 0.

This is the root of a theme that runs through the series. Likelihood-based models (flows, VAEs, and diffusion models, whose training is a bound on the likelihood) are mass-covering: they rarely drop a mode, but they can put mass where there are no data. Models trained by other divergences can be mode-seeking: sharp, but liable to miss modes.

When the model cannot be evaluated

If the model is only a sampler, log⁡pθ\log p_\theta is unavailable and maximum likelihood is impossible. Then the two distributions must be compared from samples alone. Three ways are standard, and Section 5 derives them: train a classifier to tell them apart (the Jensen–Shannon divergence of GANs), measure how far mass must move (the Wasserstein distance), or compare averages of kernel features (the maximum mean discrepancy).

2. Pushing noise forward: change of variables

The simplest way to build a sampler is to transform noise: draw z∼p(z)\boldsymbol{z} \sim p(\boldsymbol{z}) and set x=f(z)\boldsymbol{x} = f(\boldsymbol{z}). The distribution of x\boldsymbol{x} is the pushforward of p(z)p(\boldsymbol{z}) through ff. Sampling is one evaluation of ff. Evaluating the density of x\boldsymbol{x} is possible when ff is invertible, and the formula is the most-used identity in generative modelling.

Theorem 1 (Change of variables in one dimension)

Let ff be differentiable and strictly increasing, and x=f(z)x = f(z). Then

px(x)=pz(f−1(x))f′(f−1(x)).p_x(x) = \frac{p_z\big(f^{-1}(x)\big)}{f'\big(f^{-1}(x)\big)}.

For strictly decreasing ff, replace f′f' by ∣f′∣\lvert f'\rvert.

Proof

Step 1. The CDF. For increasing ff, x≤ax \le a exactly when z≤f−1(a)z \le f^{-1}(a). So P(x≤a)=P(z≤f−1(a))=Fz(f−1(a))P(x \le a) = P\big(z \le f^{-1}(a)\big) = F_z\big(f^{-1}(a)\big), with FzF_z the CDF of zz.

Step 2. Differentiate in aa. The density is the derivative of the CDF. By the chain rule, px(a)=pz(f−1(a))⋅ddaf−1(a)p_x(a) = p_z\big(f^{-1}(a)\big)\cdot\frac{d}{da}f^{-1}(a).

Step 3. The derivative of the inverse. Differentiating f(f−1(a))=af(f^{-1}(a)) = a gives f′(f−1(a))⋅ddaf−1(a)=1f'\big(f^{-1}(a)\big)\cdot\frac{d}{da}f^{-1}(a) = 1.

Step 4. Decreasing ff. Then x≤ax \le a exactly when z≥f−1(a)z \ge f^{-1}(a), so P(x≤a)=1−Fz(f−1(a))P(x \le a) = 1 - F_z(f^{-1}(a)). Differentiating gives the same formula with −f′=∣f′∣-f' = \lvert f'\rvert.

Where ff is steep, an interval of zz is stretched over a long interval of xx, so the same probability is spread thinner, and the density falls. Where ff is flat, it piles up. In more dimensions, “steepness” becomes the factor by which ff changes volume, which is the absolute determinant of its Jacobian.

Theorem 2 (Change of variables)

Let f:Rd→Rdf : \mathbb{R}^d \to \mathbb{R}^d be invertible and differentiable with a differentiable inverse, and x=f(z)\boldsymbol{x} = f(\boldsymbol{z}). Then

px(x)=pz(z) ∣det⁡Jf(z)∣−1,z=f−1(x),p_{\boldsymbol{x}}(\boldsymbol{x}) = p_{\boldsymbol{z}}(\boldsymbol{z})\,\big\lvert\det\mathbf{J}_f(\boldsymbol{z})\big\rvert^{-1}, \qquad \boldsymbol{z} = f^{-1}(\boldsymbol{x}),

or, in logs, log⁡px(x)=log⁡pz(z)−log⁡∣det⁡Jf(z)∣\log p_{\boldsymbol{x}}(\boldsymbol{x}) = \log p_{\boldsymbol{z}}(\boldsymbol{z}) - \log\big\lvert\det\mathbf{J}_f(\boldsymbol{z})\big\rvert.

Proof

Step 1. Probabilities of sets. For any region AA, x∈A\boldsymbol{x} \in A exactly when z∈f−1(A)\boldsymbol{z} \in f^{-1}(A), so P(x∈A)=∫f−1(A)pz(z) dzP(\boldsymbol{x} \in A) = \int_{f^{-1}(A)}p_{\boldsymbol{z}}(\boldsymbol{z})\,d\boldsymbol{z}.

Step 2. Substitute z=f−1(x)\boldsymbol{z} = f^{-1}(\boldsymbol{x}). The multivariate substitution rule of calculus says ∫f−1(A)h(z) dz=∫Ah(f−1(x)) ∣det⁡Jf−1(x)∣ dx\int_{f^{-1}(A)}h(\boldsymbol{z})\,d\boldsymbol{z} = \int_A h\big(f^{-1}(\boldsymbol{x})\big)\,\big\lvert\det\mathbf{J}_{f^{-1}}(\boldsymbol{x})\big\rvert\,d\boldsymbol{x}. So P(x∈A)=∫Apz(f−1(x)) ∣det⁡Jf−1(x)∣ dxP(\boldsymbol{x} \in A) = \int_A p_{\boldsymbol{z}}(f^{-1}(\boldsymbol{x}))\,\lvert\det\mathbf{J}_{f^{-1}}(\boldsymbol{x})\rvert\,d\boldsymbol{x}.

Step 3. Read off the density. This holds for every region AA, so the integrand is the density of x\boldsymbol{x}.

Step 4. Jacobian of the inverse. Differentiating f(f−1(x))=xf(f^{-1}(\boldsymbol{x})) = \boldsymbol{x} with the chain rule gives Jf(z) Jf−1(x)=I\mathbf{J}_f(\boldsymbol{z})\,\mathbf{J}_{f^{-1}}(\boldsymbol{x}) = \mathbf{I}, so Jf−1(x)=Jf(z)−1\mathbf{J}_{f^{-1}}(\boldsymbol{x}) = \mathbf{J}_f(\boldsymbol{z})^{-1} and det⁡Jf−1=1/det⁡Jf\det\mathbf{J}_{f^{-1}} = 1/\det\mathbf{J}_f.

Corollary 1 (Compositions add their log-determinants)

For f=fK∘⋯∘f1f = f_K \circ \dots \circ f_1 with z0=z\boldsymbol{z}_0 = \boldsymbol{z} and zk=fk(zk−1)\boldsymbol{z}_k = f_k(\boldsymbol{z}_{k-1}),

log⁡px(x)=log⁡pz(z0)−∑k=1Klog⁡∣det⁡Jfk(zk−1)∣.\log p_{\boldsymbol{x}}(\boldsymbol{x}) = \log p_{\boldsymbol{z}}(\boldsymbol{z}_0) - \sum_{k=1}^{K}\log\big\lvert\det\mathbf{J}_{f_k}(\boldsymbol{z}_{k-1})\big\rvert.
Proof

Step 1. Chain rule. Jf(z)=JfK(zK−1)⋯Jf1(z0)\mathbf{J}_f(\boldsymbol{z}) = \mathbf{J}_{f_K}(\boldsymbol{z}_{K-1})\cdots\mathbf{J}_{f_1}(\boldsymbol{z}_0).

Step 2. Determinants multiply. det⁡(AB)=det⁡Adet⁡B\det(\mathbf{A}\mathbf{B}) = \det\mathbf{A}\det\mathbf{B}, so the log of the absolute determinant of the product is the sum of the logs. Substitute into the theorem.

The figure at the top is this formula, live. The map there is a radial stretch, a swirl and a shear. The swirl and the shear preserve area (determinant 1), so the density changes only through the stretch. The formula’s readout is exact, and the heat map on the right is computed from it; I checked that it integrates to 1 and that the log-determinant matches a numerical Jacobian to ten decimal places.

3. Normalising flows: exact likelihood, invertible maps

A normalising flow makes the invertible map learnable: x=fθ(z)\boldsymbol{x} = f_\theta(\boldsymbol{z}) with fθ=fK∘⋯∘f1f_\theta = f_K \circ \dots \circ f_1, each fkf_k a small invertible network. The corollary gives log⁡pθ(x)\log p_\theta(\boldsymbol{x}) exactly, so the flow trains by maximum likelihood and samples in one pass (Rezende and Mohamed, 2015; Dinh, Sohl-Dickstein and Bengio, 2017).

The difficulty is cost. The determinant of a general d×dd \times d Jacobian costs O(d3)O(d^3), and for an image dd is in the hundreds of thousands. So flows are built from layers whose Jacobians are triangular, whose determinant is the product of the diagonal.

Proposition 3 (The affine coupling layer)

Split x=(xa,xb)\boldsymbol{x} = (\boldsymbol{x}_a, \boldsymbol{x}_b) and let s(⋅)\boldsymbol{s}(\cdot) and t(⋅)\boldsymbol{t}(\cdot) be any networks. The map

ya=xa,yb=xb⊙es(xa)+t(xa)\boldsymbol{y}_a = \boldsymbol{x}_a, \qquad \boldsymbol{y}_b = \boldsymbol{x}_b \odot e^{\boldsymbol{s}(\boldsymbol{x}_a)} + \boldsymbol{t}(\boldsymbol{x}_a)

is invertible in closed form, and log⁡∣det⁡J∣=∑isi(xa)\log\lvert\det\mathbf{J}\rvert = \sum_i s_i(\boldsymbol{x}_a), at cost O(d)O(d).

Proof

Step 1. The inverse. xa=ya\boldsymbol{x}_a = \boldsymbol{y}_a, and then xb=(yb−t(ya))⊙e−s(ya)\boldsymbol{x}_b = \big(\boldsymbol{y}_b - \boldsymbol{t}(\boldsymbol{y}_a)\big)\odot e^{-\boldsymbol{s}(\boldsymbol{y}_a)}. Nothing needs inverting except an exponential, because s\boldsymbol{s} and t\boldsymbol{t} are only ever evaluated at xa\boldsymbol{x}_a, which is known.

Step 2. The Jacobian’s blocks. ∂ya/∂xa=I\partial\boldsymbol{y}_a/\partial\boldsymbol{x}_a = \mathbf{I} and ∂ya/∂xb=0\partial\boldsymbol{y}_a/\partial\boldsymbol{x}_b = \mathbf{0}. ∂yb/∂xb=diag⁡(es(xa))\partial\boldsymbol{y}_b/\partial\boldsymbol{x}_b = \operatorname{diag}(e^{\boldsymbol{s}(\boldsymbol{x}_a)}). The block ∂yb/∂xa\partial\boldsymbol{y}_b/\partial\boldsymbol{x}_a is complicated, but it sits below the diagonal.

Step 3. The determinant. The Jacobian is block lower-triangular, so its determinant is the product of the diagonal blocks’ determinants: 1⋅∏iesi=e∑isi1 \cdot \prod_ie^{s_i} = e^{\sum_is_i}.

Step 4. Stacking. One layer leaves xa\boldsymbol{x}_a unchanged, so consecutive layers swap the roles of the two halves.

Flows have one limitation that no amount of training removes.

Proposition 4 (A flow cannot separate modes)

If ff is continuous and z\boldsymbol{z} has a positive density on all of Rd\mathbb{R}^d, then the flow’s density is positive on the connected set f(Rd)f(\mathbb{R}^d). If the data’s modes are separated by regions of zero density, the flow must still put positive density on paths between them.

Proof

Step 1. The support. px(x)=pz(f−1(x))∣det⁡Jf∣−1>0p_{\boldsymbol{x}}(\boldsymbol{x}) = p_{\boldsymbol{z}}(f^{-1}(\boldsymbol{x}))\lvert\det\mathbf{J}_f\rvert^{-1} > 0 for every x\boldsymbol{x} in the image f(Rd)f(\mathbb{R}^d), since both factors are positive.

Step 2. The image is connected. Rd\mathbb{R}^d is connected, and the continuous image of a connected set is connected.

Step 3. Conclusion. Any two modes lie in one connected set on which the density is positive, so there is a path between them along which the density never vanishes.

On the ring of eight Gaussians (Section 8) the trained flow does exactly this: it draws thin bridges from mode to mode, and a quarter of its samples land on them. Continuous-time flows, which define ff by an ordinary differential equation x˙=v(x,t)\dot{\boldsymbol{x}} = \boldsymbol{v}(\boldsymbol{x}, t), share the limitation, and they are the starting point of the flow-matching post.

4. Latent variables and VAEs

A latent-variable model does not need ff to be invertible. It draws a latent z∼p(z)\boldsymbol{z} \sim p(\boldsymbol{z}) and then x\boldsymbol{x} from a decoder pθ(x∣z)p_\theta(\boldsymbol{x} \mid \boldsymbol{z}), for example N(x∣NNθ(z),σx2I)\mathcal{N}(\boldsymbol{x} \mid \mathrm{NN}_\theta(\boldsymbol{z}), \sigma_x^2\mathbf{I}). Sampling is easy, but the likelihood

pθ(x)=∫pθ(x∣z) p(z) dzp_\theta(\boldsymbol{x}) = \int p_\theta(\boldsymbol{x} \mid \boldsymbol{z})\,p(\boldsymbol{z})\,d\boldsymbol{z}

has no closed form once the decoder is a neural network. Variational inference supplies a bound. The sparse GP post, Section 2, derives it in general; here it is for one data point.

Proposition 5 (The VAE bound (Kingma and Welling, 2014; Rezende, Mohamed and Wierstra, 2014))

For any distribution qϕ(z∣x)q_\phi(\boldsymbol{z} \mid \boldsymbol{x}),

log⁡pθ(x)=Eqϕ(z∣x)[log⁡pθ(x∣z)]−KL[qϕ(z∣x) ∥ p(z)]⏟ELBO+KL[qϕ(z∣x) ∥ pθ(z∣x)].\log p_\theta(\boldsymbol{x}) = \underbrace{\mathbb{E}_{q_\phi(\boldsymbol{z} \mid \boldsymbol{x})}\big[\log p_\theta(\boldsymbol{x} \mid \boldsymbol{z})\big] - \mathrm{KL}\big[q_\phi(\boldsymbol{z} \mid \boldsymbol{x}) \,\Vert\, p(\boldsymbol{z})\big]}_{\text{ELBO}} + \mathrm{KL}\big[q_\phi(\boldsymbol{z} \mid \boldsymbol{x}) \,\Vert\, p_\theta(\boldsymbol{z} \mid \boldsymbol{x})\big].
Proof

Step 1. Bayes’ rule, pointwise in z\boldsymbol{z}. log⁡pθ(x)=log⁡pθ(x∣z)+log⁡p(z)−log⁡pθ(z∣x)\log p_\theta(\boldsymbol{x}) = \log p_\theta(\boldsymbol{x} \mid \boldsymbol{z}) + \log p(\boldsymbol{z}) - \log p_\theta(\boldsymbol{z} \mid \boldsymbol{x}).

Step 2. Add and subtract log⁡qϕ(z∣x)\log q_\phi(\boldsymbol{z} \mid \boldsymbol{x}) and group:

log⁡pθ(x)=log⁡pθ(x∣z)−log⁡qϕ(z∣x)p(z)+log⁡qϕ(z∣x)pθ(z∣x).\log p_\theta(\boldsymbol{x}) = \log p_\theta(\boldsymbol{x} \mid \boldsymbol{z}) - \log\frac{q_\phi(\boldsymbol{z} \mid \boldsymbol{x})}{p(\boldsymbol{z})} + \log\frac{q_\phi(\boldsymbol{z} \mid \boldsymbol{x})}{p_\theta(\boldsymbol{z} \mid \boldsymbol{x})}.

Step 3. Average over qϕq_\phi. The left side does not depend on z\boldsymbol{z}. The three averages on the right are the reconstruction term and the two KL divergences.

The last KL is non-negative, so the ELBO is a lower bound, and maximising it over ϕ\phi makes the encoder approximate the true posterior. Two choices make it trainable at scale. The encoder is amortised: one network outputs qϕ(z∣x)=N(μϕ(x),diag⁡σϕ2(x))q_\phi(\boldsymbol{z} \mid \boldsymbol{x}) = \mathcal{N}\big(\boldsymbol{\mu}_\phi(\boldsymbol{x}), \operatorname{diag}\boldsymbol{\sigma}^2_\phi(\boldsymbol{x})\big) for every x\boldsymbol{x}, instead of separate parameters per data point. And the expectation is estimated by reparameterisation, z=μϕ+σϕ⊙ε\boldsymbol{z} = \boldsymbol{\mu}_\phi + \boldsymbol{\sigma}_\phi \odot \boldsymbol{\varepsilon}, proved in the deep GP post, Section 5. The KL term is in closed form:

Proposition 6 (KL to a standard Gaussian)

KL[N(μ,diag⁡σ2) ∥ N(0,I)]=12∑j=1k(μj2+σj2−1−log⁡σj2).\mathrm{KL}\big[\mathcal{N}(\boldsymbol{\mu}, \operatorname{diag}\boldsymbol{\sigma}^2) \,\Vert\, \mathcal{N}(\mathbf{0}, \mathbf{I})\big] = \tfrac12\sum_{j=1}^{k}\big(\mu_j^2 + \sigma_j^2 - 1 - \log\sigma_j^2\big).
Proof

Step 1. The general formula for KL[N(m,S) ∥ N(μ0,Σ0)]\mathrm{KL}[\mathcal{N}(\boldsymbol{m}, \mathbf{S}) \,\Vert\, \mathcal{N}(\boldsymbol{\mu}_0, \boldsymbol{\Sigma}_0)] is 12[tr⁡(Σ0−1S)+(μ0−m)⊤Σ0−1(μ0−m)−k+log⁡∣Σ0∣−log⁡∣S∣]\tfrac12\big[\operatorname{tr}(\boldsymbol{\Sigma}_0^{-1}\mathbf{S}) + (\boldsymbol{\mu}_0 - \boldsymbol{m})^\top\boldsymbol{\Sigma}_0^{-1}(\boldsymbol{\mu}_0 - \boldsymbol{m}) - k + \log\lvert\boldsymbol{\Sigma}_0\rvert - \log\lvert\mathbf{S}\rvert\big] (proved in the Gaussian toolkit).

Step 2. Substitute Σ0=I\boldsymbol{\Sigma}_0 = \mathbf{I}, μ0=0\boldsymbol{\mu}_0 = \mathbf{0}, m=μ\boldsymbol{m} = \boldsymbol{\mu}, S=diag⁡σ2\mathbf{S} = \operatorname{diag}\boldsymbol{\sigma}^2: the trace is ∑jσj2\sum_j\sigma_j^2, the quadratic form is ∑jμj2\sum_j\mu_j^2, log⁡∣I∣=0\log\lvert\mathbf{I}\rvert = 0 and log⁡∣S∣=∑jlog⁡σj2\log\lvert\mathbf{S}\rvert = \sum_j\log\sigma_j^2.

Why VAE samples look the way they do follows from the model, not from bad training:

  • The decoder adds isotropic noise. A sample is the decoder mean plus σxε\sigma_x\boldsymbol{\varepsilon}, which blurs every output by the same amount in every direction.
  • The prior has holes. The encoder maps the data to a set of codes, but the prior N(0,I)\mathcal{N}(\mathbf{0}, \mathbf{I}) also covers codes that no data point maps to. Those decode to points between the modes.
  • The bound has a gap. Training maximises the ELBO, not the likelihood, and a decoder that ignores z\boldsymbol{z} can make the KL term zero. When this posterior collapse happens, the model explains the data as noise.

5. GANs: learning a sampler with a classifier

A generative adversarial network (Goodfellow et al., 2014) keeps only the sampler, x=Gθ(z)\boldsymbol{x} = G_\theta(\boldsymbol{z}), with no density at all. To compare its samples with the data, it trains a classifier D(x)∈(0,1)D(\boldsymbol{x}) \in (0, 1) to tell real from generated, and trains GG to fool it:

min⁡Gmax⁡D V(G,D)=Epdata[log⁡D(x)]+Ez[log⁡(1−D(G(z)))].\min_G\max_D\ V(G, D) = \mathbb{E}_{p_{\mathrm{data}}}\big[\log D(\boldsymbol{x})\big] + \mathbb{E}_{\boldsymbol{z}}\big[\log\big(1 - D(G(\boldsymbol{z}))\big)\big].

What is the generator really minimising? Write pgp_g for the distribution of G(z)G(\boldsymbol{z}).

Proposition 7 (The optimal discriminator)

For fixed GG, VV is maximised by D∗(x)=pdata(x)pdata(x)+pg(x)D^*(\boldsymbol{x}) = \dfrac{p_{\mathrm{data}}(\boldsymbol{x})}{p_{\mathrm{data}}(\boldsymbol{x}) + p_g(\boldsymbol{x})}.

Proof

Step 1. One integral. V=∫[pdata(x)log⁡D(x)+pg(x)log⁡(1−D(x))] dxV = \int\big[p_{\mathrm{data}}(\boldsymbol{x})\log D(\boldsymbol{x}) + p_g(\boldsymbol{x})\log(1 - D(\boldsymbol{x}))\big]\,d\boldsymbol{x}, writing the second expectation over x=G(z)\boldsymbol{x} = G(\boldsymbol{z}).

Step 2. Maximise pointwise. DD can be chosen separately at each x\boldsymbol{x}, so maximise alog⁡y+blog⁡(1−y)a\log y + b\log(1 - y) over y∈(0,1)y \in (0, 1), with a=pdata(x)a = p_{\mathrm{data}}(\boldsymbol{x}) and b=pg(x)b = p_g(\boldsymbol{x}).

Step 3. Set the derivative to zero. a/y−b/(1−y)=0a/y - b/(1 - y) = 0 gives y=a/(a+b)y = a/(a + b). The second derivative, −a/y2−b/(1−y)2-a/y^2 - b/(1 - y)^2, is negative, so it is a maximum.

Proposition 8 (GANs minimise the Jensen–Shannon divergence)

At the optimal discriminator, V(G,D∗)=2 JS(pdata,pg)−log⁡4V(G, D^*) = 2\,\mathrm{JS}(p_{\mathrm{data}}, p_g) - \log 4, where JS(p,q)=12KL[p ∥ m]+12KL[q ∥ m]\mathrm{JS}(p, q) = \tfrac12\mathrm{KL}[p \,\Vert\, m] + \tfrac12\mathrm{KL}[q \,\Vert\, m] with m=12(p+q)m = \tfrac12(p + q).

Proof

Step 1. Substitute D∗D^*.

V(G,D∗)=Epdata[log⁡pdatapdata+pg]+Epg[log⁡pgpdata+pg].V(G, D^*) = \mathbb{E}_{p_{\mathrm{data}}}\Big[\log\frac{p_{\mathrm{data}}}{p_{\mathrm{data}} + p_g}\Big] + \mathbb{E}_{p_g}\Big[\log\frac{p_g}{p_{\mathrm{data}} + p_g}\Big].

Step 2. Bring in the mixture mm. pdata+pg=2mp_{\mathrm{data}} + p_g = 2m, so each logarithm is log⁡(p/m)−log⁡2\log(p/m) - \log 2.

Step 3. Recognise the KLs. V=KL[pdata ∥ m]−log⁡2+KL[pg ∥ m]−log⁡2=2 JS−log⁡4V = \mathrm{KL}[p_{\mathrm{data}} \,\Vert\, m] - \log 2 + \mathrm{KL}[p_g \,\Vert\, m] - \log 2 = 2\,\mathrm{JS} - \log 4.

So the ideal generator minimises the Jensen–Shannon divergence, which is zero only when pg=pdatap_g = p_{\mathrm{data}}. In practice the ideal is far away, for two reasons:

Proposition 9 (No gradient when the supports are disjoint)

If pdatap_{\mathrm{data}} and pgp_g are positive on disjoint sets, then JS(pdata,pg)=log⁡2\mathrm{JS}(p_{\mathrm{data}}, p_g) = \log 2, however close or far apart the sets are.

Proof

Step 1. On the support of pdatap_{\mathrm{data}}, pg=0p_g = 0, so m=pdata/2m = p_{\mathrm{data}}/2 and log⁡(pdata/m)=log⁡2\log(p_{\mathrm{data}}/m) = \log 2. Hence KL[pdata ∥ m]=log⁡2\mathrm{KL}[p_{\mathrm{data}} \,\Vert\, m] = \log 2.

Step 2. Symmetrically, KL[pg ∥ m]=log⁡2\mathrm{KL}[p_g \,\Vert\, m] = \log 2, so JS=12(log⁡2+log⁡2)=log⁡2\mathrm{JS} = \tfrac12(\log 2 + \log 2) = \log 2.

Step 3. Consequence. Moving pgp_g a little closer to the data, without overlapping it, does not change the divergence: its gradient is zero. Early in training, and for data on thin sets such as images, this is the usual situation.

The second reason is mode collapse: the generator can fool the current discriminator by producing a few convincing kinds of sample, then move on when the discriminator catches up. Its behaviour resembles the reverse KL of Section 1, sharp and mode-seeking.

Divergences that see distance: Wasserstein and MMD

The fixes replace the Jensen–Shannon divergence with one that changes smoothly as the generated distribution moves towards the data, even without overlap. The Wasserstein-1 distance is the least average distance mass must travel to turn pgp_g into pdatap_{\mathrm{data}}; it is estimated through its dual form with a constrained critic network (Arjovsky, Chintala and Bottou, 2017). The other fix comes from kernel methods, and returns in the post on one-step generators.

Definition 2 (Kernel mean embedding and MMD (Gretton et al., 2012))

For a positive-definite kernel kk with reproducing kernel Hilbert space H\mathcal{H}, the mean embedding of pp is μp=Ex∼p[k(x,⋅)]∈H\mu_p = \mathbb{E}_{\boldsymbol{x} \sim p}[k(\boldsymbol{x}, \cdot)] \in \mathcal{H}, and the maximum mean discrepancy is MMDk(p,q)=∥μp−μq∥H\mathrm{MMD}_k(p, q) = \lVert\mu_p - \mu_q\rVert_{\mathcal{H}}.

Proposition 10 (MMD from samples)

MMDk2(p,q)=E[k(x,x′)]+E[k(y,y′)]−2 E[k(x,y)],\mathrm{MMD}_k^2(p, q) = \mathbb{E}\big[k(\boldsymbol{x}, \boldsymbol{x}')\big] + \mathbb{E}\big[k(\boldsymbol{y}, \boldsymbol{y}')\big] - 2\,\mathbb{E}\big[k(\boldsymbol{x}, \boldsymbol{y})\big],

with x,x′∼p\boldsymbol{x}, \boldsymbol{x}' \sim p and y,y′∼q\boldsymbol{y}, \boldsymbol{y}' \sim q, all independent. Each term can be estimated by averaging the kernel over pairs of samples.

Proof

Step 1. Expand the squared norm. ∥μp−μq∥2=⟨μp,μp⟩+⟨μq,μq⟩−2⟨μp,μq⟩\lVert\mu_p - \mu_q\rVert^2 = \langle\mu_p, \mu_p\rangle + \langle\mu_q, \mu_q\rangle - 2\langle\mu_p, \mu_q\rangle.

Step 2. The reproducing property. ⟨k(x,⋅),k(y,⋅)⟩H=k(x,y)\langle k(\boldsymbol{x}, \cdot), k(\boldsymbol{y}, \cdot)\rangle_{\mathcal{H}} = k(\boldsymbol{x}, \boldsymbol{y}).

Step 3. Move the expectations out of the inner products (the inner product is linear in each argument, and the expectations are finite for a bounded kernel): ⟨μp,μq⟩=E⟨k(x,⋅),k(y,⋅)⟩=E[k(x,y)]\langle\mu_p, \mu_q\rangle = \mathbb{E}\langle k(\boldsymbol{x}, \cdot), k(\boldsymbol{y}, \cdot)\rangle = \mathbb{E}[k(\boldsymbol{x}, \boldsymbol{y})], and likewise for the other two terms.

For a characteristic kernel such as the squared-exponential, MMDk(p,q)=0\mathrm{MMD}_k(p, q) = 0 only when p=qp = q (Sriperumbudur et al., 2010), so the MMD is a genuine discrepancy that needs only samples. Generators trained to minimise it directly, without an adversary, were among the first alternatives to GANs (Li, Swersky and Zemel, 2015; Dziugaite, Roy and Ghahramani, 2015).

6. Energy-based models and the score

An energy-based model writes down an unnormalised density, pθ(x)=e−Eθ(x)/Zθp_\theta(\boldsymbol{x}) = e^{-E_\theta(\boldsymbol{x})}/Z_\theta, where EθE_\theta is any network and Zθ=∫e−Eθ(x) dxZ_\theta = \int e^{-E_\theta(\boldsymbol{x})}\,d\boldsymbol{x}. Any shape is allowed, but ZθZ_\theta is an integral over all of Rd\mathbb{R}^d and is intractable. It enters the likelihood gradient:

Proposition 11 (The likelihood gradient of an energy-based model)

∇θlog⁡pθ(x)=−∇θEθ(x)+Ex′∼pθ[∇θEθ(x′)].\nabla_\theta\log p_\theta(\boldsymbol{x}) = -\nabla_\theta E_\theta(\boldsymbol{x}) + \mathbb{E}_{\boldsymbol{x}' \sim p_\theta}\big[\nabla_\theta E_\theta(\boldsymbol{x}')\big].
Proof

Step 1. log⁡pθ(x)=−Eθ(x)−log⁡Zθ\log p_\theta(\boldsymbol{x}) = -E_\theta(\boldsymbol{x}) - \log Z_\theta.

Step 2. Differentiate log⁡Zθ\log Z_\theta. ∇θlog⁡Zθ=1Zθ∫∇θe−Eθ(x′) dx′=−∫e−Eθ(x′)Zθ∇θEθ(x′) dx′=−Epθ[∇θEθ]\nabla_\theta\log Z_\theta = \frac{1}{Z_\theta}\int\nabla_\theta e^{-E_\theta(\boldsymbol{x}')}\,d\boldsymbol{x}' = -\int\frac{e^{-E_\theta(\boldsymbol{x}')}}{Z_\theta}\nabla_\theta E_\theta(\boldsymbol{x}')\,d\boldsymbol{x}' = -\mathbb{E}_{p_\theta}[\nabla_\theta E_\theta].

Step 3. Combine. Subtracting gives the stated form: push the energy down at the data, and up at samples from the model.

So training needs samples from the model at every step, which is expensive. The way out is a quantity that does not involve ZθZ_\theta at all.

Proposition 12 (The score does not need the normalising constant)

sθ(x)=∇xlog⁡pθ(x)=−∇xEθ(x)\boldsymbol{s}_\theta(\boldsymbol{x}) = \nabla_{\boldsymbol{x}}\log p_\theta(\boldsymbol{x}) = -\nabla_{\boldsymbol{x}}E_\theta(\boldsymbol{x}).

Proof

Step 1. log⁡pθ(x)=−Eθ(x)−log⁡Zθ\log p_\theta(\boldsymbol{x}) = -E_\theta(\boldsymbol{x}) - \log Z_\theta.

Step 2. ZθZ_\theta depends on θ\theta but not on x\boldsymbol{x}, so its gradient in x\boldsymbol{x} is zero.

The score points uphill in density. Remarkably, it is enough to sample.

Proposition 13 (Langevin dynamics leaves p invariant)

The stochastic differential equation dx=∇log⁡p(x) dt+2 dWd\boldsymbol{x} = \nabla\log p(\boldsymbol{x})\,dt + \sqrt{2}\,d\boldsymbol{W} has pp as a stationary distribution. Its discretisation xk+1=xk+η s(xk)+2η ξk\boldsymbol{x}_{k+1} = \boldsymbol{x}_k + \eta\,\boldsymbol{s}(\boldsymbol{x}_k) + \sqrt{2\eta}\,\boldsymbol{\xi}_k, ξk∼N(0,I)\boldsymbol{\xi}_k \sim \mathcal{N}(\mathbf{0}, \mathbf{I}), samples approximately from pp for small η\eta and many steps.

Proof

We check the one-dimensional case with the Fokker–Planck equation, which the diffusion post derives. For dx=a(x) dt+2 dWdx = a(x)\,dt + \sqrt{2}\,dW, the density ρt\rho_t of xx evolves by ∂tρ=−∂x(aρ)+∂x2ρ\partial_t\rho = -\partial_x(a\rho) + \partial_x^2\rho.

Step 1. Put in a=(log⁡p)′=p′/pa = (\log p)' = p'/p and ρ=p\rho = p. Then aρ=p′a\rho = p'.

Step 2. The right-hand side. −∂x(p′)+∂x2p=−p′′+p′′=0-\partial_x(p') + \partial_x^2p = -p'' + p'' = 0.

Step 3. Conclusion. ∂tρ=0\partial_t\rho = 0: if xx is distributed as pp, it stays distributed as pp. The drift pushes mass uphill exactly as fast as the noise spreads it out.

What remains is to learn the score from data, without knowing pdatap_{\mathrm{data}}. Hyvärinen (2005) showed that the obvious objective can be rewritten without the unknown score.

Proposition 14 (Score matching (Hyvärinen, 2005))

In one dimension, for a model score sθs_\theta and data density pp that vanish fast enough at infinity,

Ep[(sθ(x)−(log⁡p)′(x))2]=Ep[sθ(x)2+2 sθ′(x)]+const.\mathbb{E}_p\big[(s_\theta(x) - (\log p)'(x))^2\big] = \mathbb{E}_p\big[s_\theta(x)^2 + 2\,s_\theta'(x)\big] + \text{const}.

In dd dimensions the derivative becomes the divergence, ∇⋅sθ=∑i∂sθ,i/∂xi\nabla\cdot\boldsymbol{s}_\theta = \sum_i\partial s_{\theta,i}/\partial x_i.

Proof

Step 1. Expand the square. Ep[sθ2]−2 Ep[sθ(log⁡p)′]+Ep[((log⁡p)′)2]\mathbb{E}_p[s_\theta^2] - 2\,\mathbb{E}_p[s_\theta(\log p)'] + \mathbb{E}_p[((\log p)')^2]. The last term does not depend on θ\theta.

Step 2. Simplify the cross term. p (log⁡p)′=p′p\,(\log p)' = p', so Ep[sθ(log⁡p)′]=∫sθ(x) p′(x) dx\mathbb{E}_p[s_\theta(\log p)'] = \int s_\theta(x)\,p'(x)\,dx.

Step 3. Integrate by parts. ∫sθp′ dx=[sθp]−∞∞−∫sθ′ p dx=−Ep[sθ′]\int s_\theta p'\,dx = \big[s_\theta p\big]_{-\infty}^{\infty} - \int s_\theta'\,p\,dx = -\mathbb{E}_p[s_\theta'], because the boundary term vanishes.

Step 4. Substitute. The cross term becomes +2 Ep[sθ′]+2\,\mathbb{E}_p[s_\theta'], which depends only on the model and the data samples.

In high dimensions the divergence costs one backward pass per dimension, and the score is learned badly in regions with no data, where Langevin dynamics starts. Both problems disappear if the data are first blurred with Gaussian noise of several sizes, and the score of each blurred distribution is learned instead (Vincent, 2011; Song and Ermon, 2019). That step is the beginning of diffusion models, and of the next post.

7. Autoregressive models

The last family evaluates exactly and samples slowly. Order the coordinates of x\boldsymbol{x}, and use the chain rule of probability:

p(x)=∏i=1dp(xi∣x1,…,xi−1).p(\boldsymbol{x}) = \prod_{i=1}^{d}p(x_i \mid x_1, \dots, x_{i-1}).

It holds for every distribution, by repeated use of p(a,b)=p(a) p(b∣a)p(a, b) = p(a)\,p(b \mid a), so nothing is approximated. A network outputs each conditional, for example a softmax over pixel values, so the likelihood is exact and training is maximum likelihood (van den Oord et al., 2016). Sampling must generate x1x_1, then x2x_2 given x1x_1, and so on: dd sequential network passes. For text that is natural, and large language models are exactly this. For an image with hundreds of thousands of values it is slow, and the ordering of pixels is arbitrary.

8. Same data, three families

Here is the ring of eight Gaussians (radius 2, standard deviation 0.1), and three models trained on it: a normalising flow (eight affine coupling layers), a VAE (two-dimensional latent, learned decoder noise) and a GAN. All three use the same small networks, one training run each with a fixed seed. Below each panel: how many of the eight modes receive at least 2% of the samples, the share of samples within three standard deviations of a mode (99% for the data), and the likelihood where the model has one.

Each family fails in the way its mathematics predicts:

  • The flow covers all eight modes and draws bridges between them. A quarter of its samples lie off the modes, on the connecting paths that Section 3 proved it cannot avoid. Its likelihood is exact: 0.90 nats per point, against 0.32 for the true distribution.
  • The VAE covers all eight modes and fills the space between them. Only 53% of its samples are on a mode. The decoder noise blurs, and codes from the prior’s holes decode to points between the modes. Its −ELBO-\text{ELBO} of 1.71 is an upper bound on its negative log-likelihood, not the value itself.
  • The GAN’s samples are sharp but smear along the ring, and it drops one mode entirely. It covers 7 of 8. It has no likelihood to report at all.

With more tuning each model improves, and these small networks are far from the state of the art. But the characters are the ones reported throughout the literature: likelihood training covers the data and leaks between modes, adversarial training is sharp and drops modes.

9. The map, and where this series goes

learn a distributionfrom samples x₁, …, xₙwrite down p(x)and maximise likelihoodlearn a sampler x = G(z)push noise through a networklearn the score ∇ log pthen sample by a dynamics• autoregressiveexact p, slow to sample• normalising flowsexact p, invertible maps• energy-basedp up to a constant• VAEsa lower bound on log p• GANssharp samples, no p• score matching + Langevinthe score needs no constant• diffusion modelspost 2 of this series• flow matchingpost 3one-step generatorspost 4: one network pass, diffusion qualitydistil or shortcutthe dynamicskeep a one-passsampler

Side by side:

familyevaluate p(x)p(\boldsymbol{x})network passes per sampletypical failuretraining
autoregressiveexactdd (one per coordinate)slow samplingstable, maximum likelihood
normalising flowexact1bridges between modes; restricted layersstable, maximum likelihood
VAElower bound1blur, holes, posterior collapsestable, ELBO
GANnone1missing modesunstable minimax game
energy-basedup to ZθZ_\thetamany (MCMC)slow, hard to trainneeds model samples
diffusion and flow matchingthrough an ODE, costlytens to hundredsslow samplingstable, simple regression

Xiao, Kreis and Vahdat (2022) summarised the tension as a trilemma: high sample quality, coverage of all modes, and fast sampling. GANs had quality and speed but not coverage. VAEs and flows had speed and coverage but lower quality. Diffusion models, which learn the score of the data blurred at every noise level and then follow a dynamics like Langevin’s, achieve quality and coverage and pay in speed.

The rest of the series follows that route and then removes its cost:

  • Diffusion models (next): add noise until the data are Gaussian, learn to undo it, and see why denoising is score matching in disguise.
  • Flow matching: replace the noisy dynamics by a deterministic flow, learned by plain regression on a velocity field, and make its paths straighter.
  • One-step generators: learn to jump along the whole flow in a single network pass. This brings back the GAN’s speed with the diffusion model’s coverage: consistency models, flow maps, MeanFlow, and drifting models, where the kernel discrepancies of Section 5 return.

Questions

Question 1

A model can produce samples but not evaluate its density. Which of the divergences in this post can you still use to train it, and why not maximum likelihood?

Answer

Maximum likelihood needs log⁡pθ(x)\log p_\theta(\boldsymbol{x}) at the data points, which a sampler cannot provide. Divergences that need only samples remain: the Jensen–Shannon divergence through a trained classifier (a GAN), the Wasserstein distance through a constrained critic, and the MMD, whose three terms are averages of a kernel over pairs of samples.

Question 2

Why is the density of a flow’s output low where the map stretches space, and high where it compresses it?

Answer

By change of variables, px(x)=pz(z)/∣det⁡Jf(z)∣p_{\boldsymbol{x}}(\boldsymbol{x}) = p_{\boldsymbol{z}}(\boldsymbol{z})/\lvert\det\mathbf{J}_f(\boldsymbol{z})\rvert, and ∣det⁡Jf∣\lvert\det\mathbf{J}_f\rvert is the factor by which ff multiplies small volumes. The probability in a small region is preserved, so if the region’s volume is multiplied by 3, its density is divided by 3.

Question 3

In the GAN proof, what does the discriminator output at the optimum when the generator is perfect, and what does that tell you about training dynamics?

Answer

With pg=pdatap_g = p_{\mathrm{data}}, D∗(x)=12D^*(\boldsymbol{x}) = \tfrac12 everywhere: the best classifier can only guess. The value is V=−log⁡4V = -\log 4, the minimum. During training the discriminator is never optimal and the generator never perfect, and the two chase each other; nothing in the game guarantees that this chase converges.

Question 4

Why can score matching be computed from data, although its definition contains the unknown ∇log⁡pdata\nabla\log p_{\mathrm{data}}?

Answer

Integration by parts moves the derivative from the data density onto the model’s score (Step 3 of the proof), turning Ep[sθ(log⁡p)′]\mathbb{E}_p[s_\theta(\log p)'] into −Ep[∇⋅sθ]-\mathbb{E}_p[\nabla\cdot\boldsymbol{s}_\theta]. What remains are expectations under pdatap_{\mathrm{data}} of quantities that depend only on the model, which sample averages estimate.

Question 5

The VAE in Section 8 reports −ELBO=1.71-\text{ELBO} = 1.71 and the flow an exact negative log-likelihood of 0.900.90. Can you conclude that the flow fits the data better?

Answer

Not quite. The −ELBO-\text{ELBO} is only an upper bound on the VAE’s negative log-likelihood; its true value lies somewhere below 1.71. An importance-weighted estimate would tighten it. The sample statistics (53% against 75% on a mode) point the same way as the numbers, so the conclusion is probably right, but the comparison of a bound with an exact value is not by itself a proof.

References

  • I. Goodfellow, J. Pouget-Abadie, M. Mirza, B. Xu, D. Warde-Farley, S. Ozair, A. Courville, Y. Bengio. Generative adversarial nets. NeurIPS, 2014.
  • D. P. Kingma, M. Welling. Auto-encoding variational Bayes. ICLR, 2014. arXiv:1312.6114
  • D. J. Rezende, S. Mohamed, D. Wierstra. Stochastic backpropagation and approximate inference in deep generative models. ICML, 2014.
  • D. J. Rezende, S. Mohamed. Variational inference with normalizing flows. ICML, 2015.
  • L. Dinh, J. Sohl-Dickstein, S. Bengio. Density estimation using Real NVP. ICLR, 2017. arXiv:1605.08803
  • G. Papamakarios, E. Nalisnick, D. J. Rezende, S. Mohamed, B. Lakshminarayanan. Normalizing flows for probabilistic modeling and inference. JMLR, 2021.
  • A. Hyvärinen. Estimation of non-normalized statistical models by score matching. JMLR, 2005.
  • P. Vincent. A connection between score matching and denoising autoencoders. Neural Computation, 2011.
  • Y. Song, S. Ermon. Generative modeling by estimating gradients of the data distribution. NeurIPS, 2019.
  • A. Gretton, K. M. Borgwardt, M. J. Rasch, B. Schölkopf, A. Smola. A kernel two-sample test. JMLR, 2012.
  • B. K. Sriperumbudur, A. Gretton, K. Fukumizu, B. Schölkopf, G. R. G. Lanckriet. Hilbert space embeddings and metrics on probability measures. JMLR, 2010.
  • Y. Li, K. Swersky, R. Zemel. Generative moment matching networks. ICML, 2015.
  • G. K. Dziugaite, D. M. Roy, Z. Ghahramani. Training generative neural networks via maximum mean discrepancy optimization. UAI, 2015.
  • M. Arjovsky, S. Chintala, L. Bottou. Wasserstein generative adversarial networks. ICML, 2017.
  • A. van den Oord, N. Kalchbrenner, K. Kavukcuoglu. Pixel recurrent neural networks. ICML, 2016.
  • Z. Xiao, K. Kreis, A. Vahdat. Tackling the generative learning trilemma with denoising diffusion GANs. ICLR, 2022.
  • S. Bond-Taylor, A. Leach, Y. Long, C. G. Willcocks. Deep generative modelling: a comparative review of VAEs, GANs, normalizing flows, energy-based and autoregressive models. IEEE TPAMI, 2022.