Applications: Bayesian Inference, Information & Simulation

the Kullback-Leibler divergence

/ KOOL-bak LYE-bler /

Suppose you model the world with a distribution Q, but reality actually follows a distribution P. How much do you pay for using the wrong model? The Kullback-Leibler divergence answers this with a single number: it measures how far the approximation Q is from the truth P, in units of wasted information. It is the workhorse 'distance' between two probability distributions, and it sits at the center of statistics, information theory, and machine learning.

The definition reads as an expected log-ratio: KL(P given Q) = sum over x of p(x) log[p(x) / q(x)] (an integral in the continuous case). Read it as the average, weighted by the TRUE distribution P, of the log-disagreement between P and Q. There is a beautiful coding interpretation: if you build an optimal code assuming the distribution is Q but symbols actually arrive according to P, then KL(P given Q) is the average number of EXTRA bits per symbol you waste compared to having used the right code for P — it is exactly cross-entropy minus entropy, H(P, Q) - H(P). Two key properties: KL is always greater than or equal to 0, and it equals 0 if and only if P and Q are identical (Gibbs' inequality). So it is zero exactly when your model is perfect, and grows as the model strays.

It is everywhere: maximum likelihood is equivalent to minimizing the KL divergence from the data's empirical distribution to your model, training a classifier by minimizing cross-entropy is the same thing, and variational inference approximates an intractable posterior by minimizing KL to a simpler family. The honest and important caveat: KL is NOT a true distance. It is not symmetric — KL(P given Q) generally does not equal KL(Q given P) — and it does not satisfy the triangle inequality, so calling it a 'distance' is loose talk. It also blows up to infinity if Q assigns zero probability to an outcome that P considers possible, which is why approximating models are usually kept broad enough to cover the truth's support.

True distribution P over {rain, shine} is (0.5, 0.5); your model Q is (0.9, 0.1). Then KL(P given Q) = 0.5 log2(0.5/0.9) + 0.5 log2(0.5/0.1) about 0.74 bits — you waste roughly 0.74 extra bits per day encoding the weather with the overconfident model. Swap the roles and KL(Q given P) comes out different, showing the asymmetry directly.

KL is the extra bits wasted by using the wrong model — zero only when the models match.

KL divergence is not a true distance: it is asymmetric (KL(P given Q) is generally not KL(Q given P)) and fails the triangle inequality, and it becomes infinite when Q rules out something P allows.

Also called
KL divergencerelative entropyKL散度相對熵