Entropy & Information Content

Volume I, Chapter 3 — Part III. Shannon entropy from axioms, uniqueness theorem, chain rule, conditional entropy, differential entropy, maximum entropy principle, source coding, and connections to cross-entropy loss and perplexity in machine learning.

Intermediate

Prerequisites

Table of Contents

  1. Learning Objectives
  2. Prerequisites
  3. Notation
  4. Core Intuition
  5. Information Content of an Event
  6. The Uniqueness Theorem for Self-Information
  7. Shannon Entropy: Definition and Derivation
  8. Properties of Entropy: Proofs
  9. Conditional Entropy and the Chain Rule
  10. Mutual Information
  11. Differential Entropy for Continuous Variables
  12. Maximum Entropy Principle
  13. Source Coding and the Entropy Lower Bound
  14. Connection to Machine Learning
  15. Common Pitfalls and Misconceptions
  16. Research Perspective
  17. Summary of Takeaways
  18. Exercises

Learning Objectives

After reading this chapter, you should be able to:

  1. State the axioms for self-information and prove that I(p)=logpI(p) = -\log p is the unique solution (up to base).
  2. Define Shannon entropy and prove non-negativity, the upper bound H(X)lognH(X) \leq \log n, and when equality holds.
  3. Derive and apply the chain rule for joint entropy and conditional entropy.
  4. Define mutual information and prove the identity I(X;Y)=H(X)H(XY)I(X; Y) = H(X) - H(X \mid Y).
  5. Distinguish discrete entropy from differential entropy and explain why differential entropy can be negative.
  6. State the maximum entropy principle for discrete and continuous settings.
  7. Explain how cross-entropy loss, perplexity, and the information bottleneck arise from entropy concepts.

Prerequisites

Later connections:


Notation

  • H(X)H(X) — Shannon entropy (nats or bits)
  • H(XY)H(X \mid Y) — Conditional entropy
  • I(X;Y)I(X; Y) — Mutual information
  • p(x),p(x,y)p(x), p(x, y) — Mass or density functions
  • log\log — Natural logarithm unless stated otherwise

Core Intuition

How much information does a random event carry? A fair coin flip (p=1/2p = 1/2) is more informative than a biased coin (p=0.99p = 0.99) because the outcome is more uncertain. Shannon's insight (1948) was to quantify this intuition axiomatically: information should be non-negative, zero for certain events, and additive for independent events. The unique measure is I(p)=logpI(p) = -\log p.

The entropy H(X)=E[logp(X)]H(X) = \mathbb{E}[-\log p(X)] is the average information content — the expected surprise when sampling from XX. It answers: How many bits (on average) are needed to encode outcomes of XX using an optimal code?

In machine learning, entropy is everywhere:

  • Cross-entropy loss measures how many extra bits our model uses compared to the true distribution.
  • Perplexity exponentiates cross-entropy to give an effective "branching factor" for language models.
  • Mutual information quantifies how much a representation tells us about the target — the foundation of the information bottleneck.

Series context. This is Part III of Chapter 3 in Volume I. It precedes KL Divergence, where DKL(pq)=H(p,q)H(p)D_{\text{KL}}(p \| q) = H(p, q) - H(p).

Interactive: Entropy & Information Content

30.0%
A
25.0%
B
20.0%
C
12.0%
D
8.0%
E
5.0%
F
A
B
C
D
E
F
Entropy H(X)2.360 bits
0 (certain)max = 2.58 (uniform)

Surprise of most likely

-log₂(0.30) = 1.74 bits

Efficiency

91.3% of max

Key insight: Entropy measures average surprise. Uniform distributions maximize entropy (most uncertain). Peaked distributions have low entropy (predictable). In ML, cross-entropy loss measures how surprised your model is by the true labels.

Information Content of an Event

Definition 1 (Self-Information). The information content (self-information, surprisal) of an event with probability p(0,1]p \in (0, 1] is:

I(p)=logbp=logb1p,(1)I(p) = -\log_b p = \log_b \frac{1}{p}, \tag{1}

where bb is the log base. We use b=2b = 2 for bits and b=eb = e for nats (1 bit=ln2 nats1 \text{ bit} = \ln 2 \text{ nats}).

Example 1. For a fair die outcome (p=1/6p = 1/6): I(1/6)=log262.585I(1/6) = \log_2 6 \approx 2.585 bits. For a certain event (p=1p = 1): I(1)=0I(1) = 0 bits.

Axioms for Self-Information. A function I:(0,1]R0I: (0, 1] \to \mathbb{R}_{\geq 0} should satisfy:

  1. Non-negativity: I(p)0I(p) \geq 0.
  2. Zero for certainty: I(1)=0I(1) = 0.
  3. Continuity: II is continuous on (0,1](0, 1].
  4. Additivity for independence: I(p1p2)=I(p1)+I(p2)I(p_1 p_2) = I(p_1) + I(p_2) when two events with probabilities p1,p2p_1, p_2 are independent (joint probability p1p2p_1 p_2).

Interpretation of (4). Learning that two independent events occurred should convey the sum of their individual information contents — information is additive for independent surprises.


The Uniqueness Theorem for Self-Information

Theorem 1 (Uniqueness of Self-Information). The only function I:(0,1]R0I: (0, 1] \to \mathbb{R}_{\geq 0} satisfying axioms 1–4 is I(p)=clogpI(p) = -c \log p for some constant c>0c > 0.

Proof. Axiom 4 states I(p1p2)=I(p1)+I(p2)I(p_1 p_2) = I(p_1) + I(p_2). Define f(p)=I(p)f(p) = I(p) for p(0,1]p \in (0, 1]. This is Cauchy's functional equation on the multiplicative group (R>0,×)(\mathbb{R}_{>0}, \times).

Step 1 — Reduction to additive form. Let g(x)=f(ex)g(x) = f(e^{-x}) for x0x \geq 0. Then for x,y0x, y \geq 0:

g(x+y)=f(e(x+y))=f(exey)=f(ex)+f(ey)=g(x)+g(y).(2)g(x + y) = f(e^{-(x+y)}) = f(e^{-x} e^{-y}) = f(e^{-x}) + f(e^{-y}) = g(x) + g(y). \tag{2}

So gg satisfies the additive Cauchy equation on [0,)[0, \infty).

Step 2 — Continuity implies linearity. By axiom 3, ff is continuous, hence gg is continuous. The only continuous solution to g(x+y)=g(x)+g(y)g(x+y) = g(x) + g(y) on [0,)[0, \infty) is g(x)=cxg(x) = cx for some c0c \geq 0.

Step 3 — Back-substitution. f(p)=g(logp)=clogpf(p) = g(-\log p) = -c \log p. Non-negativity (axiom 1) and monotonicity (axiom 2: I(1)=0I(1) = 0, and II decreases as pp increases) require c>0c > 0. \blacksquare

Remark. The choice of base bb is conventional: I(p)=log2pI(p) = -\log_2 p gives bits; I(p)=lnpI(p) = -\ln p gives nats. All bases differ by a constant factor logbe\log_b e.


Shannon Entropy: Definition and Derivation

Definition 2 (Shannon Entropy — Discrete). For discrete random variable XX with PMF p(x)=P(X=x)p(x) = P(X = x):

H(X)=E[I(P(X))]=E[logp(X)]=xXp(x)logp(x).(3)H(X) = \mathbb{E}[I(P(X))] = \mathbb{E}[-\log p(X)] = -\sum_{x \in \mathcal{X}} p(x) \log p(x). \tag{3}

Convention. Define 0log0=limp0+plogp=00 \log 0 = \lim_{p \to 0^+} p \log p = 0, ensuring events with zero probability contribute nothing.

Definition 3 (Joint and Conditional Entropy). For joint PMF p(x,y)p(x, y):

H(X,Y)=x,yp(x,y)logp(x,y),(4)H(X, Y) = -\sum_{x,y} p(x,y) \log p(x,y), \tag{4} H(YX)=EX[H(YX=x)]=x,yp(x,y)logp(yx).(5)H(Y \mid X) = \mathbb{E}_X[H(Y \mid X = x)] = -\sum_{x,y} p(x,y) \log p(y \mid x). \tag{5}

Example 2 (Binary Entropy). For XBernoulli(p)X \sim \text{Bernoulli}(p):

H(X)=Hb(p)=plogp(1p)log(1p).(6)H(X) = H_b(p) = -p \log p - (1-p) \log(1-p). \tag{6}

This is symmetric about p=1/2p = 1/2, where Hb(1/2)=1H_b(1/2) = 1 bit (maximum). At p{0,1}p \in \{0, 1\}, H=0H = 0.

Example 3 (Uniform Distribution). For XX uniform on {1,,n}\{1, \ldots, n\}: H(X)=lognH(X) = \log n bits.


Properties of Entropy: Proofs

Property 1 (Non-Negativity). H(X)0H(X) \geq 0, with equality iff XX is deterministic (supported on a single value).

Proof. Each term p(x)logp(x)0-p(x) \log p(x) \geq 0 since p(x)[0,1]p(x) \in [0, 1] implies logp(x)0\log p(x) \leq 0. Equality requires p(x){0,1}p(x) \in \{0, 1\} for all xx, with exactly one p(x)=1p(x) = 1. \blacksquare

Property 2 (Upper Bound). For XX taking at most nn distinct values:

H(X)logn,(7)H(X) \leq \log n, \tag{7}

with equality iff XX is uniform on nn values.

Proof. By Jensen's inequality, since log-\log is convex (equivalently, log\log is concave):

H(X)=E[logp(X)]=E[log1p(X)]logE[1p(X)]=logxp(x)1p(x)=logn.(8)H(X) = \mathbb{E}[-\log p(X)] = \mathbb{E}\left[\log \frac{1}{p(X)}\right] \leq \log \mathbb{E}\left[\frac{1}{p(X)}\right] = \log \sum_x p(x) \cdot \frac{1}{p(x)} = \log n. \tag{8}

Equality in Jensen holds iff 1/p(X)1/p(X) is constant a.e., i.e., p(x)=1/np(x) = 1/n for all xx in the support. \blacksquare

Property 3 (Invariance under bijection). If Y=g(X)Y = g(X) for a bijection gg, then H(Y)=H(X)H(Y) = H(X).

Proof. pY(y)=pX(g1(y))p_Y(y) = p_X(g^{-1}(y)), and the sum (3) is unchanged under relabeling. \blacksquare

Property 4 (Concavity in the distribution). H(X)H(X) is concave in the probability vector (p(x1),,p(xn))(p(x_1), \ldots, p(x_n)).

This implies that mixing distributions increases entropy — uncertainty is maximized at the "center" of the probability simplex.


Conditional Entropy and the Chain Rule

Theorem 2 (Chain Rule for Entropy). For any random variables XX and YY:

H(X,Y)=H(X)+H(YX)=H(Y)+H(XY).(9)H(X, Y) = H(X) + H(Y \mid X) = H(Y) + H(X \mid Y). \tag{9}

Proof. Using p(x,y)=p(x)p(yx)p(x,y) = p(x) p(y \mid x):

H(X,Y)=x,yp(x,y)logp(x,y)=x,yp(x,y)[logp(x)+logp(yx)].(10)H(X, Y) = -\sum_{x,y} p(x,y) \log p(x,y) = -\sum_{x,y} p(x,y) [\log p(x) + \log p(y \mid x)]. \tag{10}

Splitting the sum:

=xp(x)yp(yx)logp(yx)yp(x,y)logp(x).(11)= -\sum_x p(x) \sum_y p(y \mid x) \log p(y \mid x) - \sum_y p(x,y) \log p(x). \tag{11}

The first term is H(YX)H(Y \mid X). For the second: yp(x,y)=p(x)\sum_y p(x,y) = p(x), so x,yp(x,y)logp(x)=xp(x)logp(x)=H(X)-\sum_{x,y} p(x,y) \log p(x) = -\sum_x p(x) \log p(x) = H(X). \blacksquare

Theorem 3 (Conditioning Reduces Entropy). H(YX)H(Y)H(Y \mid X) \leq H(Y), with equality iff XX and YY are independent.

Proof. From (9): H(Y)=H(X,Y)H(XY)H(Y) = H(X, Y) - H(X \mid Y) and H(YX)=H(X,Y)H(X)H(Y \mid X) = H(X, Y) - H(X). Alternatively, directly:

H(Y)H(YX)=x,yp(x,y)logp(y)+x,yp(x,y)logp(yx)=x,yp(x,y)logp(x,y)p(x)p(y)0,(12)H(Y) - H(Y \mid X) = -\sum_{x,y} p(x,y) \log p(y) + \sum_{x,y} p(x,y) \log p(y \mid x) = \sum_{x,y} p(x,y) \log \frac{p(x,y)}{p(x)p(y)} \geq 0, \tag{12}

since logp(x,y)p(x)p(y)0\log \frac{p(x,y)}{p(x)p(y)} \geq 0 iff p(x,y)p(x)p(y)p(x,y) \geq p(x)p(y) — the log-sum inequality gives non-negativity. Equality when p(x,y)=p(x)p(y)p(x,y) = p(x)p(y) everywhere. \blacksquare

Interpretation. Observing XX cannot increase average uncertainty about YY. Side information helps (or at least does not hurt) prediction.

Corollary 1 (General Chain Rule). For X1,,XnX_1, \ldots, X_n:

H(X1,,Xn)=i=1nH(XiX1,,Xi1).(13)H(X_1, \ldots, X_n) = \sum_{i=1}^{n} H(X_i \mid X_1, \ldots, X_{i-1}). \tag{13}

This decomposition is fundamental to sequential coding and autoregressive language models.


Mutual Information

Definition 4 (Mutual Information). The mutual information between XX and YY is:

I(X;Y)=H(X)H(XY)=H(Y)H(YX)=H(X)+H(Y)H(X,Y).(14)I(X; Y) = H(X) - H(X \mid Y) = H(Y) - H(Y \mid X) = H(X) + H(Y) - H(X, Y). \tag{14}

Theorem 4. I(X;Y)0I(X; Y) \geq 0, with equality iff XX and YY are independent.

Proof. From (12), H(Y)H(YX)0H(Y) - H(Y \mid X) \geq 0. \blacksquare

Interpretation. I(X;Y)I(X; Y) measures how much knowing YY reduces uncertainty about XX (equivalently, how much knowing XX reduces uncertainty about YY). It is symmetric: I(X;Y)=I(Y;X)I(X; Y) = I(Y; X).

Definition 5 (KL Connection — Preview).

I(X;Y)=DKL(p(x,y)p(x)p(y)),(15)I(X; Y) = D_{\text{KL}}(p(x,y) \| p(x)p(y)), \tag{15}

the KL divergence between the joint distribution and the product of marginals. Developed fully in KL Divergence.


Differential Entropy for Continuous Variables

Definition 6 (Differential Entropy). For continuous XX with PDF f(x)f(x):

h(X)=f(x)logf(x)dx.(16)h(X) = -\int_{-\infty}^{\infty} f(x) \log f(x)\, dx. \tag{16}

Key differences from discrete entropy:

  1. Can be negative. Example: XUniform(0,1/2)X \sim \text{Uniform}(0, 1/2) has h(X)=01/22log2dx=log2<0h(X) = -\int_0^{1/2} 2 \log 2\, dx = -\log 2 < 0.
  2. Not invariant to coordinate changes. Under Y=g(X)Y = g(X), h(Y)=h(X)+E[logg(X)]h(Y) = h(X) + \mathbb{E}[\log |g'(X)|].
  3. Not a direct coding bound (unlike discrete HH), but differences of differential entropies are meaningful.

Theorem 5 (Gaussian Maximum Entropy — Univariate). For fixed variance σ2\sigma^2, the Gaussian N(μ,σ2)\mathcal{N}(\mu, \sigma^2) maximizes h(X)h(X):

h(X)12log(2πeσ2),(17)h(X) \leq \frac{1}{2}\log(2\pi e \sigma^2), \tag{17}

with equality iff XN(μ,σ2)X \sim \mathcal{N}(\mu, \sigma^2).

Proof sketch. Lagrange multipliers on h(f)=flogfh(f) = -\int f \log f subject to f=1\int f = 1 and (xμ)2f=σ2\int (x-\mu)^2 f = \sigma^2. The optimizer satisfies logf(x)=1λ0λ1(xμ)2\log f(x) = -1 - \lambda_0 - \lambda_1(x-\mu)^2, i.e., ff is Gaussian. \blacksquare

Multivariate extension: see The Multivariate Gaussian, Theorem 9.


Maximum Entropy Principle

Principle (Maximum Entropy). Given constraints (e.g., known mean, variance, support), choose the distribution that maximizes entropy subject to those constraints. This is the least informative (most agnostic) distribution consistent with what is known.

Theorem 6 (Discrete Maximum Entropy). Among distributions on nn points with no further constraints, the uniform distribution maximizes H(X)H(X) at logn\log n.

Theorem 7 (Continuous — Fixed Mean and Variance). Among distributions on R\mathbb{R} with given mean μ\mu and variance σ2\sigma^2, the Gaussian maximizes h(X)h(X).

Theorem 8 (Exponential Family). Maximum entropy subject to constraints E[Tk(X)]=tk\mathbb{E}[T_k(X)] = t_k for sufficient statistics TkT_k yields an exponential family distribution:

p(x)exp(kλkTk(x)).(18)p(x) \propto \exp\left(\sum_k \lambda_k T_k(x)\right). \tag{18}

ML significance. Logistic regression arises from max-entropy with fixed mean constraints on features; Gaussian noise models arise from max-entropy with fixed variance. Prior selection in Bayes' Theorem often uses max-entropy reasoning.


Source Coding and the Entropy Lower Bound

Theorem 9 (Shannon's Source Coding Theorem — Informal). The expected code length for any lossless encoding of i.i.d. samples from pp is bounded below by H(X)H(X) bits per symbol. There exist codes (e.g., Huffman, arithmetic) achieving H(X)+o(1)H(X) + o(1).

Proof sketch (lower bound). For code lengths (x)\ell(x) with Kraft inequality x2(x)1\sum_x 2^{-\ell(x)} \leq 1, define q(x)=2(x)/Zq(x) = 2^{-\ell(x)} / Z. Then:

E[(X)]=E[logq(X)]+logZH(X)+logZH(X),(19)\mathbb{E}[\ell(X)] = \mathbb{E}[-\log q(X)] + \log Z \geq H(X) + \log Z \geq H(X), \tag{19}

since DKL(pq)0D_{\text{KL}}(p \| q) \geq 0. \blacksquare

Interpretation. Entropy is the fundamental limit of compression. Language models that achieve low cross-entropy are approaching the entropy of natural language — the irreducible randomness in text.


Connection to Machine Learning

Cross-Entropy Loss

For true distribution pp and model qq:

H(p,q)=xp(x)logq(x)=H(p)+DKL(pq).(20)H(p, q) = -\sum_x p(x) \log q(x) = H(p) + D_{\text{KL}}(p \| q). \tag{20}

Since H(p)H(p) is constant w.r.t. model parameters, minimizing cross-entropy \equiv minimizing KL divergence \equiv Maximum Likelihood Estimation.

For one-hot labels p=δyp = \delta_{y} and softmax output qq:

H(p,q)=logq(y),(21)H(p, q) = -\log q(y), \tag{21}

the standard classification loss.

Perplexity

For language models:

PPL=2H(p,q)=21Ni=1Nlog2q(xi).(22)\text{PPL} = 2^{H(p, q)} = 2^{-\frac{1}{N}\sum_{i=1}^N \log_2 q(x_i)}. \tag{22}

Perplexity kk means the model assigns on average the same probability as choosing uniformly among kk options. GPT-class models achieve perplexity 10\sim 103030 on diverse corpora; the entropy of English text is estimated at 1.0\sim 1.01.51.5 bits per character.

Information Bottleneck

Find representation TT of input XX that maximizes I(T;Y)I(T; Y) (relevant to target YY) while minimizing I(X;T)I(X; T) (compression):

minp(tx)I(X;T)βI(T;Y).(23)\min_{p(t \mid x)} I(X; T) - \beta I(T; Y). \tag{23}

This provides a theoretical framework for understanding what deep networks extract — task-relevant information at minimal complexity.

Decision Trees and Information Gain

Splitting a node on feature XjX_j maximizes information gain I(Y;Xj)=H(Y)H(YXj)I(Y; X_j) = H(Y) - H(Y \mid X_j) — the reduction in label entropy. ID3 and C4.5 use this criterion.


Common Pitfalls and Misconceptions

Pitfall 1: Treating differential entropy like discrete entropy. Negative differential entropy does not mean "negative information." Only differences (e.g., KL divergence) are invariant and interpretable in the continuous case.

Pitfall 2: Confusing entropy with variance. High variance does not always mean high entropy (e.g., a deterministic function of a high-entropy variable can have low entropy). Entropy depends on the full distribution, not just second moments.

Pitfall 3: Assuming H(YX)=0H(Y \mid X) = 0 means YY is a function of XX. It means YY is determined given XX, but YY could still be random if XX is unobserved.

Pitfall 4: Ignoring the base of the logarithm. Entropy in bits vs nats differs by ln2\ln 2. Cross-entropy loss in deep learning typically uses nats (ln\ln); perplexity uses bits (log2\log_2).

Pitfall 5: Equating low training cross-entropy with good generalization. H(p,q)H(p, q) on training data can be minimized while H(ptest,q)H(p_{\text{test}}, q) remains high — overfitting. See Bias–Variance Tradeoff.


Research Perspective

Claude Shannon's "A Mathematical Theory of Communication" (1948) established entropy, channel capacity, and source coding — founding information theory. Jaynes (1957) extended maximum entropy to statistical mechanics and Bayesian inference. The connection to ML emerged gradually: cross-entropy as classification loss (Bridle, 1990), the information bottleneck (Tishby et al., 1999), and modern use in language modeling evaluation.

Current research uses mutual information for representation learning (MINE, InfoNCE), studies entropy of neural network outputs for calibration, and applies information-theoretic bounds to generalization. The entropy of LLM-generated text and its relationship to human text entropy is an active measurement problem.


Summary of Takeaways

  • Self-informationI(p)=logpI(p) = -\log p — Per-sample surprisal
  • EntropyH(X)=plogpH(X) = -\sum p \log p — Average uncertainty
  • Conditional entropyH(YX)=H(X,Y)H(X)H(Y \mid X) = H(X,Y) - H(X) — Remaining uncertainty
  • Chain ruleH(X,Y)=H(X)+H(YX)H(X,Y) = H(X) + H(Y \mid X) — Autoregressive decomposition
  • Mutual informationI(X;Y)=H(X)H(XY)I(X;Y) = H(X) - H(X \mid Y) — Feature relevance
  • Cross-entropyH(p,q)=plogqH(p,q) = -\sum p \log q — Classification loss
  • Perplexity2H(p,q)2^{H(p,q)} — LM evaluation
  • Max entropy — Uniform (discrete), Gaussian (continuous) — Prior / noise selection

Next article: KL Divergence → — measuring discrepancy between distributions.


Exercises

Exercise 1 (Uniqueness). Verify that I(p)=log2pI(p) = -\log_2 p satisfies all four axioms for self-information.

Exercise 2 (Binary entropy). Plot Hb(p)H_b(p) and prove it is maximized at p=1/2p = 1/2 by differentiation.

Exercise 3 (Chain rule). Prove (13) by induction on nn.

Exercise 4 (Mutual information). Show I(X;Y)=DKL(p(x,y)p(x)p(y))I(X; Y) = D_{\text{KL}}(p(x,y) \| p(x)p(y)) using definitions.

Exercise 5 (Differential entropy). Compute h(X)h(X) for XUniform(a,b)X \sim \text{Uniform}(a, b) and verify (17) at equality when ba=12σb - a = \sqrt{12}\sigma.

Exercise 6 (Coding). For X{A,B,C}X \sim \{A, B, C\} with p=(1/2,1/4,1/4)p = (1/2, 1/4, 1/4), construct a prefix code and compare its expected length to H(X)H(X).

Exercise 7 (Conceptual). Why does minimizing cross-entropy not guarantee good test performance?

Exercise 8 (Proof). Complete the proof of Theorem 3 (conditioning reduces entropy) using the log-sum inequality.