M5.1 The Cost of a Wrong Probability Table: KL Divergence and Cross-Entropy
Builds on2 notes
A wrong weather table
Consider a mathematical betting model with sunny, rainy, and cloudy outcomes. A bookmaker’s positive table sets payout multipliers . Each participant allocates all wealth among outcomes.
This is a probability illustration. If someone believes table , allocating in proportions maximizes expected log wealth under that belief [3]. But actual outcomes follow another table .
Compare two people observing the same outcomes, using allocations and . Wealth multiplies, so logarithms turn the accumulated comparison into a sum.
DiscussionQ1
Define daily outcomes and wealth updates. Which quantity measures the cost of using the wrong table?
Show the reasoning
Let iid . Allocating by multiplies wealth by each day. Under integrability,
The logarithm turns compounding into addition. The expectation is under true outcome law , regardless of the participant’s belief.
Subtract this expected log growth from that obtained with allocation :
The common payout table cancels. Expected annual log-wealth difference is 365 times this value; a realized year still fluctuates.
A small expected cost each day
On a logarithmic wealth plot, both realized paths fluctuate, but their expected slopes differ by a fixed amount.
The expected gap grows linearly. The actual gap need not increase by the same amount every day, or even increase every day.
Realized log differences fluctuate; their expectation accumulates at rate .
KL, nonnegativity, and cross-entropy
For distributions on the same sample space, define Kullback–Leibler divergence:
Use an integral for densities. A zero- term contributes zero; positive where gives infinite KL. Interpret it as excess expected log cost when observations follow but predictions use [2].
Nonnegativity. Write KL as . Convexity of and Jensen give
Equality in Jensen requires constant on the support of ; equality in the normalization step requires no extra mass outside it. Together they give . KL vanishes exactly for identical laws, but is not a metric.
Entropy and cross-entropy. Split the log ratio:
When these quantities are finite, cross-entropy is the correct-table cost plus excess cost. For fixed , minimizing it is equivalent to minimizing KL. Differential entropy for continuous densities can be negative and has a different interpretation from discrete entropy.
Asymmetry matters: generally .
- If remains fixed while , the contribution grows without bound: a true event is severely underpredicted.
- If , its direct contribution vanishes. Allocating mass there still removes mass from other outcomes and can increase the total cost.
Reversing the arguments changes the averaging law. is infinite when places positive mass where . This direction treats errors differently; neither direction is universally the larger number.
DetailsNot a metric, but additive for independent products
KL is asymmetric and does not satisfy a metric triangle inequality. For independent product laws, : split the logarithm and take expectations.
Pinsker’s inequality with natural logarithms gives KL(p‖q)≥½‖p−q‖₁². Thus small KL controls every event-probability difference. The converse fails: small total variation can coexist with infinite KL through a support mismatch.
Quantify the asymmetry
For and , calculate
The annual expected log gap is about 57.4 nats. This is neither a deterministic wealth ratio nor the logarithm of an expected wealth ratio. Individual summands can be negative; only the total is guaranteed nonnegative.
Swapping the two tables gives approximately , rather than . The same absolute probability discrepancy can have different log costs depending on the true law.
The long-run sample-average statement assumes fixed iid outcomes and an integrable log ratio. Keeping some wealth unallocated changes the multiplier and does not simply scale KL by the allocated fraction.
Simulate a year and nearly remove an outcome
import numpy as np
rng = np.random.default_rng(0)
p = np.array([.5,.3,.2])
q = np.array([.6,.1,.3])
kl = lambda a,b:np.sum(a*np.log(a/b))
print(kl(p,q),kl(q,p))
x = rng.choice(3,size=(2000,365),p=p)
gap = np.log(p[x]).sum(1)-np.log(q[x]).sum(1)
print('daily mean and annualized fluctuation:',gap.mean()/365,gap.std()/365)
q_bad = np.array([.7,1e-6,.3-1e-6])
print('near-zero rainy probability:',kl(p,q_bad))
The simulated daily expected gap approaches , with finite-year fluctuations. Making rainy probability raises KL to about 3.5 nats per observation. The formula identifies which underpredicted events dominate the cost.
Change and exchange the two arguments to inspect the costly errors.
Check your understanding
References
- Cover, T. M., Thomas, J. A. Elements of Information Theory. Wiley, 2nd ed., 2006.、
- Kullback, S., Leibler, R. A. On Information and Sufficiency. Annals of Mathematical Statistics 22(1), 1951.
- Kelly, J. L. A New Interpretation of Information Rate. Bell System Technical Journal 35(4), 1956.
- MacKay, D. J. C. Information Theory, Inference, and Learning Algorithms. Cambridge University Press, 2003.