M5.1 7 min read Oct 2026

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 bb sets payout multipliers 1/b(x)1/b(x). Each participant allocates all wealth among outcomes.

This is a probability illustration. If someone believes table qq, allocating in proportions qq maximizes expected log wealth under that belief [3]. But actual outcomes follow another table pp.

Compare two people observing the same outcomes, using allocations pp and qq. 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 Xt∼pX_t\sim p. Allocating by qq multiplies wealth by q(Xt)/b(Xt)q(X_t)/b(X_t) each day. Under integrability,

Wn=W0∏t=1nq(Xt)b(Xt),1nlog⁡WnW0=1n∑t=1nlog⁡q(Xt)b(Xt)⟶Ep ⁣[log⁡q(X)b(X)].W_n=W_0\prod_{t=1}^n\frac{q(X_t)}{b(X_t)},\qquad \frac1n\log\frac{W_n}{W_0}=\frac1n\sum_{t=1}^n\log\frac{q(X_t)}{b(X_t)} \longrightarrow\mathbb E_p\!\left[\log\frac{q(X)}{b(X)}\right].

The logarithm turns compounding into addition. The expectation is under true outcome law pp, regardless of the participant’s belief.

Subtract this expected log growth from that obtained with allocation pp:

Ep ⁣[log⁡p(X)b(X)]−Ep ⁣[log⁡q(X)b(X)]=Ep ⁣[log⁡p(X)q(X)].\mathbb E_p\!\left[\log\frac{p(X)}{b(X)}\right]-\mathbb E_p\!\left[\log\frac{q(X)}{b(X)}\right] =\mathbb E_p\!\left[\log\frac{p(X)}{q(X)}\right].

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.

Accumulating expected log cost from using a wrong probability table.

Realized log differences fluctuate; their expectation accumulates at rate KL(p∥q)\mathrm{KL}(p\|q).

KL, nonnegativity, and cross-entropy

For distributions on the same sample space, define Kullback–Leibler divergence:

KL(p ∥ q)=∑xp(x)log⁡p(x)q(x)=EX∼p[log⁡p(X)q(X)].\mathrm{KL}(p\,\|\,q)=\sum_x p(x)\log\frac{p(x)}{q(x)}=\mathbb E_{X\sim p}\Big[\log\frac{p(X)}{q(X)}\Big].

Use an integral for densities. A zero-pp term contributes zero; positive pp where q=0q=0 gives infinite KL. Interpret it as excess expected log cost when observations follow pp but predictions use qq [2].

Nonnegativity. Write KL as −Ep[log⁡(q/p)]-\mathbb E_p[\log(q/p)]. Convexity of −log⁡-\log and Jensen give

−Ep[log⁡q(X)p(X)]≥−log⁡∑x:p(x)>0q(x)≥−log⁡1=0.□-\mathbb E_p\Big[\log\frac{q(X)}{p(X)}\Big]\ge-\log\sum_{x:p(x)>0}q(x)\ge-\log1=0.\qquad\square

Equality in Jensen requires q/pq/p constant on the support of pp; equality in the normalization step requires no extra qq mass outside it. Together they give p=qp=q. KL vanishes exactly for identical laws, but is not a metric.

Entropy and cross-entropy. Split the log ratio:

KL(p ∥ q)=Ep[−log⁡q(X)]⏟H(p,q) cross-entropy−Ep[−log⁡p(X)]⏟H(p) entropy.\mathrm{KL}(p\,\|\,q)=\underbrace{\mathbb E_p[-\log q(X)]}_{H(p,q)\ \text{cross-entropy}}-\underbrace{\mathbb E_p[-\log p(X)]}_{H(p)\ \text{entropy}}.

When these quantities are finite, cross-entropy is the correct-table cost plus excess cost. For fixed pp, 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 KL(p∥q)≠KL(q∥p)\mathrm{KL}(p\|q)\ne\mathrm{KL}(q\|p).

  • If p(x)>0p(x)>0 remains fixed while q(x)→0q(x)\to0, the contribution grows without bound: a true event is severely underpredicted.
  • If p(x)=0p(x)=0, its direct contribution vanishes. Allocating qq mass there still removes mass from other outcomes and can increase the total cost.

Reversing the arguments changes the averaging law. KL(q∥p)\mathrm{KL}(q\|p) is infinite when qq places positive mass where p=0p=0. 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, KL(p1p2∥q1q2)=KL(p1∥q1)+KL(p2∥q2)\mathrm{KL}(p_1p_2\|q_1q_2)=\mathrm{KL}(p_1\|q_1)+\mathrm{KL}(p_2\|q_2): 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 p=(0.5,0.3,0.2)p=(0.5,0.3,0.2) and q=(0.6,0.1,0.3)q=(0.6,0.1,0.3), calculate

KL(p∥q)=0.5log⁡0.50.6+0.3log⁡0.30.1+0.2log⁡0.20.3≈0.158 nats per day.\mathrm{KL}(p\|q)=0.5\log\frac{0.5}{0.6}+0.3\log\frac{0.3}{0.1}+0.2\log\frac{0.2}{0.3}\approx0.158\ \text{nats per day}.

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 0.1210.121, rather than 0.1580.158. 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 0.1580.158, with finite-year fluctuations. Making rainy probability 10−610^{-6} raises KL to about 3.5 nats per observation. The formula identifies which underpredicted events dominate the cost.

Change qq and exchange the two arguments to inspect the costly errors.

Check your understanding

Check your understanding

An empirical table gives a storm frequency 0.008 and hail frequency zero. The model assigns 0.001 and 0.05. Which direct empirical KL contribution is larger?

Check your understanding

A stationary Markov chain has marginal pp each day. Both predictors ignore history and use fixed tables pp and qq. What is the expected log gap over nn days?

Check your understanding

Why train with cross-entropy instead of explicitly calculating data-to-model KL?

References

  1. Cover, T. M., Thomas, J. A. Elements of Information Theory. Wiley, 2nd ed., 2006.、
  2. Kullback, S., Leibler, R. A. On Information and Sufficiency. Annals of Mathematical Statistics 22(1), 1951.
  3. Kelly, J. L. A New Interpretation of Information Rate. Bell System Technical Journal 35(4), 1956.
  4. MacKay, D. J. C. Information Theory, Inference, and Learning Algorithms. Cambridge University Press, 2003.