Contents · Probability & Information Theory
Part 0 · Expectation & Monte Carlo
Part 1 · Entropy & Divergence
- Entropy, KL Divergence, and Cross-Entropy
Part 2 · Score-Function Gradient
Part 3 · Bayesian Estimation
Part 1 · Entropy & Divergence
Entropy, KL Divergence, and Cross-Entropy
Reinforcement learning is full of distributions: a policy over actions, a target over labels, an old policy and a new one. Three quantities measure them. Entropy scores how spread out one distribution is, KL divergence scores how far one sits from another, and cross-entropy is the sum of the two. Every policy regularizer and trust region in modern RL is built from these.
Entropy: how uncertain is one distribution
For a discrete distribution , the Shannon entropy is
It is the average surprise, in nats when is natural. A point mass has ; the uniform distribution over outcomes maximizes it at . For a continuous density the sum becomes an integral, the differential entropy , which for a Gaussian is1
Only the variance enters: a wider Gaussian is more uncertain.
KL divergence: how far apart are two
The Kullback-Leibler divergence of from is
By Jensen's inequality , with equality iff almost everywhere.2 It is not a metric: it is asymmetric, in general, and obeys no triangle inequality. The expectation is taken under , so penalizes placing -mass where is small, and ignores regions never visits.
Cross-entropy ties them together
The cross-entropy of relative to is . Splitting the log of the ratio gives the identity that connects all three:
Since does not depend on , minimizing cross-entropy over is exactly minimizing . That is why the classification and behavior-cloning loss is written as a cross-entropy: with the fixed data (or expert) distribution, driving down pulls the model toward .
Why RL cares
Three uses, one toolkit.
- Entropy bonus. Maximum-entropy RL augments the reward with the policy entropy, optimizing so the agent solves the task while staying as random as possible. This keeps exploration alive and yields more robust policies; Soft Actor-Critic makes the entropy term the center of the objective.3
- KL trust region. TRPO limits how far each update moves the policy by constraining , a trust region in distribution space rather than in parameters.
- Cross-entropy loss. Supervised heads, including behavior cloning of an expert, minimize cross-entropy, which by the identity above is fitting to the data distribution by KL.
Worked example: KL between two Gaussians
The KL of one 1D Gaussian from another has a closed form,1
Take and , so only the means differ by one. Then , and
With equal variances the reverse is identical, : the mean gap enters symmetrically. The asymmetry shows up once the widths differ. Compare a broad against a narrow reference :
Same pair of Gaussians, two different numbers. The forward direction is larger because has mass out in the tails where the narrow is nearly zero, and blows up there; the reverse averages over the narrow , which never sees those tails.
- H(q) nats
- 1.419
- D(q‖p)
- 0.500
- D(p‖q)
- 0.500
- H(q,p) = H(q)+D(q‖p)
- 1.919
- |D(q‖p) − D(p‖q)|
- 0.000
Solid accent is q = N(μ, σ²); dashed is the reference p = N(0,1). The two divergences move independently: only μ = 0, σ = 1 sends both to zero.
The single case that zeroes both divergences is , where . Everywhere else the two numbers differ, which is why the direction of the KL is a modeling choice, not a detail: a trust region on constrains something genuinely different from its reverse.
Footnotes
-
Cover & Thomas, Elements of Information Theory (2006). ↩ ↩2
-
MacKay, Information Theory, Inference, and Learning Algorithms (2003). ↩
-
Haarnoja et al., Soft Actor-Critic (2018). ↩