Foundations to Frontier
Tests
A. Mathematical Foundations › A7 Information Theory

Jensen–Shannon Divergence and f-Divergences

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.

Level 0: Foundation

★☆☆☆☆ 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²)
10separation d →KL (clipped at 1.2)JS / ln 2TVHellinger²
KL(p‖q) = 1.125 · KL(q‖p) = 1.125 · JS = 0.221 nats (max ln 2 = 0.693) · TV = 0.547 · H² = 0.245
Pinsker: TV 0.547 ≤ √(KL/2) = 0.750 ✓
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. 1. Jensen–Shannon divergence is…
  2. 2. JS is at most…
  3. 3. TV distance between identical distributions is…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

f-divergences

For a convex ff with f(1)=0f(1) = 0:

Df(p ∥ q)=∑xq(x)f(p(x)q(x))D_f(p\,\|\,q) = \sum_xq(x)f\Big(\frac{p(x)}{q(x)}\Big)
Divergence f(t)
KL(p ‖ q) tlog⁡tt\log t
reverse KL −log⁡t-\log t
total variation 12∣t−1∣\tfrac12\lvert t - 1\rvert
Hellinger² 12(t−1)2\tfrac12(\sqrt t - 1)^2
Pearson χ² (t−1)2(t - 1)^2
Jensen–Shannon 12[tlog⁡t−(1+t)log⁡1+t2]\tfrac12[t\log t - (1 + t)\log\tfrac{1 + t}2]

By Jensen, Df≥f(1)=0D_f\ge f(1) = 0.

Jensen–Shannon

JS⁡(p,q)=12KL⁡(p ∥ m)+12KL⁡(q ∥ m),m=12(p+q)\operatorname{JS}(p, q) = \tfrac12\operatorname{KL}(p\,\|\,m) + \tfrac12\operatorname{KL}(q\,\|\,m),\quad m = \tfrac12(p + q)

JS is symmetric, always finite, 0≤JS⁡≤log⁡20\le\operatorname{JS}\le\log2, and JS⁡\sqrt{\operatorname{JS}} is a metric (Endres and Schindelin, 2003).

📝 Quick check (Level 1)
0/3 answered
  1. 1. The KL generator is f(t) =
  2. 2. JS between distributions with disjoint supports =
  3. 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\operatorname{TV}\le\sqrt{\operatorname{KL}/2} (nats).
  • Hellinger: H2≤TV⁡≤2 HH^2\le\operatorname{TV}\le\sqrt2\,H.
  • Chi-squared: KL⁡≤log⁡(1+χ2)≤χ2\operatorname{KL}\le\log(1 + \chi^2)\le\chi^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⁡\lvert P(A) - Q(A)\rvert\le\operatorname{TV} for every event AA.

Variational form and GANs

Every f-divergence has a dual form, Df=sup⁡TEp[T]−Eq[f∗(T)]D_f = \sup_T\mathbb E_p[T] - \mathbb E_q[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)D^* = p/(p + q), and

max⁡D Eplog⁡D+Eqlog⁡(1−D)=2JS⁡(p,q)−log⁡4\max_D\ \mathbb E_p\log D + \mathbb E_q\log(1 - D) = 2\operatorname{JS}(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. 1. With KL = 0.5 nats, Pinsker bounds TV by…
  2. 2. The optimal GAN discriminator is D*(x) =
  3. 3. |P(A) − Q(A)| for any event A is at most…

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Proofs

  • Non-negativity: Df=Eqf(p/q)≥f(Eq[p/q])=f(1)=0D_f = \mathbb E_q f(p/q)\ge f(\mathbb E_q[p/q]) = f(1) = 0 (Jensen). ∎
  • JS ≤ log 2: KL⁡(p ∥ m)=∑plog⁡2pp+q≤∑plog⁡2=log⁡2\operatorname{KL}(p\,\|\,m) = \sum p\log\frac{2p}{p + q}\le\sum p\log2 = \log2, since p/(p+q)≤1p/(p + q)\le1. The same holds for q, and averaging gives the bound. ∎
  • Optimal discriminator: pointwise, plog⁡D+qlog⁡(1−D)p\log D + q\log(1 - D) is maximized at D=p/(p+q)D = p/(p + q). Substituting gives KL⁡(p ∥ m)+KL⁡(q ∥ m)−log⁡4\operatorname{KL}(p\,\|\,m) + \operatorname{KL}(q\,\|\,m) - \log4. ∎
  • H² ≤ TV: (p−q)2≤∣p−q∣(p+q)=∣p−q∣(\sqrt p - \sqrt q)^2\le\lvert\sqrt p - \sqrt q\rvert(\sqrt p + \sqrt q) = \lvert p - q\rvert. Sum and halve. ∎
Exercise 3.1: JS for p = (1, 0), q = (½, ½)

m=(34,14)m = (\frac34, \frac14). KL⁡(p ∥ m)=log⁡43\operatorname{KL}(p\,\|\,m) = \log\frac43 and KL⁡(q ∥ m)=12log⁡23+12log⁡2\operatorname{KL}(q\,\|\,m) = \frac12\log\frac23 + \frac12\log2. In bits, JS ≈ 0.311.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Non-negativity of every f-divergence follows from…
  2. 2. Value of the GAN game at the optimal discriminator:
  3. 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 log⁡2\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

  1. I. Csiszár (1967). “Information-type measures of difference of probability distributions.” Studia Sci. Math. Hungarica, 2.
  2. J. Lin (1991). “Divergence measures based on the Shannon entropy.” IEEE Transactions on Information Theory, 37(1).
  3. D. Endres, J. Schindelin (2003). “A new metric for probability distributions.” IEEE Transactions on Information Theory, 49(7).
  4. I. Goodfellow et al. (2014). “Generative adversarial nets.” NeurIPS.
  5. S. Nowozin, B. Cseke, R. Tomioka (2016). “f-GAN: training generative neural samplers using variational divergence minimization.” NeurIPS.
  6. M. Arjovsky, S. Chintala, L. Bottou (2017). “Wasserstein generative adversarial networks.” ICML.
  7. J. Ho, S. Ermon (2016). “Generative adversarial imitation learning.” NeurIPS.
  8. Y. Ganin et al. (2016). “Domain-adversarial training of neural networks.” JMLR, 17.
  9. A. Tsybakov (2009). Introduction to Nonparametric Estimation. Springer. Ch. 2 (divergence inequalities).
  10. 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).