Module 11. Comparing distributions: f-divergences, variational critics, and Wasserstein distance
How to read this module. The main route is Sections 11.1–11.9. We first build the family of f-divergences, then show how classifiers and variational critics recover density ratios from samples. The same mechanism leads to GANs, f-GAN, MINE, and InfoNCE. Section 11.8 changes the lens and adds geometry through IPMs, Wasserstein distance, and MMD. Section 11.10 is an optional mathematical deepening on singular measure components, joint convexity, and the exact conditions behind the dual representation.
11.1. From two sample sets to a distribution-comparison problem
KL has been the workhorse of the preceding modules. It appeared in cross-entropy, mutual information, the ELBO, the Information Bottleneck, KL-regularized policies, and MDL. Modern ML often presents a more awkward situation, however: we can sample from two distributions but cannot evaluate their densities.
This is the usual setting for an implicit generator. It can quickly produce
while the pointwise value is typically unavailable. The expression
is still mathematically meaningful, but it does not directly become a computable loss.
Consider a much smaller example. A first source emits and with probabilities
and a second source emits them with probabilities
If the two sources are equally likely a priori, the optimal source classifier returns
Its logits are and . This already hints at the central mechanism: an ideal classifier does more than distinguish two sample sets; it encodes their probability ratio. We derive the exact statement in Section 11.4.
The same pattern occurs in many ML problems:
- the data distribution is compared with a generator distribution ;
- the joint distribution is compared with the product when estimating mutual information;
- representation distributions are compared before and after distribution shift;
- two sample sets are compared in a two-sample test;
- a reference policy is compared with an updated policy.
These settings raise three separate questions.
- What should count as distributional error? Missing mass, extra mass, and geometric displacement are not the same failure.
- How can the discrepancy be estimated from samples? This is where classifiers and variational critics enter.
- Does the sample space itself carry useful geometry? f-divergences use probability ratios, whereas Wasserstein distance also uses distances between points.

The main construction of the module is:
A variational critic turns an inaccessible density ratio into a trainable sample-based problem.
It helps to see the whole ladder before studying its steps:
The first arrow may leave a variational gap if the function class is too small. The second adds statistical and optimization error. This does not make critics useless; it tells us exactly what quantity a training run has produced.
Unless stated otherwise, logarithms are natural and logarithmic quantities are measured in nats.
11.2. f-divergences: one template, different penalties
Let and have densities and with respect to a common base measure. Along the main route, assume for now that . Define the density ratio
It has a direct interpretation:
- : the two distributions assign the same relative mass at ;
- : under-allocates mass relative to ;
- : allocates more mass than .
Choose a convex function
It specifies how costly each density-ratio value should be. The corresponding f-divergence is
In this sense, is a penalty schedule for density-ratio errors. Different schedules yield different discrepancies.
Why the divergence is nonnegative
Because
Jensen's inequality gives
There is a useful subtlety here. The generator itself need not be nonnegative at every . What is nonnegative is its average score under the constraint . This is why equivalent generators may dip below zero without producing a negative divergence.
Equality always holds when . For the converse implication, must be sufficiently strictly convex on the realized range of .
Main examples
We use the following normalization throughout the course:
| Discrepancy | Generator | Explicit form |
|---|---|---|
| Forward KL | ||
| Reverse KL | ||
| Pearson | ||
| Squared Hellinger distance | ||
| Total variation (TV) | ||
| Jensen–Shannon | , |
With this normalization,

Why the generator is not unique
Replacing by
does not change the divergence, because
Hence
This is why tables sometimes display different-looking formulas for the same discrepancy: the formulas differ by a linear term that vanishes after averaging.
A neighboring family: power and Rényi divergences
For , the convex generator
defines a family of power f-divergences. The limits and give generators that are affine-equivalent to forward and reverse KL.
For , , Rényi divergence,
is a monotone transformation of the corresponding power f-divergence and therefore induces the same ordering of distribution pairs for fixed , but it does not generally have the form . Properties of all f-divergences cannot be transferred to Rényi divergence merely because the notation looks similar.
11.3. What f-divergences can see
An f-divergence tracks how one probability measure reweights another. The construction explains both its strength and its natural boundary.
Processing cannot increase distinguishability
Apply the same stochastic channel to and , and denote the output distributions by and . Then
This is the data processing inequality.
The short proof exposes the mechanism. Let
The output density ratio is the conditional mean of the input ratio:
Conditional Jensen therefore gives
That is the entire mechanism: the channel replaces the exact ratio by a conditional average. Averaging smooths distinctions, and convexity prevents the average penalty from increasing.
For a representation , the conclusion is that a fixed encoder cannot make two groups more distinguishable at the population-distribution level than they were in the input. A restricted linear probe may nevertheless perform much better on than on : the encoder can make an existing distinction easier for the chosen readout class to access.

Invariance under invertible reparameterization
If is a measurable bijection with a measurable inverse, then
Under a smooth coordinate change, the Jacobian factors cancel in the density ratio. Thus an f-divergence is unaffected by describing the same objects in original coordinates, normalized coordinates, or any other invertible representation.
This is a powerful invariance. It also reveals a limitation: an f-divergence does not use external geometry. It knows how probabilities compare, but not whether two different points are close in Euclidean, cosine, or perceptual distance.
What the choice of changes
For a fixed direction , large values of
mark regions where underestimates . Small values mark regions where assigns more mass than .
Different generators weight these two errors differently. In a restricted model family, they can therefore select different projections of the same target distribution:
- forward KL heavily penalizes regions with substantial -mass that receive tiny probability under ;
- reverse KL heavily penalizes -mass in regions where is nearly absent;
- bounded divergences such as JS, Hellinger, and TV gradually saturate under severe mismatch.
This yields the familiar mode-covering versus mode-seeking heuristic. Module 3 showed it when a single Gaussian approximated a mixture. The precise statement is about a projection into a restricted family, not a universal law of every optimizer whose loss contains the same acronym.
Disjoint supports
Suppose and are mutually singular. Common f-divergences then reach their boundary values:
while forward KL and Pearson become infinite in the corresponding directions.
The numbers are different. What they share is that they no longer report how far apart the supports are. Supports separated by and by may receive the same JS value. Section 11.8 recovers this missing geometry through Wasserstein distance.
11.4. Classification as density-ratio estimation
We now return to the source-classification game from the opening and derive it exactly.
Construct a binary sample:
- with probability , draw and set ;
- with probability , draw and set .
Bayes' rule gives the optimal probabilistic classifier:
Taking odds,
and hence
For equal class priors, the prior-odds term disappears:

In the two-point example from Section 11.1,
so
The ideal classifier recovers exactly the log-ratio required by KL and many related divergences.
This is a central tool in likelihood-free inference: instead of estimating two densities separately, we estimate one function that distinguishes their samples.
Two tasks must still be separated:
- source classification requires the correct decision or ranking;
- density-ratio estimation also requires calibrated probabilities.
With nearly separable classes, accuracy can be perfect while logits are arbitrarily overconfident. High classification accuracy confirms that the samples are distinguishable, but it does not by itself provide an accurate numerical estimate of .
11.5. Variational form: making a discrepancy trainable
Classification gave one route to a density ratio. We now derive a mechanism that works for the entire family of f-divergences.
From Fenchel's inequality to a lower bound
For convex , define the convex conjugate
The definition implies Fenchel's inequality,
for every admissible . Choose pointwise and set :
Multiply by and integrate:
Thus every admissible function gives a lower bound:
With a sufficiently rich function class and the appropriate regularity conditions, taking the supremum yields
For differentiable strictly convex , the pointwise optimizer satisfies
If is invertible, the ideal critic recovers the density ratio:

The critic's role is now exact. It need not output a class probability; in general, it learns the transformation of the density ratio selected by .
From the theorem to a neural training run
Let be a restricted critic class, such as a fixed neural architecture. Then
A practical run adds three more approximations:
- population expectations are replaced by finite-sample averages;
- optimization does not find the best critic even within ;
- the same data are often used both to fit the critic and to report its value.
The third point is especially important. For a fixed , the population objective is a lower bound. The maximum empirical objective over a flexible class can overfit and exceed the population divergence. A sound protocol separates critic training from held-out evaluation and includes a permutation baseline.
KL: the NWJ and Donsker–Varadhan forms
For forward KL, take
Its conjugate is
The general formula becomes
In the mutual-information estimation literature, this is often called the Nguyen–Wainwright–Jordan, or NWJ, form. Its optimal critic is
Another exact representation is Donsker–Varadhan:
The relationship is easier to derive than to memorize. Substitute into the NWJ objective:
The optimum over the free shift is
Substitution leaves the DV objective. Consequently, the optimal DV critic is defined only up to an additive constant:
Both formulas are exact at the population level, but their finite-sample estimators behave differently. The exponential and the logarithm of a normalization average make the DV objective particularly sensitive to rare large critic values.
11.6. GAN and f-GAN
The adversarial game now stops looking like an isolated trick. It is one way to fit a variational critic while simultaneously moving the distribution being compared with the data.
The original minimax GAN
Goodfellow et al. use the objective
For a fixed generator, the pointwise optimum is
Let
Substituting the optimal discriminator gives

This is a strong and exact statement: the idealized minimax game with an optimal discriminator compares the data and generator distributions through Jensen–Shannon divergence.
Actual training solves the inner problem only approximately. The generator belongs to a restricted parametric family, and the commonly used non-saturating loss
replaces the original saturating objective to provide a stronger early gradient. The desired fixed point is preserved, but an individual generator update is no longer literal gradient descent on exact JS.
f-GAN
The general variational representation replaces JS by another f-divergence:
If the critic class is sufficiently rich and the inner maximum is solved, the inner value equals
Some conjugates have restricted domains. f-GAN therefore maps an unconstrained network output through
so that

The choice of changes several parts of the problem:
- the projection selected within a restricted generator family;
- the shape and curvature of the critic loss;
- the admissible critic output range;
- sensitivity to different density-ratio regimes;
- the bias–variance tradeoff of the estimator.
It is useful to separate two levels. In the idealized population problem, the divergence defines the destination. In an actual GAN, saddle-point dynamics determine whether training approaches it. Mode collapse, oscillations, and instability depend not only on , but also on architecture, regularization, relative learning rates, and the generator's surrogate loss.
11.7. MINE and InfoNCE
Mutual information is already a distribution-comparison problem:
The joint distribution supplies genuine pairs . The product of marginals supplies independently assembled pairs. Estimating MI can therefore be turned into distinguishing associated pairs from shuffled ones.
MINE: a DV critic for joint versus product
MINE substitutes these distributions into the Donsker–Varadhan representation:
Positive pairs come from the joint distribution. Samples from the product of marginals can be formed by independently resampling and ; shuffling within a minibatch is a common approximation.
The population expression is simple, but finite-sample estimation is difficult because of the exponential. Rare large critic values can dominate the normalization term and create high variance. The original MINE procedure used a moving average to stabilize the gradient of that term.
A useful protocol separates three steps:
- train the critic on training pairs;
- evaluate the objective on held-out pairs;
- use a permutation experiment to verify that the estimate returns to its null baseline when dependence is destroyed.
InfoNCE: choosing the positive candidate
InfoNCE uses a different game. For each , one candidate is drawn from , while
are negative candidates. The critic must identify the positive pair:
Under this sampling scheme,
The optimal score has the form
so the same density ratio appears again.

For example, and a loss of nats give
This is an MI lower bound under the specified sampling scheme, not a standalone measurement of all information in the representation.
One density ratio, different sample objectives
MINE and InfoNCE converge toward related optimal score functions, but they construct different variational problems:
- MINE uses the DV functional with an exponential expectation;
- InfoNCE solves a -way positive-candidate classification problem.
Calling InfoNCE “MINE with a small bias” therefore hides the actual distinction.
InfoNCE has an explicit ceiling:
Increasing raises the ceiling and can tighten the bound under an ideal critic. Representation learning, however, depends on more than the reported bound: false negatives, augmentations, compute, and optimization difficulty can all change downstream quality.
This leads to an important distinction:
A variational bound can be a useful training signal even when its numerical value is a poor absolute MI meter.
When true MI is large, neural lower bounds face a bias–variance tradeoff. More broadly, without additional assumptions, a distribution-free high-confidence lower bound from observations cannot reliably grow much faster than order . This limits statistical certification; it does not forbid using a contrastive objective as a learning signal.
11.8. Integral probability metrics: Wasserstein distance and MMD
f-divergences quantify probability reweighting. Some tasks must also distinguish a nearby mismatch from a distant one.
Two moving point masses
Let
For every , the supports are disjoint, so
and both KL directions are infinite. These values do not change as moves from to .
Wasserstein-1 does see the displacement:

The example motivates a different language: rather than starting from a density ratio, start from a class of test functions that is sensitive to the relevant geometry.
Integral probability metrics
For a symmetric function class , define
The class determines which discrepancies the critic can observe. A class that is too simple misses differences; a very rich class is harder to estimate and optimize.
Wasserstein-1
Let the sample space carry a metric , and assume and have finite first moments. For the class of all 1-Lipschitz functions, Kantorovich–Rubinstein duality gives
The same quantity has the transport form
Here is the set of couplings with marginals and . The first formula describes the best 1-Lipschitz critic; the second describes the minimum average cost of transporting probability mass.
Wasserstein distance depends on the ground metric. Multiplying all coordinates by one hundred changes the transport cost. That is not a defect: the metric states which displacements the problem considers small.
WGAN
Wasserstein GAN trains a critic with the objective
The inner maximum equals in the ideal problem. The main engineering challenge is enforcing the Lipschitz condition.
The original WGAN used weight clipping. WGAN-GP replaced clipping with the penalty
on interpolated points. This often gives a better-behaved training problem, but it is not a global certificate that the neural critic is 1-Lipschitz everywhere.
The positive result of WGAN is not a promise that every run converges. It is a population discrepancy with more informative geometry for nearby disjoint supports. Practical performance still depends on the critic class, the Lipschitz-control mechanism, and optimization dynamics.
MMD: a kernel-defined critic class
If is the unit ball of a reproducing-kernel Hilbert space , the IPM becomes maximum mean discrepancy:
Its square can be computed without an inner neural optimization:
For a characteristic kernel, MMD if and only if . The Gaussian kernel
is characteristic on Euclidean space. Its bandwidth determines the scale of visible differences: an overly small bandwidth sees only local coincidences, while an overly large one smooths away structure.
MMD is useful for two-sample testing and shift detection. Its empirical estimate is built from pairwise kernel evaluations and requires no adversarial inner loop. The tradeoff is that the kernel must encode a meaningful notion of similarity, and the naive estimator has quadratic sample complexity in time.
The families overlap
f-divergences and IPMs are not disjoint boxes. Total variation has both representations:
and
The useful distinction is the mechanism:
- an f-divergence obtains its geometry from the density ratio and the function ;
- an IPM obtains its geometry from the test-function class .
11.9. Choosing a discrepancy in practice
There is no universally best discrepancy. The choice begins with what the system can observe and what it should count as an error.
| Setting | Natural first candidate | What to check |
|---|---|---|
| Normalized likelihood is available | KL / NLL / MLE | KL direction, support, and model misspecification |
| Only samples from and are available | classifier ratio estimation or a variational f-bound | critic capacity, calibration, and held-out evaluation |
| An implicit generator is trained | GAN/f-GAN or an IPM | generator surrogate and saddle-point dynamics |
| Geometric proximity of supports matters | Wasserstein distance | the ground metric and Lipschitz control |
| A two-sample test is needed | MMD or a classifier test | select the kernel or critic without test-set leakage |
| MI is used as a training objective | InfoNCE, NWJ, DV, or related bounds | negative sampling, bias–variance, and bound versus MI |
Four questions provide a useful decision procedure.
1. What can be computed?
Are and available, or only samples? Can gradients flow through the generator? Does the problem naturally provide positive and negative pairs?
2. Which error matters?
Should the objective heavily penalize missing mass, extra mass, geometric displacement, selected moments, or any distinction visible to a chosen test-function class?
3. What is actually being optimized?
An exact discrepancy, a variational lower bound, a finite-sample estimator, and a generator surrogate are different objects. They may share an ideal optimum while having different training trajectories and statistical behavior.
4. How will the result be checked?
A critic value should be complemented by independent evidence: a held-out objective, a downstream metric, domain-specific inspection, a permutation baseline, or sensitivity across kernels and critic classes.
The practical principle is more useful than a slogan about the “best distance”:
A good discrepancy aligns the meaning of error, the available estimator, and the geometry of the model's sample space.
11.10. Mathematical deepening: general measures and exact duality
Optional on a first pass. This section makes precise the places where the main route assumed densities with .
General f-divergence and the singular part
Let and be dominated by a measure :
Define the boundary values
The extended f-divergence is
The value does not depend on the chosen dominating measure. If , then
This immediately yields the boundary values:
- TV: ;
- squared Hellinger distance in our normalization: ;
- JS: ;
- forward KL and Pearson : .
Joint convexity
The two-variable function
is the perspective of the convex function and is jointly convex in . Integrating gives, for ,
This formalizes a simple idea: mixing two comparison problems cannot create more discrepancy than their average pre-mixture score.
When the variational supremum is exact
The identity
requires convexity and lower semicontinuity of , a correct domain for , a sufficiently rich measurable function class, and conditions that justify the pointwise optimizer and the interchange of integration with the supremum.
For differentiable ,
For nondifferentiable generators such as TV, the derivative is replaced by a subgradient condition:
A neural critic class is almost always smaller than the full measurable function class. The optimized expression in code should therefore be called a variational lower bound unless tightness has been established for the chosen architecture and procedure.
11.12. Conclusion
KL led us into this module, but the resulting picture is broader than one divergence.
f-divergences collect a large class of discrepancies into one expression:
The function determines how different density-ratio errors are priced. Data processing explains why a fixed transformation cannot increase population distinguishability, while saturation on disjoint supports shows where a density-ratio view loses external geometry.
Fenchel duality turns an inaccessible discrepancy into a trainable problem:
Ideally, the critic recovers a transformation of . In a real run, it operates in a restricted class, on finite data, and with finite optimization. A critic value is therefore useful to the extent that this protocol is stated clearly.
The same mechanism connects several methods that initially look unrelated:
- a probabilistic classifier estimates a log density ratio;
- the original minimax GAN is linked to JS under an optimal discriminator;
- f-GAN changes and the critic's conjugate loss;
- MINE compares joint and shuffled pairs through the DV representation;
- InfoNCE solves a multi-candidate classification problem whose optimal score contains the same ratio.
When distances between points matter in their own right, the language changes. Wasserstein distance uses transport cost in a ground metric, whereas MMD measures distinguishability by a kernel-defined test-function class.
The engineering conclusion is:
Choose a discrepancy by the error it makes expensive, the estimator you can actually run, and the geometry your task needs—not by the reputation of its name.
Module 12 will use the same variational apparatus in a different role. KL will measure how far a data-dependent posterior moves from a prior, and PAC-Bayes will turn that cost into a generalization bound.
Primary references
- X. Nguyen, M. Wainwright, M. Jordan, Estimating Divergence Functionals and the Likelihood Ratio by Convex Risk Minimization, 2010.
- S. Nowozin, B. Cseke, R. Tomioka, f-GAN: Training Generative Neural Samplers using Variational Divergence Minimization, 2016.
- I. Goodfellow et al., Generative Adversarial Nets, 2014.
- M. Belghazi et al., MINE: Mutual Information Neural Estimation, 2018.
- A. van den Oord, Y. Li, O. Vinyals, Representation Learning with Contrastive Predictive Coding, 2018.
- B. Poole et al., On Variational Bounds of Mutual Information, 2019.
- D. McAllester, K. Stratos, Formal Limitations on the Measurement of Mutual Information, 2020.
- M. Arjovsky, S. Chintala, L. Bottou, Wasserstein GAN, 2017.
- I. Gulrajani et al., Improved Training of Wasserstein GANs, 2017.
- A. Gretton et al., A Kernel Two-Sample Test, 2012.