Skip to content
AIAI Wranglers

4 Divergence Measures and Information Theory

Every generative model is trained by minimising some measure of discrepancy between two distributions: the true data distribution pdata and the model distribution pθ. Different choices of discrepancy lead to fundamentally different algorithms:

  • KL divergence maximum likelihood, VAEs (Chapter ch:vae),

  • Jensen–Shannon divergence the original GAN (Chapter 9),

  • Wasserstein distance Wasserstein GAN (Chapter 10),

  • Fisher divergence score matching and diffusion models (Chapter 16).

Understanding these divergences, their definitions, properties, and failure modes, is therefore essential before studying any specific model.

This chapter develops the information-theoretic and optimal-transport foundations that the rest of the book relies on. We begin with entropy and cross-entropy, build up to KL divergence and its variants, introduce the unifying f-divergence family, and then turn to the geometrically-motivated Wasserstein distance. We close with the Fisher divergence, which connects to the score function at the heart of diffusion models.

Entropy and Cross-Entropy

Historical Note.

In his landmark 1948 paper “A Mathematical Theory of Communication” [1], Claude Shannon introduced the concept of information entropy. Legend has it that John von Neumann advised Shannon to call it “entropy,” borrowing the term from thermodynamics, saying: “No one really knows what entropy is, so in a debate you will always have the advantage.” The same quantity had appeared in Boltzmann's statistical mechanics in the 1870s, but Shannon's formulation recast it as the fundamental currency of information.

Definition 1 (Shannon Entropy).

The Shannon entropy of a discrete random variable X with distribution P on a finite alphabet 𝒳 is (Entropy)𝖧(P)=x𝒳P(x)logP(x), with the convention 0log0=0. For a continuous random variable with density p(x), the differential entropy is (DIFF Entropy)h(p)=p(x)logp(x)dx.

Entropy measures the average surprise or uncertainty inherent in the distribution. A distribution concentrated on a single outcome has zero entropy; the uniform distribution over n outcomes has maximal entropy logn.

Example 1 (Entropy of a Bernoulli Variable).

Let XBernoulli(θ). Then 𝖧(θ)=θlogθ(1θ)log(1θ). This is maximised at θ=1/2 (a fair coin), where 𝖧=log20.693 nats. A biased coin with θ=0.9 has 𝖧0.325 nats, less than half the uncertainty of a fair coin.

Example 2 (Entropy of Common Distributions).

  • Uniform on {1,,n}: 𝖧=logn. For a byte (n=256), 𝖧=8log2 bits =8 bits.

  • Gaussian 𝒩(μ,σ2): h=12log(2πeσ2). Among all distributions with fixed variance σ2, the Gaussian has maximum differential entropy, a fact that makes Gaussian assumptions natural in many settings.

  • Exponential Exp(λ): h=1logλ.

Remark 1 (Entropy in Data Compression).

Shannon's source coding theorem states that the entropy 𝖧(P) is the minimum average number of bits needed to encode a message drawn from P. This result launched the entire field of information theory and has direct implications for generative models: the log-likelihood logpθ(x) measures how many bits the model needs to encode a data point. A model with higher log-likelihood is literally a better compressor of the data.

Definition 2 (Cross-Entropy).

The cross-entropy between distributions P and Q on the same space is (Cross Entropy)𝖧(P,Q)=xP(x)logQ(x)=𝔼xP[logQ(x)].

Example 3 (Cross-Entropy in Classification).

In a 3-class problem, suppose the true label is class 2, so the one-hot label vector is P=(0,1,0). A classifier predicts Q=(0.1,0.7,0.2). The cross-entropy loss is 𝖧(P,Q)=log(0.7)0.357 nats. A perfect prediction Q=(0,1,0) gives 𝖧(P,Q)=0. This is exactly the loss function used to train neural network classifiers.

Insight.

When we train a classifier by minimising cross-entropy loss, we are minimising 𝖧(Pdata,Pθ) over model parameters θ. Since 𝖧(Pdata,Pθ)=𝖧(Pdata)+𝖣KL(PdataPθ), and the entropy 𝖧(Pdata) is a constant with respect to θ, minimising cross-entropy is equivalent to minimising KL divergence, which is equivalent to maximum likelihood estimation. This fundamental trinity (MLE = cross-entropy minimisation = KL minimisation) underpins most of modern machine learning.

Kullback–Leibler Divergence

Historical Note.

Solomon Kullback and Richard Leibler introduced their divergence in 1951 [2], calling it “discrimination information”. Kullback later wrote an entire book, Information Theory and Statistics (1959), developing the connections between hypothesis testing and information theory. The quantity is also known as relative entropy, since it measures the “extra” entropy incurred when using the wrong distribution Q instead of the true distribution P.

Definition 3 (KL Divergence).

The Kullback–Leibler divergence (also called relative entropy) from distribution P to Q is [2] (KL Discrete)𝖣KL(PQ)=xP(x)logP(x)Q(x)=𝔼xP[logP(x)Q(x)], for discrete distributions, and (KL Continuous)𝖣KL(pq)=p(x)logp(x)q(x)dx for continuous densities, provided P is absolutely continuous with respect to Q (i.e. Q(x)=0P(x)=0). Otherwise, 𝖣KL(PQ)=+.

Note the asymmetry: P is the reference (the distribution we average over) and Q is the model we are measuring against. The notation 𝖣KL(PQ) is read as “the KL divergence from P to Q” or equivalently “of P with respect to Q.”

Example 4 (KL Divergence between Two Discrete Distributions).

Let P=(0.5,0.3,0.2) and Q=(0.1,0.6,0.3) on {1,2,3}. 𝖣KL(PQ)=0.5log0.50.1+0.3log0.30.6+0.2log0.20.3=0.51.609+0.3(0.693)+0.2(0.405)0.516 nats. But in the other direction: 𝖣KL(QP)=0.1log0.10.5+0.6log0.60.3+0.2log0.20.20.254 nats. Notice that 0.5160.254; KL divergence is not symmetric.

Theorem 1 (Gibbs' Inequality - Non-Negativity of KL).

For any two distributions P and Q, 𝖣KL(PQ)0, with equality if and only if P=Q almost everywhere.

Proof.

By Jensen's inequality applied to the concave function log(): 𝖣KL(PQ)=xP(x)logQ(x)P(x)=𝔼xP[logQ(x)P(x)]log(𝔼xP[Q(x)P(x)])=log(xQ(x))=log1=0. Hence 𝖣KL(PQ)0. Equality holds iff Q(x)/P(x) is constant P-a.s., which forces P=Q.

Remark 2 (KL Divergence Is Not a Metric).

Although 𝖣KL0 and 𝖣KL(PQ)=0P=Q, KL divergence fails two properties of a metric:

  1. Asymmetry: as Example 4 shows, 𝖣KL(PQ)𝖣KL(QP) in general.

  2. No triangle inequality: there exist P,Q,R such that 𝖣KL(PR)>𝖣KL(PQ)+𝖣KL(QR).

Despite not being a metric, KL divergence is the most widely used divergence in machine learning, due to its connection to MLE and information theory.

Example 5 (KL Can Be Infinite).

Let P=(1,0) and Q=(0.5,0.5) on {a,b}. Then 𝖣KL(PQ)=log20.693. But 𝖣KL(QP)=0.5log0.51+0.5log0.50=+, because Q assigns positive mass to b where P(b)=0. This is a crucial failure mode: when the model Q assigns probability to events that never occur under the reference P, KL stays finite; but when Q assigns zero probability to events that do occur under P, KL explodes to infinity.

Key Idea.

Where is KL divergence used in generative modelling?

  • Maximum likelihood training: For any model with a tractable density pθ(x), MLE is equivalent to minimising 𝖣KL(pdatapθ). This includes autoregressive models (GPT, LLaMA), normalising flows, and Gaussian mixture models.

  • VAE regularisation: The KL term in the ELBO, 𝖣KL(qϕ(z|x)p(z)), pushes the encoder towards the prior (Chapter ch:vae).

  • Knowledge distillation: A student model is trained to minimise KL divergence from the teacher's output distribution.

  • Reinforcement learning from human feedback (RLHF): A KL penalty 𝖣KL(πθπref) prevents the fine-tuned model from drifting too far from the reference policy, a crucial component in training ChatGPT and similar systems.

KL Divergence between Gaussians

Since Gaussian distributions appear ubiquitously in generative models (VAE encoders, diffusion noise schedules, etc.), the closed-form KL between Gaussians is one of the most-used formulas in practice.

Proposition 1 (KL between Univariate Gaussians).

For P=𝒩(μ1,σ12) and Q=𝒩(μ2,σ22), (KL Gaussian 1D)𝖣KL(PQ)=logσ2σ1+σ12+(μ1μ2)22σ2212.

Proof.

Write 𝖣KL=𝔼P[logplogq] and expand each Gaussian log-density: 𝖣KL=𝔼P[(xμ1)22σ12logσ1+(xμ2)22σ22+logσ2]=logσ2σ112+𝔼P[(xμ2)2]2σ22. Now 𝔼P[(xμ2)2]=𝖵arP(x)+(𝔼P[x]μ2)2=σ12+(μ1μ2)2, giving the result.

Example 6 (KL between Two Specific Gaussians).

Let P=𝒩(0,1) (standard normal) and Q=𝒩(1,4). Then 𝖣KL(PQ)=log21+1+1812=0.693+0.250.5=0.443 nats. In the reverse direction: 𝖣KL(QP)=log12+4+1212=0.693+2.50.5=1.307 nats. The asymmetry is striking: fitting a narrow distribution with a wider one (forward) costs much less than fitting a wider distribution with a narrower one (reverse).

Proposition 2 (KL between Multivariate Gaussians).

For P=𝒩(𝝁1,Σ1) and Q=𝒩(𝝁2,Σ2) in d, (KL Gaussian MV)𝖣KL(PQ)=12[logdetΣ2detΣ1d+trace(Σ21Σ1)+(𝝁2𝝁1)Σ21(𝝁2𝝁1)].

Key Idea.

In VAEs (Chapter ch:vae), the encoder outputs 𝝁ϕ(x) and σϕ2(x), and the KL term in the ELBO becomes 𝖣KL(𝒩(𝝁ϕ,diag(σϕ2))𝒩(0,I)), which by (KL Gaussian MV) simplifies to 12j=1d[μj2+σj2logσj21]. This closed-form expression is why VAEs almost always use Gaussian encoders, as it eliminates the need for Monte Carlo estimation of the KL term, making training significantly more stable.

Forward vs. Reverse KL Divergence

The asymmetry of KL divergence has profound practical consequences. Suppose p is the true (data) distribution and qθ is our model.

Definition 4 (Forward and Reverse KL).

  • Forward KL (also M-projection): minθ𝖣KL(pqθ)=minθ𝔼xp[logp(x)qθ(x)]. This is equivalent to maximum likelihood estimation.

  • Reverse KL (also I-projection): minθ𝖣KL(qθp)=minθ𝔼xqθ[logqθ(x)p(x)]. This arises in variational inference and expectation propagation.

The two directions produce qualitatively different behaviour when the model qθ is not flexible enough to match p exactly:

Forward KL forces qθ to cover all modes of p (mode-covering), producing a broad, potentially blurry fit. Reverse KL allows qθ to concentrate on a single mode (mode-seeking), producing a sharp but incomplete fit.

Key Idea.

Forward KL penalises qθ(x)0 where p(x)>0. Since p is the reference, any region where p has mass but qθ does not incurs an enormous penalty (log(p/q)+). The result is a mode-covering fit: qθ spreads out to cover all modes, even if it fills in the gaps between modes with spurious mass. This explains why MLE-trained models (VAEs) tend to produce blurry outputs.

Reverse KL penalises qθ(x)>0 where p(x)0. Now qθ is the reference distribution; placing mass outside the support of p incurs log(q/p)+. The model avoids generating anything “unrealistic” but may ignore entire modes. This is mode-seeking behaviour and partially explains GAN mode collapse.

Remark 3 (The Forward/Reverse Divide in Generative Modelling).

This asymmetry creates a deep divide in the field:

  • Forward KL models (MLE-based): autoregressive models, normalising flows, VAE reconstruction term. These produce diverse but sometimes blurry samples.

  • Reverse KL / adversarial models: GANs, and the KL term in variational inference. These produce sharp samples but risk mode collapse.

Diffusion models sidestep this divide entirely by using a score-matching objective that does not directly involve either direction of KL (Fisher Divergence and Score Matching).

Jensen–Shannon Divergence

Definition 5 (Jensen–Shannon Divergence).

The Jensen–Shannon (JS) divergence [3] between P and Q is (JS)𝖣JS(PQ)=12𝖣KL(PM)+12𝖣KL(QM),M=12(P+Q).

JS divergence repairs two deficiencies of KL: it is symmetric (𝖣JS(PQ)=𝖣JS(QP)) and always finite (even when P and Q have disjoint support).

Example 7 (JS Divergence between Two Distributions).

With P=(0.5,0.3,0.2) and Q=(0.1,0.6,0.3) as in Example 4, the mixture is M=(0.3,0.45,0.25). Then 𝖣KL(PM)=0.5log0.50.3+0.3log0.30.45+0.2log0.20.250.082,𝖣KL(QM)=0.1log0.10.3+0.6log0.60.45+0.3log0.30.250.088,𝖣JS(PQ)=12(0.082+0.088)0.085 nats. Compare this with 𝖣KL(PQ)0.516: JS divergence is much smaller because it symmetrises and smooths the comparison.

Proposition 3 (Entropy Representation of JS).

(JS Entropy)𝖣JS(PQ)=𝖧(M)12𝖧(P)12𝖧(Q), where 𝖧() denotes the Shannon entropy and M=12(P+Q).

Proof.

Expand each KL term: 𝖣KL(PM)=xP(x)logP(x)M(x)=𝖧(P)xP(x)logM(x),𝖣KL(QM)=𝖧(Q)xQ(x)logM(x). Averaging and noting that 12x[P(x)+Q(x)]logM(x)=xM(x)logM(x)=𝖧(M) gives the result.

Theorem 2 (Bounds on JS Divergence).

For any P,Q, (JS Bounds)0𝖣JS(PQ)log2. The lower bound is attained iff P=Q; the upper bound iff P and Q have disjoint support.

Proof.

The lower bound follows from Gibbs' inequality applied to both KL terms. For the upper bound, when P and Q have disjoint support, every x in the support of P satisfies M(x)=P(x)/2, so 𝖣KL(PM)=log2; similarly for Q. Hence 𝖣JS=log2.

Insight.

The original GAN [4] minimises (a function of) the JS divergence between pdata and pθ. Goodfellow et al. showed that the optimal discriminator satisfies D(x)=pdata(x)pdata(x)+pθ(x), and the resulting generator objective equals 2𝖣JS(pdatapθ)log4. The upper bound 𝖣JSlog2 being a constant means that when pdata and pθ have disjoint support (common early in training when generated images are far from realistic), the gradient of the JS divergence is zero, so the generator receives no learning signal. This is the celebrated “vanishing gradient” problem [5] that motivated the Wasserstein GAN [6] (Chapter 10).

The f-Divergence Family

KL, JS, and total variation are all special cases of a single unified framework.

Historical Note.

The f-divergence was introduced independently by Imre Csiszár [7] in 1963 and by Syed Mumtaz Ali and Samuel Silvey [8] in 1966. Csiszár, a Hungarian information theorist, studied the concept through the lens of information theory, while Ali and Silvey approached it from statistical hypothesis testing. Their independent discovery underscores how naturally the f-divergence framework arises from different mathematical perspectives.

Definition 6 (f-Divergence).

Let f:(0,) be a convex function with f(1)=0. The f-divergence [7][8] from P to Q is (F DIV)𝖣f(PQ)=𝔼xQ[f(P(x)Q(x))]=xQ(x)f(P(x)Q(x)). For continuous densities, the sum is replaced by an integral.

Remark 4 (Convention).

Some references define 𝖣f(PQ)=𝔼P[f(Q/P)]. The two conventions differ by swapping P and Q and/or replacing f(t) with tf(1/t) (the conjugate generator). We follow the convention 𝔼Q[f(P/Q)], which is standard in the optimal-transport and GAN literature.

Theorem 3 (Non-Negativity of f-Divergence).

𝖣f(PQ)0 for all P,Q, with equality iff P=Q.

Proof.

By Jensen's inequality (since f is convex): 𝖣f(PQ)=𝔼Q[f(PQ)]f(𝔼Q[PQ])=f(1)=0.

The following table shows how common divergences arise from specific choices of the generator f.

llc@ DivergenceGenerator f(t)Symmetric?
KL divergencetlogtNo
Reverse KLlogtNo
Jensen–Shannontlogt(1+t)log1+t2Yes
Total variation12|t1|Yes
χ2-divergence(t1)2No
Hellinger distance(t1)2Yes
Common divergences as special cases of f-divergence with different convex generators.

Example 8 (Deriving KL from f-Divergence).

Choose f(t)=tlogt. Then 𝖣f(PQ)=𝔼Q[PQlogPQ]=xP(x)logP(x)Q(x)=𝖣KL(PQ).

Example 9 (Deriving TV from f-Divergence).

Choose f(t)=12|t1|. Then 𝖣f(PQ)=xQ(x)12|P(x)Q(x)1|=12x|P(x)Q(x)|=𝖣TV(P,Q).

Theorem 4 (Data Processing Inequality).

Let T be any stochastic map (Markov kernel). Then for any f-divergence, (DPI)𝖣f(TPTQ)𝖣f(PQ). In words: processing data can only lose information; it can never increase the divergence.

Key Idea.

The data processing inequality has direct consequences for generative modelling:

  • No post-processing of generated samples (e.g. applying filters, super-resolution) can make them closer in f-divergence to the true data than the raw model output.

  • f-GAN [9]: Nowozin et al. showed that any f-divergence can be used as a GAN training objective via a variational lower bound. This led to a family of GAN variants using different generators f, generalising the original JS-based GAN.

Total Variation Distance

Definition 7 (Total Variation Distance).

The total variation distance between distributions P and Q is (TV)𝖣TV(P,Q)=12x|P(x)Q(x)|=supA𝒳|P(A)Q(A)|. For continuous densities, the sum becomes an integral. TV distance is symmetric, satisfies the triangle inequality, and takes values in [0,1].

The second expression as a supremum over events has an elegant interpretation: TV distance is the maximum advantage a hypothesis test can gain by choosing the best decision region.

Example 10 (Computing TV Distance).

Let P=(0.1,0.3,0.4,0.2) and Q=(0.2,0.2,0.4,0.2) on {1,2,3,4}. Then 𝖣TV(P,Q)=12(|0.10.2|+|0.30.2|+|0.40.4|+|0.20.2|)=12(0.1+0.1)=0.1. This means that the best possible test to distinguish samples from P versus Q can achieve at most a 10% advantage over random guessing.

Example 11 (TV between Gaussians).

For P=𝒩(0,1) and Q=𝒩(μ,1) (same variance, shifted mean), the TV distance has no simple closed form but can be computed numerically:

μ0.51.02.05.0
𝖣TV(P,Q)0.200.380.680.99
At μ=5, the distributions are nearly disjoint and TV approaches 1.

The total variation distance is related to KL divergence through an important inequality.

Theorem 5 (Pinsker's Inequality).

For any two distributions P and Q [10], (Pinsker)𝖣TV(P,Q)12𝖣KL(PQ).

Remark 5 (Pinsker in Practice).

Pinsker's inequality provides a useful conceptual bridge: bounding the KL divergence automatically bounds the TV distance. If a model achieves 𝖣KL(pdatapθ)=0.02 nats, then 𝖣TV0.01=0.1, meaning no statistical test can distinguish real from generated samples with more than 10% advantage. This is why small KL values imply good generative quality.

Wasserstein Distance and Optimal Transport

The divergences studied so far (KL, JS, TV) compare distributions point-wise: they depend on the values of P(x) and Q(x) but not on the geometry of the underlying space 𝒳. The Wasserstein distance, rooted in optimal transport theory, does account for geometry: moving probability mass a short distance costs less than moving it a long distance.

Historical Note.

The optimal transport problem has a remarkable 240-year history. Gaspard Monge first posed the problem in 1781 [11], not for abstract mathematics, but for a concrete military engineering task: finding the cheapest way to move soil (déblais) to fill fortifications (remblais) during the French Revolution. The problem proved incredibly hard: Monge's formulation requires a deterministic point-to-point assignment, which may not exist.

Over 160 years later, Soviet mathematician Leonid Kantorovich (1942) [12] reformulated the problem by allowing probabilistic transport plans (splitting mass from one source to multiple destinations), turning it into a linear programme. This breakthrough earned him the 1975 Nobel Prize in Economics (for the theory of optimal allocation of resources).

The name “Wasserstein distance” comes from Leonid Vasershtein [13], who used the metric in 1969 to study convergence of Markov chains. The German transliteration of his name (of Yiddish origin, meaning “water stone”) became the standard mathematical term. Computer vision researchers later coined the more intuitive name “earth mover's distance” (EMD) in the 1990s.

The Optimal Transport Problem

Imagine P and Q as two piles of sand of equal total mass, spread over a landscape 𝒳. A transport plan γ(x,y) specifies how much mass to move from location x to location y. Any valid plan must satisfy the marginal constraints: the total mass leaving x equals P(x), and the total mass arriving at y equals Q(y).

Definition 8 (Wasserstein-p Distance).

Let (𝒳,d) be a metric space and let P,Q be probability measures on 𝒳 with finite p-th moments (p1). The Wasserstein-p distance is (Wasserstein)Wp(P,Q)=(infγΠ(P,Q)𝒳×𝒳d(x,y)pdγ(x,y))1/p, where Π(P,Q) is the set of all couplings (joint distributions on 𝒳×𝒳 with marginals P and Q).

The Wasserstein distance is the minimum-cost transport plan that reshapes distribution P into distribution Q. The cost of each “shipment” is proportional to the mass moved times the distance travelled.

Example 12 (Wasserstein between Point Masses).

For P=δa and Q=δb (point masses at a and b on ), the only coupling is γ=δ(a,b), giving Wp(P,Q)=|ab| for all p. The Wasserstein distance is simply the Euclidean distance between the two points.

Example 13 (Wasserstein between Univariate Gaussians).

For P=𝒩(μ1,σ12) and Q=𝒩(μ2,σ22), the Wasserstein-2 distance has a beautiful closed form: (W2 Gaussian)W2(P,Q)=(μ1μ2)2+(σ1σ2)2. This is just the Euclidean distance in the (μ,σ)-parameter space! Compare this with the KL divergence ((KL Gaussian 1D)), which has a more complex, asymmetric form.

Proposition 4 (Wasserstein Distance Is a True Metric).

Wp satisfies all properties of a metric: non-negativity, identity of indiscernibles, symmetry, and the triangle inequality. This is a significant advantage over KL and JS divergences.

Proposition 5 (Wasserstein-1 in One Dimension).

For distributions on with CDFs FP and FQ, the Wasserstein-1 distance has the closed form (W1 1D)W1(P,Q)=|FP(x)FQ(x)|dx. This is simply the L1 distance between the CDFs, the “area between the curves.”

The Kantorovich–Rubinstein Duality

Computing W1 from the primal definition requires optimising over all couplings, a challenging task. The following duality theorem provides an alternative characterisation that is far more practical.

Theorem 6 (Kantorovich–Rubinstein Duality).

The Wasserstein-1 distance equals [14] (KR)W1(P,Q)=supfL1[𝔼xP[f(x)]𝔼xQ[f(x)]], where the supremum is over all 1-Lipschitz functions f:𝒳 (i.e. |f(x)f(y)|d(x,y) for all x,y).

Insight.

The Kantorovich–Rubinstein duality is the theoretical foundation of the Wasserstein GAN (WGAN) [6], studied in Chapter 10. In WGAN, the discriminator (called the critic) approximates the supremum in (KR): it is a neural network trained to maximise 𝔼xpdata[fw(x)]𝔼zpZ[fw(gθ(z))] subject to a Lipschitz constraint on fw. The generator then minimises the resulting estimate of W1.

Enforcing the Lipschitz constraint in practice remains a challenge. Three main approaches have been proposed:

  • Weight clipping [6]: clip critic weights to [c,c]. Simple but can cause the critic to learn only very simple functions.

  • Gradient penalty (WGAN-GP) [15]: add a penalty λ𝔼[(f1)2] to the critic loss. More stable but computationally expensive.

  • Spectral normalisation [16]: normalise each weight matrix by its spectral norm. Efficient and widely adopted.

Why Wasserstein Distance Matters for GANs

The key advantage of Wasserstein distance over KL and JS for training generative models is its behaviour when distributions have disjoint or low-dimensional support, a situation that is the norm, not the exception, in image generation.

Example 14 (Disjoint Support: KL, JS, TV, and Wasserstein Compared).

Let P=δ0 and Qt=δt be point masses at 0 and t on . For t0: 𝖣KL(PQt)=+,𝖣JS(PQt)=log20.693(constant),𝖣TV(P,Qt)=1(constant),W1(P,Qt)=|t|. Only the Wasserstein distance provides a smooth, meaningful signal: as t0, W10 continuously, while KL divergence remains infinite and JS/TV jump discontinuously from a constant to 0.

Divergences between δ0 and δt as a function of t. KL is infinite for all t0; JS and TV are flat constants; only W1 varies smoothly with t, providing useful gradients for optimisation.

Remark 6 (Why Disjoint Support Is the Norm).

Real image distributions are believed to concentrate on a low-dimensional manifold in pixel space (the manifold hypothesis [5]). During GAN training, the generator distribution pθ is also supported on a low-dimensional manifold (the image of the latent space through the network). Two low-dimensional manifolds in a high-dimensional ambient space have measure-zero overlap with probability one. This means KL and JS are essentially useless early in training; their gradients carry no information about which direction to move the generator manifold. Wasserstein distance, by contrast, “sees” the geometric distance between the two manifolds and provides useful gradients throughout.

Caution.

Computing the exact Wasserstein distance in high dimensions is computationally expensive: the primal LP has O(n2) variables for n support points, and the dual requires optimising over all Lipschitz functions. The Sinkhorn algorithm [17] (Chapter ch:sinkhorn) provides an efficient entropic regularisation, and neural-network critics approximate the KR dual in WGANs, but both are approximations.

Wasserstein Distance and Weak Convergence

Theorem 7 (Wasserstein Convergence Implies Weak Convergence).

Let (μn)n1 be a sequence of probability measures on a metric space (𝒳,d). If Wp(μn,μ)0 for some p1, then μn converges weakly to μ: fdμnfdμfor all bounded continuous f.

Proof sketch.

Any bounded Lipschitz function satisfies |fdμnfdμ|fLW1(μn,μ) by the Kantorovich–Rubinstein duality. Since bounded Lipschitz functions are dense (in the sup-norm) among bounded continuous functions on a separable metric space, W10 implies convergence of integrals for all bounded continuous f. The case p>1 follows from the inequality W1Wp (by Jensen's).

Remark 7 (Why Weak Convergence Matters for Generative Models).

In generative modelling, we want pθpdata in a sense that implies convergence of all expectations, e.g. that generated images “look like” real ones on average. Weak convergence is exactly this notion. Since Wasserstein convergence implies weak convergence, training with Wp loss gives meaningful convergence guarantees. By contrast, while 𝖣KL0 also implies weak convergence (via Pinsker), KL can be infinite when Wp is perfectly well-defined.

Mutual Information

Definition 9 (Mutual Information).

The mutual information between random variables X and Y with joint distribution PXY and marginals PX,PY is (MI)𝖨(X;Y)=𝖣KL(PXYPXPY)=𝔼[logPXY(x,y)PX(x)PY(y)]. Equivalently, 𝖨(X;Y)=𝖧(X)𝖧(X|Y)=𝖧(Y)𝖧(Y|X).

Mutual information measures how much knowing Y reduces our uncertainty about X (and vice versa). It is zero iff X and Y are independent.

Example 15 (Mutual Information in a Simple Channel).

Consider a binary symmetric channel: XBernoulli(0.5) and Y=X⊕︎N where NBernoulli(ϵ) is independent noise (flipping X with probability ϵ). Then 𝖨(X;Y)=log2𝖧(ϵ)=1𝖧(ϵ) bits. For a noiseless channel (ϵ=0), 𝖨=1 bit (knowing Y determines X completely). For a completely noisy channel (ϵ=0.5), 𝖨=0 (observing Y tells us nothing about X).

Key Idea.

Mutual information appears throughout generative modelling:

  • InfoGAN [18]: the generator is trained to maximise 𝖨(c;G(z,c)) between a latent code c and generated output, encouraging disentangled representations, e.g. one dimension of c might control rotation while another controls lighting.

  • ELBO decomposition: the evidence lower bound in VAEs can be rewritten as ELBO=𝔼[logp(x)]𝖨q(x;z)𝖣KL(q(z)p(z)), revealing that the ELBO trades off reconstruction quality against the mutual information between x and z under the encoder q.

  • Representation learning: good representations should have high mutual information with downstream tasks while discarding irrelevant details (the “information bottleneck” principle).

Fisher Divergence and Score Matching

The divergences discussed so far require evaluating probability densities. The Fisher divergence takes a radically different approach: it compares distributions through their gradients (scores), avoiding the need for normalisation constants entirely.

Definition 10 (Score Function).

The score function (or score) of a distribution with density p(x) is the gradient of the log-density: (Score)sp(x)=xlogp(x)=xp(x)p(x).

The score function points in the direction of steepest ascent of the log-density; intuitively, it points “towards the data.” Crucially, it does not depend on the normalisation constant of p: if p(x)=p~(x)/Z, then xlogp(x)=xlogp~(x).

Example 16 (Score of a Gaussian).

For p(x)=𝒩(μ,σ2), sp(x)=ddx[(xμ)22σ2logσ12log2π]=xμσ2. The score points towards the mean μ: positive when x<μ (“go right”) and negative when x>μ (“go left”). Points far from the mean have larger score magnitude; they are “more strongly pulled” towards the centre.

Definition 11 (Fisher Divergence).

The Fisher divergence between distributions p and q is (Fisher)𝖣F(pq)=𝔼xp[xlogp(x)xlogq(x)2]=𝔼xp[sp(x)sq(x)2].

Example 17 (Fisher Divergence between Gaussians).

For p=𝒩(μ1,σ2) and q=𝒩(μ2,σ2) (same variance), 𝖣F(pq)=𝔼xp[(μ2μ1σ2)2]=(μ1μ2)2σ4. The Fisher divergence is proportional to the squared distance between the means, scaled by the inverse fourth power of the standard deviation; sharper distributions amplify the divergence.

Proposition 6 (Properties of Fisher Divergence).

  1. 𝖣F(pq)0, with equality iff p=q (under mild regularity conditions).

  2. 𝖣F does not require computing the normalisation constants of p or q, only their score functions.

  3. 𝖣F involves only first-order derivatives, making it amenable to gradient-based optimisation.

Score Matching

Directly computing 𝖣F(pdataqθ) requires access to spdata(x)=xlogpdata(x), which we do not know. Hyvärinen's score matching objective [19] circumvents this via integration by parts.

Theorem 8 (Hyvärinen's Score Matching Identity).

Under suitable regularity conditions (in particular, p(x)sqθ(x)0 as x), (Score Matching)𝖣F(pqθ)=𝔼xp[trace(xsqθ(x))+12sqθ(x)2]+C, where C is a constant independent of θ and xsqθ is the Jacobian of the model's score [19].

The key point is that the right-hand side depends only on the model's score sqθ and samples from the data; we never need to know spdata explicitly.

Denoising Score Matching

In practice, computing trace(xsqθ) is expensive in high dimensions (it requires computing diagonal entries of the Jacobian). Vincent [22] showed that adding noise provides a much cheaper alternative.

Theorem 9 (Denoising Score Matching).

Let x~=x+σϵ with ϵ𝒩(0,I). Define the noised density pσ(x~)=p(x)𝒩(x~;x,σ2I)dx. Then (DSM)arg minθ𝔼xp𝔼ϵ𝒩(0,I)[sθ(x~)+ϵσ2]=arg minθ𝖣F(pσqθ). At the optimal θ, sθ(x~)x~logpσ(x~).

Key Idea.

Score matching is the foundation of diffusion models. Song and Ermon [20] showed that training a neural network sθ(x,σ) to estimate the score at multiple noise levels σ enables generation via annealed Langevin dynamics: starting from pure noise and gradually reducing σ while following the estimated score.

Ho et al. [21] (DDPM) showed that this is equivalent to training a denoiser ϵθ(xt,t) that predicts the noise added at each diffusion step, the connection being sθ(xt,t)=ϵθ(xt,t)/σt. The entire training pipeline of modern diffusion models (Stable Diffusion, DALL-E, etc.) rests on the Fisher divergence and denoising score matching.

Choosing a Divergence for Generative Modelling

Each divergence has strengths and weaknesses. tab:divergence-comparison summarises the trade-offs.

lcccl@ DivergenceMetric?Disjoint OK?Needs density?Used by
𝖣KL (fwd)NoNo (=)YesMLE, VAE
𝖣KL (rev)NoNo (=)YesVI, wake-sleep
𝖣JSNoFinite but flatYesOriginal GAN
𝖣TVYesFinite but flatYesTheory
W1 (Wasserstein)YesYes (smooth)NoWGAN
𝖣F (Fisher)NoN/A (uses scores)Scores onlyDiffusion
Comparison of divergences for generative modelling. “Disjoint OK?” indicates behaviour when P and Q have non-overlapping support. “Needs density?” indicates whether evaluating p(x) or q(x) is required.

Remark 8 (No Single Best Divergence).

There is no universally “best” divergence. The choice depends on the model architecture and the computational budget:

  • If the model provides a tractable density (autoregressive, flow), use forward KL (MLE).

  • If the model is implicit (GAN), use Wasserstein or JS.

  • If the model is a score network (diffusion), use Fisher divergence via denoising score matching.

  • For variational inference with an approximate posterior, use reverse KL.

Understanding why each model uses a particular divergence is the key to understanding its strengths and failure modes.

Remark 9 (A Curious Unification).

It is a remarkable fact that the seemingly different training objectives used by GANs, VAEs, and diffusion models can all be understood as minimising different divergences between the same pair of distributions. The entire landscape of modern generative modelling can be organised by the single question: which divergence are you minimising? This chapter gives you the vocabulary to answer that question for any model you encounter.

Exercises

Exercise 1 (Non-Negativity of KL via Jensen's Inequality).

Prove that 𝖣KL(PQ)0 using Jensen's inequality applied to the concave function log. When does equality hold?

Exercise 2 (KL between Discrete Distributions).

Let P=(0.5,0.3,0.2) and Q=(0.1,0.6,0.3) on {1,2,3}. Compute: (a) 𝖣KL(PQ), (b) 𝖣KL(QP), (c) 𝖣JS(PQ), and (d) 𝖣TV(P,Q). Verify that 𝖣KL(PQ)𝖣KL(QP).

Exercise 3 (KL between Univariate Gaussians).

Let P=𝒩(μ1,σ12) and Q=𝒩(μ2,σ22). Derive the closed-form expression . Specialise to σ1=σ2=σ and interpret the result geometrically.

Exercise 4 (JS Entropy Representation).

Prove that 𝖣JS(PQ)=𝖧(M)12𝖧(P)12𝖧(Q) where M=12(P+Q). Use this to show 0𝖣JSlog2.

Exercise 5 (Disjoint Support).

Let P and Q have disjoint supports. Compute 𝖣KL(PQ), 𝖣JS(PQ), 𝖣TV(P,Q), and W1(P,Q) (for P=δ0, Q=δt on ). Explain why only Wasserstein provides a useful gradient signal for training.

Exercise 6 (TV as f-Divergence).

Show that 𝖣TV(P,Q)=𝖣f(PQ) with generator f(t)=12|t1|. Verify that f is convex and f(1)=0.

Exercise 7 (Pinsker's Inequality Application).

A model achieves 𝖣KL(pdatapθ)=0.02 nats. Use Pinsker's inequality to bound the total variation distance. If you have n=10,000 test samples, approximately how many would you expect to be “misclassified” by a hypothesis test between pdata and pθ?

Exercise 8 (Data Processing Inequality).

Let P and Q be distributions on images, and let T be a Gaussian blur operator. Explain intuitively why 𝖣f(TPTQ)𝖣f(PQ). What does this imply about evaluating generative models using blurred images?

Exercise 9 (Kantorovich–Rubinstein in Practice).

Explain why the Kantorovich–Rubinstein duality ((KR)) requires f to be 1-Lipschitz rather than merely bounded. In WGAN, the critic network fw is constrained to be approximately 1-Lipschitz. Describe two practical methods for enforcing this constraint and discuss their trade-offs.

Exercise 10 (Score Matching Derivation).

Starting from 𝖣F(pqθ)=𝔼p[spsqθ2], expand the square and use integration by parts to derive Hyvärinen's identity . State clearly the boundary conditions needed for the integration by parts to work.

Exercise 11 (Forward vs. Reverse KL).

Let p(x)=0.5𝒩(3,0.5)+0.5𝒩(3,0.5) be a bimodal distribution, and let qθ=𝒩(μ,σ2) be a single Gaussian.

  1. Find arg minμ,σ2𝖣KL(pqθ) (forward KL). Describe the fitted qθ.

  2. Argue qualitatively what arg minμ,σ2𝖣KL(qθp) (reverse KL) looks like.

  3. Relate your findings to the mode-covering vs. mode-seeking behaviour discussed in Forward vs. Reverse KL Divergence.

Exercise 12 (Mutual Information and Independence).

Prove that 𝖨(X;Y)0 with equality iff X and Y are independent. Then show that 𝖨(X;Y)=𝖧(X)+𝖧(Y)𝖧(X,Y) and use this to argue that mutual information measures the “redundancy” between X and Y.

Exercise 13 (Comparing Divergences Numerically).

Let P=𝒩(0,1) and Qt=𝒩(t,1) for t{0,0.5,1,2,5}. Compute 𝖣KL(PQt), W2(P,Qt), and 𝖣F(PQt) for each value of t using the closed-form expressions derived in this chapter. Hint: For equal-variance Gaussians, 𝖣KL=(μ1μ2)2/(2σ2), W2=|μ1μ2|, and 𝖣F=(μ1μ2)2/σ4. Plot all three as functions of t and discuss their different scaling behaviours.

Exercise 14 (Wasserstein between Gaussians).

Verify (W2 Gaussian): for P=𝒩(0,1) and Q=𝒩(2,4), compute W2(P,Q) using the closed form. Compare with 𝖣KL(PQ) and comment on which measure is more “geometrically natural.”

References

  1. A mathematical theory of communication

    Claude Elwood Shannon

    The Bell System Technical Journal, vol. 27, no. 3, pp. 379-423 · 1948

    BibTeX
    @article{shannon1948mathematical,
      title={A mathematical theory of communication},
      author={Shannon, Claude Elwood},
      journal={The Bell System Technical Journal},
      volume={27},
      number={3},
      pages={379--423},
      year={1948},
      publisher={Nokia Bell Labs}
    }

    Journal article

  2. On information and sufficiency

    Solomon Kullback, Richard A Leibler

    The annals of mathematical statistics, vol. 22, no. 1, pp. 79-86 · 1951

    BibTeX
    @article{kullback1951information,
      title={On information and sufficiency},
      author={Kullback, Solomon and Leibler, Richard A},
      journal={The annals of mathematical statistics},
      volume={22},
      number={1},
      pages={79--86},
      year={1951},
      publisher={Institute of Mathematical Statistics}
    }

    Journal article

  3. Divergence measures based on the Shannon entropy

    Jianhua Lin

    IEEE Transactions on Information theory, vol. 37, no. 1, pp. 145-151 · 1991

    BibTeX
    @article{lin1991divergence,
      title={Divergence measures based on the Shannon entropy},
      author={Lin, Jianhua},
      journal={IEEE Transactions on Information theory},
      volume={37},
      number={1},
      pages={145--151},
      year={1991},
      publisher={IEEE}
    }

    Journal article

  4. Generative Adversarial Networks

    Ian Goodfellow, Jean Pouget-Abadie, Mehdi Mirza, Bing Xu, David Warde-Farley, Sherjil Ozair, Aaron Courville, Yoshua Bengio

    Advances in Neural Information Processing Systems, vol. 27 · 2014

    BibTeX
    @inproceedings{goodfellow2014generative,
      title={Generative Adversarial Networks},
      author={Goodfellow, Ian and Pouget-Abadie, Jean and Mirza, Mehdi and Xu, Bing and Warde-Farley, David and Ozair, Sherjil and Courville, Aaron and Bengio, Yoshua},
      booktitle={Advances in Neural Information Processing Systems},
      volume={27},
      year={2014}
    }

    Conference paper

  5. Towards principled methods for training generative adversarial networks

    Martin Arjovsky, Leon Bottou

    arXiv preprint arXiv:1701.04862 · 2017

    BibTeX
    @article{arjovsky2017towards,
      title={Towards principled methods for training generative adversarial networks},
      author={Arjovsky, Martin and Bottou, L{\'e}on},
      journal={arXiv preprint arXiv:1701.04862},
      year={2017}
    }

    Journal article

  6. Wasserstein GAN

    Martin Arjovsky, Soumith Chintala, Leon Bottou

    arXiv:1701.07875 · 2017

    BibTeX
    @article{arjovsky2017wasserstein,
        title = {Wasserstein GAN},
        author = {Arjovsky, Martin and Chintala, Soumith and Bottou, L\'eon},
        journal = {arXiv:1701.07875},
        year = {2017}
    }

    Journal article

  7. Eine informationstheoretische Ungleichung und ihre Anwendung auf den Beweis der Ergodizitat von Markoffschen Ketten

    Imre Csiszar

    Magyar Tud. Akad. Mat. Kutato Int. Kozl, vol. 8, pp. 85-108 · 1963

    BibTeX
    @article{csiszar1963information,
      title={Eine informationstheoretische Ungleichung und ihre Anwendung auf den Beweis der Ergodizit{\"a}t von Markoffschen Ketten},
      author={Csisz{\'a}r, Imre},
      journal={Magyar Tud. Akad. Mat. Kutat{\'o} Int. K{\"o}zl},
      volume={8},
      pages={85--108},
      year={1963}
    }

    Journal article

  8. A general class of coefficients of divergence of one distribution from another

    Syed Mumtaz Ali, Samuel D. Silvey

    Journal of the Royal Statistical Society: Series B (Methodological), vol. 28, no. 1, pp. 131-142 · 1966

    BibTeX
    @article{ali1966general,
      title={A general class of coefficients of divergence of one distribution from another},
      author={Ali, Syed Mumtaz and Silvey, Samuel D.},
      journal={Journal of the Royal Statistical Society: Series B (Methodological)},
      volume={28},
      number={1},
      pages={131--142},
      year={1966}
    }

    Journal article

  9. f-GAN: Training generative neural samplers using variational divergence minimization

    Sebastian Nowozin, Botond Cseke, Ryota Tomioka

    Advances in Neural Information Processing Systems, vol. 29 · 2016

    BibTeX
    @inproceedings{nowozin2016fgan,
      title={f-GAN: Training generative neural samplers using variational divergence minimization},
      author={Nowozin, Sebastian and Cseke, Botond and Tomioka, Ryota},
      booktitle={Advances in Neural Information Processing Systems},
      volume={29},
      year={2016}
    }

    Conference paper

  10. Information and Information Stability of Random Variables and Processes

    Mark S. Pinsker

    Holden-Day · 1964

    BibTeX
    @book{pinsker1964information,
      title={Information and Information Stability of Random Variables and Processes},
      author={Pinsker, Mark S.},
      publisher={Holden-Day},
      year={1964},
      address={San Francisco}
    }

    Book

  11. Memoire sur la theorie des deblais et des remblais

    Gaspard Monge

    Memoires de l'Academie Royale des Sciences de Paris, pp. 666-704 · 1781

    BibTeX
    @article{monge1781memoire,
      title={M{\'e}moire sur la th{\'e}orie des d{\'e}blais et des remblais},
      author={Monge, Gaspard},
      journal={M{\'e}moires de l'Acad{\'e}mie Royale des Sciences de Paris},
      pages={666--704},
      year={1781}
    }

    Journal article

  12. On the translocation of masses

    L. V. Kantorovich

    C. R. (Doklady) Acad. Sci. URSS (N.S.), vol. 37, pp. 199-201 · 1942

    BibTeX
    @article{kantorovich1942translocation,
      title={On the translocation of masses},
      author={Kantorovich, L. V.},
      journal={C. R. (Doklady) Acad. Sci. URSS (N.S.)},
      volume={37},
      pages={199--201},
      year={1942}
    }

    Journal article

  13. Markov processes over denumerable products of spaces, describing large systems of automata

    Leonid N. Vasershtein

    Problemy Peredachi Informatsii, vol. 5, no. 3, pp. 64-72 · 1969

    BibTeX
    @article{vasershtein1969markov,
      title={Markov processes over denumerable products of spaces, describing large systems of automata},
      author={Vasershtein, Leonid N.},
      journal={Problemy Peredachi Informatsii},
      volume={5},
      number={3},
      pages={64--72},
      year={1969}
    }

    Journal article

  14. Optimal Transport: Old and New

    Cedric Villani

    Springer-Verlag · 2008

    BibTeX
    @book{villani2008optimal,
        title = {Optimal Transport: Old and New},
        author = {Villani, C\'edric},
        year = {2008},
        publisher = {Springer-Verlag}
    }

    Book

  15. Improved training of Wasserstein GANs

    Ishaan Gulrajani, Faruk Ahmed, Martin Arjovsky, Vincent Dumoulin, Aaron C Courville

    Advances in neural information processing systems, pp. 5767-5777 · 2017

    BibTeX
    @inproceedings{gulrajani2017improved,
      title={Improved training of Wasserstein GANs},
      author={Gulrajani, Ishaan and Ahmed, Faruk and Arjovsky, Martin and Dumoulin, Vincent and Courville, Aaron C},
      booktitle={Advances in neural information processing systems},
      pages={5767--5777},
      year={2017}
    }

    Conference paper

  16. Spectral normalization for generative adversarial networks

    Takeru Miyato, Toshiki Kataoka, Masanori Koyama, Yuichi Yoshida

    Proceedings of the International Conference on Learning Representations · 2018

    BibTeX
    @inproceedings{miyato2018spectral,
      title={Spectral normalization for generative adversarial networks},
      author={Miyato, Takeru and Kataoka, Toshiki and Koyama, Masanori and Yoshida, Yuichi},
      booktitle={Proceedings of the International Conference on Learning Representations},
      year={2018},
      url={https://openreview.net/forum?id=B1QRgziT-}
    }

    Conference paper

  17. Sinkhorn Distances: Lightspeed Computation of Optimal Transport

    Marco Cuturi

    Advances in Neural Information Processing Systems · 2013

    BibTeX
    @inproceedings{cuturi2013sinkhorn,
      title={Sinkhorn Distances: Lightspeed Computation of Optimal Transport},
      author={Cuturi, Marco},
      booktitle={Advances in Neural Information Processing Systems},
      year={2013}
    }

    Conference paper

  18. InfoGAN: Interpretable representation learning by information maximizing generative adversarial nets

    Xi Chen, Yan Duan, Rein Houthooft, John Schulman, Ilya Sutskever, Pieter Abbeel

    Advances in Neural Information Processing Systems, vol. 29 · 2016

    BibTeX
    @inproceedings{chen2016infogan,
      title={InfoGAN: Interpretable representation learning by information maximizing generative adversarial nets},
      author={Chen, Xi and Duan, Yan and Houthooft, Rein and Schulman, John and Sutskever, Ilya and Abbeel, Pieter},
      booktitle={Advances in Neural Information Processing Systems},
      volume={29},
      year={2016}
    }

    Conference paper

  19. Estimation of non-normalized statistical models by score matching

    Aapo Hyvarinen

    Journal of Machine Learning Research, vol. 6, pp. 695-709 · 2005

    BibTeX
    @article{hyvarinen2005estimation,
      title={Estimation of non-normalized statistical models by score matching},
      author={Hyv{\"a}rinen, Aapo},
      journal={Journal of Machine Learning Research},
      volume={6},
      pages={695--709},
      year={2005}
    }

    Journal article

  20. Generative modeling by estimating gradients of the data distribution

    Yang Song, Stefano Ermon

    Advances in Neural Information Processing Systems, vol. 32 · 2019

    BibTeX
    @inproceedings{song2019generative,
      title={Generative modeling by estimating gradients of the data distribution},
      author={Song, Yang and Ermon, Stefano},
      booktitle={Advances in Neural Information Processing Systems},
      volume={32},
      year={2019}
    }

    Conference paper

  21. Denoising Diffusion Probabilistic Models

    Jonathan Ho, Ajay Jain, Pieter Abbeel

    Advances in Neural Information Processing Systems, vol. 33, pp. 6840-6851 · 2020

    BibTeX
    @inproceedings{ho2020denoising,
      title={Denoising Diffusion Probabilistic Models},
      author={Ho, Jonathan and Jain, Ajay and Abbeel, Pieter},
      booktitle={Advances in Neural Information Processing Systems},
      volume={33},
      pages={6840--6851},
      year={2020}
    }

    Conference paper

  22. A connection between score matching and denoising autoencoders

    Pascal Vincent

    Neural Computation, vol. 23, no. 7, pp. 1661-1674 · 2011

    BibTeX
    @article{vincent2011connection,
      title={A connection between score matching and denoising autoencoders},
      author={Vincent, Pascal},
      journal={Neural Computation},
      volume={23},
      number={7},
      pages={1661--1674},
      year={2011}
    }

    Journal article