KL is one member of a large family. Every f-divergence compares two distributions through a convex function of their likelihood ratio, and choosing f gives KL, reverse KL, total variation, Hellinger, chi-squared or Jensen–Shannon. JS is symmetric, bounded by log 2, and its square root is a metric. You will build the family from one formula, prove the key inequalities (Pinsker, Hellinger ≤ TV), see that a GAN's optimal discriminator measures JS, and see why JS saturates and stops giving gradients when distributions are far apart.
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.
Many ways to compare two piles of sand
There are many ways to say how different two distributions are. Count the sand you’d have to move (total variation). Measure the surprise of being wrong (KL). Or ask how well a referee can tell them apart (Jensen–Shannon). Each answers a slightly different question. They all agree that identical distributions have divergence zero.
A family of divergences: p = N(0, 1) vs q = N(d, s²)
Every f-divergence is Σ q f(p/q) for a convex f with f(1) = 0. They differ in how they treat large likelihood ratios. KL is unbounded and asymmetric; JS, TV and Hellinger are symmetric and bounded. Push d past 4: JS, TV and H² flatten near their maxima, so a GAN trained on JS gets almost no gradient once the generator's samples are far from the data. That is the motivation for the Wasserstein GAN.
Why engineers care
The divergence you choose decides how a generative model trains (GAN, VAE, diffusion), how robust a hypothesis test is, and how you bound the error of a learned planner. Bounded divergences are safe to estimate; unbounded ones can explode.
📝 Quick check (Level 0)
0/3 answered
1. Jensen–Shannon divergence is…
2. JS is at most…
3. TV distance between identical distributions is…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.
f-divergences
For a convex f with f(1)=0:
Df(p∥q)=∑xq(x)f(q(x)p(x))
Divergence
f(t)
KL(p ‖ q)
tlogt
reverse KL
−logt
total variation
21∣t−1∣
Hellinger²
21(t−1)2
Pearson χ²
(t−1)2
Jensen–Shannon
21[tlogt−(1+t)log21+t]
By Jensen, Df≥f(1)=0.
Jensen–Shannon
JS(p,q)=21KL(p∥m)+21KL(q∥m),m=21(p+q)
JS is symmetric, always finite, 0≤JS≤log2, and JS is a metric (Endres and Schindelin, 2003).
📝 Quick check (Level 1)
0/3 answered
1. The KL generator is f(t) =
2. JS between distributions with disjoint supports =
3. TV((0.6, 0.3, 0.1), (0.2, 0.3, 0.5)) =
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.
Inequalities between divergences
Pinsker:TV≤KL/2 (nats).
Hellinger:H2≤TV≤2H.
Chi-squared:KL≤log(1+χ2)≤χ2.
These let you turn a KL bound from training or a PAC-Bayes argument into a bound on probabilities of events. For example, ∣P(A)−Q(A)∣≤TV for every event A.
Variational form and GANs
Every f-divergence has a dual form, Df=supTEp[T]−Eq[f∗(T)]. This is the basis of f-GAN (Nowozin, Cseke and Tomioka, 2016). For the original GAN (Goodfellow et al., 2014), the optimal discriminator is D∗=p/(p+q), and
maxDEplogD+Eqlog(1−D)=2JS(p,q)−log4
🐍 Exercise 1: the f-divergence family
Write a generic f-divergence and use it to build KL, TV, Hellinger² and χ²; also implement JS. On random distributions, check the identities, symmetry, the log 2 bound, Pinsker's inequality and the √JS triangle inequality.
📝 Quick check (Level 2)
0/3 answered
1. With KL = 0.5 nats, Pinsker bounds TV by…
2. The optimal GAN discriminator is D*(x) =
3. |P(A) − Q(A)| for any event A is at most…
Level 3: Advanced
★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.
JS ≤ log 2:KL(p∥m)=∑plogp+q2p≤∑plog2=log2, since p/(p+q)≤1. The same holds for q, and averaging gives the bound. ∎
Optimal discriminator: pointwise, plogD+qlog(1−D) is maximized at D=p/(p+q). Substituting gives KL(p∥m)+KL(q∥m)−log4. ∎
H² ≤ TV:(p−q)2≤∣p−q∣(p+q)=∣p−q∣. Sum and halve. ∎
Exercise 3.1: JS for p = (1, 0), q = (½, ½)
m=(43,41). KL(p∥m)=log34 and KL(q∥m)=21log32+21log2. In bits, JS ≈ 0.311.
📝 Quick check (Level 3)
0/3 answered
1. Non-negativity of every f-divergence follows from…
2. Value of the GAN game at the optimal discriminator:
3. Which divergence's square root is a metric?
Level 4: Expert
★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.
A discriminator measures divergence, and saturates
Train a logistic discriminator to tell real sensor readings from simulated ones. Its value gives back the JS divergence, as the exercise shows. But once the simulated distribution is far from the real one, JS is pinned at log2 and stops changing. The generator gets no gradient telling it which way to move. That observation motivated the Wasserstein GAN (Arjovsky, Chintala and Bottou, 2017), whose earth-mover distance keeps growing linearly with separation. It also explains why sim-to-real domain-adaptation critics are often trained with gradient penalties.
🐍 Exercise 2 (research): GAN discriminator as a JS estimator
Train a logistic discriminator with quadratic features on samples from two Gaussians, convert its value to a JS estimate and compare with numerical integration. Then show that JS saturates at log 2 as the separation grows.
f-divergences in AI, robotics and aerospace
Generative models: GAN (JS), f-GAN (any f), WGAN (Wasserstein). Diffusion models train on KL bounds.
Sim-to-real and domain adaptation: adversarial feature alignment minimizes a divergence between simulated and real features (Ganin et al., 2016).
Imitation learning: GAIL minimizes JS between expert and learner occupancy measures (Ho and Ermon, 2016). Other f-divergences give f-IRL variants.
Robust estimation and hypothesis testing: Hellinger and TV bound test error rates (Le Cam). χ² appears in importance-sampling variance.
References
I. Csiszár (1967). “Information-type measures of difference of probability distributions.” Studia Sci. Math. Hungarica, 2.
J. Lin (1991). “Divergence measures based on the Shannon entropy.” IEEE Transactions on Information Theory, 37(1).
D. Endres, J. Schindelin (2003). “A new metric for probability distributions.” IEEE Transactions on Information Theory, 49(7).
I. Goodfellow et al. (2014). “Generative adversarial nets.” NeurIPS.
S. Nowozin, B. Cseke, R. Tomioka (2016). “f-GAN: training generative neural samplers using variational divergence minimization.” NeurIPS.
M. Arjovsky, S. Chintala, L. Bottou (2017). “Wasserstein generative adversarial networks.” ICML.
J. Ho, S. Ermon (2016). “Generative adversarial imitation learning.” NeurIPS.
Y. Ganin et al. (2016). “Domain-adversarial training of neural networks.” JMLR, 17.
A. Tsybakov (2009). Introduction to Nonparametric Estimation. Springer. Ch. 2 (divergence inequalities).
X. Nguyen, M. Wainwright, M. Jordan (2010). “Estimating divergence functionals and the likelihood ratio by convex risk minimization.” IEEE Transactions on Information Theory, 56(11).
Every f-divergence decreases under any Markov kernel (A7-6).
Practice
Show:
Level 0
Problem 1Level 0
Is JS symmetric (yes/no)?
Yes.
Problem 2Level 0
What is the TV distance between distributions with disjoint supports?
1.
Problem 3Level 0
What is JS in bits for disjoint supports?
log22=1.
Level 1
Problem 4Level 1
TV((0.6, 0.3, 0.1), (0.2, 0.3, 0.5))?
21(0.4+0+0.4)=0.4.
Problem 5Level 1
χ²((½, ½) ‖ (¼, ¾))?
0.0625/0.25+0.0625/0.75=0.333.
Problem 6Level 1
Hellinger² for (¼, ¾) vs (¾, ¼)?
1−23/16=1−0.866=0.134.
Problem 7Level 1
What is f(1) for any f-divergence generator?
0.
Level 2
Problem 8Level 2
Pinsker bound on TV when KL = 0.5 nats?
0.25=0.5.
Problem 9Level 2
Pinsker bound when KL = 0.08 nats?
0.04=0.2.
Problem 10Level 2
GAN value at the optimal discriminator when p = q (nats)?
2⋅0−log4≈−1.386.
Problem 11Level 2
Optimal discriminator output at a point where p = q?
½.
Problem 12Level 2
Optimal discriminator output where p = 0.3 and q = 0.1?
0.3/0.4=0.75.
Problem 13Level 2
TV = 0.1. What is the largest possible gap between P(A) and Q(A) for any event A?
0.1.
Level 3
Problem 14Level 3
Prove that Df≥0.
Jensen: Eqf(p/q)≥f(Eq[p/q])=f(1)=0. ∎
Problem 15Level 3
Prove that JS≤log2.
KL(p∥m)=∑plogp+q2p≤log2. The same holds for q; average. ∎
Problem 16Level 3
Derive the optimal GAN discriminator.
Maximize plogD+qlog(1−D) pointwise: p/D=q/(1−D), so D=p/(p+q). ∎
Problem 17Level 3
JS in bits for p = (1, 0) and q = (½, ½)?
21log234+21(21log232+21)≈0.311.
Level 4
Problem 18Level 4
Which distance replaces JS to fix vanishing GAN gradients?
Wasserstein (earth mover).
Problem 19Level 4
Which imitation-learning method minimizes JS between expert and learner occupancies?
GAIL.
Problem 20Level 4
JS (nats) between real and simulated data with disjoint supports?
ln2≈0.693.
Coding practice
🐍 Code 1 (Level 1): JS in bits
Jensen–Shannon divergence via the mixture.
🐍 Code 2 (Level 1): total variation
½ Σ |p − q|.
🐍 Code 3 (Level 1): Hellinger²
1 − Σ √(pq).
🐍 Code 4 (Level 1): χ² divergence
Σ (p − q)²/q.
🐍 Code 5 (Level 2): Pinsker bound
Upper bound on TV from KL (nats).
Topic test
A timed test drawn at random from this topic's question bank. Each attempt gets new questions. For a longer test across the whole chapter, see the chapter test, or mix topics in the question bag.
Jensen–Shannon Divergence and f-Divergences: topic test
10 questions, drawn at random from a bank of 16. Every attempt is different.
⏱ Time limit: 15 minutes. The test submits itself when time runs out.
Levels covered: 0, 1, 2, 3, 4. No hints or solutions until you submit.