Entropy & KL divergence
Measuring uncertainty and the discrepancy between distributions through Shannon entropy, cross-entropy, and KL divergence, with the link to maximum likelihood.
Think of a distribution as “how unsure you are about the outcome.” If a coin almost always lands heads, you are nearly certain about the next flip and your uncertainty is low; if it is fair, every outcome is maximally hard to guess and your uncertainty is highest. Shannon entropy turns this “hard to guess” feeling into a single number. This page starts from entropy, builds up to cross-entropy and KL divergence — the latter measuring how far apart two distributions are — and shows that this is the shared language behind nearly every probabilistic objective, including the reconstruction methods.
Shannon entropy measures the uncertainty carried by a distribution. For a discrete distribution ,
where is the probability of outcome , is the “surprise” of seeing that outcome (rarer outcomes are more surprising), and the sum is the expected surprise. Entropy attains its maximum at the uniform distribution and is zero when all mass sits on a single outcome. It lower-bounds the average code length needed to losslessly encode samples drawn from .
A concrete example, with logarithms base 2: a fair coin has entropy bit — on average one bit per flip is needed to encode it. A biased coin has entropy bits, less than half: the outcome is more predictable, so fewer bits are needed on average. A fully certain coin has entropy zero and needs no bits at all.
Forward KL(p‖q) grows fast where q has little mass but p has mass; reverse KL(q‖p) does the opposite. The two generally differ, so KL is not a distance.
The figure illustrates the asymmetry of the KL divergence with two univariate Gaussians: the reference is fixed as a standard normal, while the mean and standard deviation of are adjustable. When collapses to near-zero density in a tail where still carries mass, the forward KL rises sharply; swapping the roles of the two distributions generally yields a different value, and both vanish together only when . This asymmetry, driven by the log-ratio term inside the integral, carries over directly to KL and cross-entropy on continuous distributions.
Cross-entropy gives the average code length when samples from are encoded with a code designed for a distribution :
Here outcomes occur at the frequencies of (hence the weighting by ), but the code lengths are designed for (hence ). If the used for coding does not match the true , the average code length must grow — the excess is exactly the KL divergence below.
Their difference is the KL divergence:
It measures the extra code length paid for using a code built for instead of the true . By Gibbs’ inequality, , with equality if and only if . The KL divergence is asymmetric: in general , so it is not a distance metric.
A worked example of the asymmetry. Let and . In bits, bits, whereas bits. Both directions are positive and vanish only when , but the values differ — swapping the two distributions changes the answer.
Forward KL heavily penalizes placing little -mass where has mass, forcing to cover the whole support of (“mass-covering”). Reverse KL penalizes for spreading outside , favoring a single mode (“mode-seeking”).
The asymmetry comes from which distribution does the weighting. Forward KL takes the expectation under : wherever but , the term is amplified by , so dares not leave a gap anywhere has support — this is the source of “mass-covering.” Reverse KL takes the expectation under : it penalizes wherever but , so prefers to cover a single peak of rather than spill outside it — the source of “mode-seeking.” When is multimodal, the minimizing forward KL spreads to cover every peak (even placing mass in the low-density valleys between them), while the minimizing reverse KL retreats into a single peak. The two objectives give markedly different solutions in generative modeling, and the choice depends on whether you want to “cover all modes” or “produce one sharp sample.”
The KL divergence connects directly to maximum likelihood. Maximizing a model’s log-likelihood on data is equivalent to minimizing the forward KL between the empirical data distribution and the model :
where is the empirical distribution that puts equal weight on each observed sample and is the model distribution with parameters . The equivalence holds because , and does not depend on , so it is constant for the optimization. This unifies maximum likelihood with information-theoretic distribution matching: training a maximum-likelihood model is making the model distribution match the empirical distribution of the data.
The KL divergence is always defined, but diverges to when has near-zero mass where has mass (it is for disjoint supports, giving no useful gradient); this is common early in training before the model and data distributions align, which is exactly why CryoGEN-II matches distributions with optimal transport instead of KL. The Wasserstein distance instead measures discrepancy through an optimal-transport cost, staying finite even without overlapping support and varying smoothly with geometric displacement, which makes it a frequent alternative to KL in variational inference and generative modeling.
These quantities are everywhere in Cryo-ET reconstruction. Maximum-likelihood and maximum-a-posteriori objectives (MAP, MLE & EM) are at heart minimizing the forward KL between the data and the predictions of the forward imaging model; the E-step of EM approximates the latent posterior with an auxiliary distribution, and the bound is tight exactly when the KL between that auxiliary distribution and the true posterior is zero. Variational inference explicitly minimizes a reverse KL, bringing the “mode-seeking” behavior into the approximate posterior. And when KL degenerates because the distributions do not overlap and gives no gradient, optimal transport takes over — this KL-versus-Wasserstein trade-off maps directly onto the boundary between the KL-family point estimates and the OT-family (CryoGEN-II) among the reconstruction methods.