Back to AI Math Mind Map
中文·English
📐 AI MathID: entropy-kl

Entropy, KL & Cross-Entropy

熵 / KL 散度 / 交叉熵
🎯Core Definition
Entropy H(X)=xp(x)logp(x)H(X) = -\sum_x p(x)\log p(x) measures uncertainty (expected bits of an optimal code); KL divergence measures the discrepancy between two distributions, DKL(PQ)=xp(x)logp(x)q(x)0D_{KL}(P \Vert Q) = \sum_x p(x)\log\frac{p(x)}{q(x)} \ge 0, with equality iff P=QP = Q. Non-negativity follows from Jensen: since log\log is concave, DKL(PQ)=Ep[logq(x)p(x)]logEp[q(x)p(x)]=log1=0D_{KL}(P \Vert Q) = -\mathbb{E}_p\left[\log\frac{q(x)}{p(x)}\right] \ge -\log\mathbb{E}_p\left[\frac{q(x)}{p(x)}\right] = -\log 1 = 0. KL is asymmetric: for P=Bern(0.5)P = \text{Bern}(0.5) and Q=Bern(0.1)Q = \text{Bern}(0.1), DKL(PQ)0.511D_{KL}(P \Vert Q) \approx 0.511 while DKL(QP)0.368D_{KL}(Q \Vert P) \approx 0.368, and DKLD_{KL} \to \infty whenever Q(x)=0<P(x)Q(x) = 0 < P(x). Cross-entropy satisfies H(P,Q)=H(P)+DKL(PQ)H(P,Q) = H(P) + D_{KL}(P \Vert Q).
💡Use Cases
distribution discrepancy is the central metric of probabilistic ML — cross-entropy loss in classification, the DKL(qp)D_{KL}(q \Vert p) term in VAEs, student-approximates-teacher in distillation, KL penalties constraining policy drift in RLHF; classic interview questions ("why cross-entropy loss", "prove KL non-negative") all start here.
Key Problems Solved
unlike geometric distances such as L2, KL carries information-theoretic meaning (extra bits to encode PP with QQ) and unifies with entropy and mutual information; but it is asymmetric and violates the triangle inequality, so symmetric alternatives (Jensen-Shannon divergence, Wasserstein distance) must be constructed when needed.
🎯5 High-Frequency Exam Points
1
Prove DKL(PQ)=xp(x)logp(x)q(x)0D_{KL}(P \Vert Q) = \sum_x p(x)\log\frac{p(x)}{q(x)} \ge 0 (via Jensen) and state when equality holds?
2
Why is KL divergence asymmetric? Give a numeric example.
3
Relation among entropy, cross-entropy and KL? Why is cross-entropy loss = entropy + KL?
4
Does KL satisfy symmetry or the triangle inequality? What symmetrized alternative is used?
5
Where does KL appear in classification, distillation and RLHF? Geometric intuition of minimizing KL?
Updated 2026-08-12
🎯
Test Your Knowledge: Practice Questions for "Entropy, KL & Cross-Entropy"
Single choice pitfall questions with instant feedback and mistake tracking.
🚀 Start Card Practice
Previous CardCommon DistributionsNext CardMutual Information

🔗 More AI Math Knowledge Cards

Adam/AdamW MathBayesian InferenceBias-Variance DecompositionBootstrap