Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.How wrong is my map?
Your map says the river is to the east; reality says it’s to the north. How wrong are you? The KL divergence measures the average extra surprise you’ll experience if you believe but the world actually behaves like . It’s zero if your beliefs are right. It’s huge, even infinite, if you’re sure something can’t happen and then it does.
Unlike ordinary distance, it depends on direction: “how wrong is q about p” differs from “how wrong is p about q”.
KL divergence is the loss behind maximum likelihood and variational inference, the trust-region constraint in PPO/TRPO, the drift measure in fault detection, and the regularizer in VAEs. Choosing the direction (forward or reverse) changes what an approximation gets right.
- 1. KL(p ‖ q) is zero when…
- 2. Is KL(p ‖ q) always equal to KL(q ‖ p)?
- 3. If q says an event is impossible but p says it can happen, KL(p ‖ q) is…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.Definition
For densities, replace the sum by an integral.
Properties
- Non-negative: , with equality iff (Gibbs).
- Asymmetric: in general. It’s not a metric, and there’s no triangle inequality.
- Infinite if where .
- Invariant under invertible reparameterizations of (unlike differential entropy).
Gaussians
For a pure mean shift with equal variances: .
- 1. KL(N(1, 1) ‖ N(0, 1)) =
- 2. KL(p ‖ q) = H(p, q) − …
- 3. KL satisfies the triangle inequality?
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.Forward vs reverse KL
When fitting an approximation to a target :
- Forward is mass-covering. must put probability everywhere does. It equals maximum likelihood on samples from . For exponential families it gives moment matching.
- Reverse is mode-seeking. avoids regions where is small and may lock onto one mode. It only needs up to a constant, which is why variational inference uses it (A5.2-9).
Chain rule and convexity
KL is jointly convex in . For Markov chains and time series, KL decomposes into a sum of per-step conditional KLs.
Estimating KL
- Monte Carlo: with , when both densities can be evaluated.
- From samples only: -NN estimators, or density-ratio and classifier-based estimators.
- 1. Maximum likelihood minimizes…
- 2. Variational inference typically minimizes reverse KL because…
- 3. The KL between two joints decomposes into…
Level 3: Advanced
★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.Proof of non-negativity (Gibbs’ inequality)
By Jensen with the convex : . Equality requires to be constant on the support, i.e. . ∎
Deriving the Gaussian KL (1-D)
. Under , and . Substitute. ∎
Chain rule
. Take . ∎
Exercise 3.1: KL(N(0, 4) ‖ N(0, 1))
nats. The reverse, , is different.
- 1. Gibbs' inequality is proved with…
- 2. KL(N(0, 4) ‖ N(0, 1)) ≈
- 3. KL is invariant under…
Level 4: Expert
★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.Detecting a gyro bias jump: KL as evidence rate
A gyro’s bias suddenly shifts by . The CUSUM detector accumulates the log-likelihood ratio , resets at zero, and alarms when the sum exceeds . After the change, each sample adds on average . So the mean detection delay is about (Lorden, 1971). Halving the shift quarters the KL and quadruples the delay. Simulations match closely.
KL divergence in AI, robotics and aerospace
- Fault detection and integrity monitoring: CUSUM and GLR tests for navigation-sensor faults and GNSS integrity (Basseville and Nikiforov, 1993).
- Policy optimization: TRPO constrains the KL between successive policies; PPO penalizes or clips it (Schulman et al., 2015, 2017).
- VAEs and variational inference: the KL term regularizes the latent posterior toward the prior (Kingma and Welling, 2014).
- Knowledge distillation: train a small on-board model to match a large model’s predictive distribution (Hinton, Vinyals and Dean, 2015).
References
- S. Kullback, R. Leibler (1951). “On information and sufficiency.” Annals of Mathematical Statistics, 22(1).
- T. Cover, J. Thomas (2006). Elements of Information Theory, 2nd ed. Wiley. Ch. 2, 11.
- G. Lorden (1971). “Procedures for reacting to a change in distribution.” Annals of Mathematical Statistics, 42(6).
- E. S. Page (1954). “Continuous inspection schemes.” Biometrika, 41 (CUSUM).
- M. Basseville, I. Nikiforov (1993). Detection of Abrupt Changes: Theory and Application. Prentice Hall.
- T. Minka (2005). “Divergence measures and message passing.” Microsoft Research Technical Report MSR-TR-2005-173.
- J. Schulman, S. Levine, P. Moritz, M. Jordan, P. Abbeel (2015). “Trust region policy optimization.” ICML.
- D. Kingma, M. Welling (2014). “Auto-encoding variational Bayes.” ICLR.
- G. Hinton, O. Vinyals, J. Dean (2015). “Distilling the knowledge in a neural network.” arXiv:1503.02531.
- Q. Wang, S. Kulkarni, S. Verdú (2009). “Divergence estimation for multidimensional densities via k-nearest-neighbor distances.” IEEE Transactions on Information Theory, 55(5).