Information TheoryDeeper

Kayavak / Information Theory / IT·04 Entropy: the Average Surprise of a Source / Deeper

Deeper · Information Theory

Entropy: the Average Surprise of a Source

The questions the chapter doesn't stop for: why this exists, the model to keep in your head, what changes when an assumption does, how sure we are of each claim, and what's still open. Read it after the chapter; back to the chapter.

Why does this exist?

The formula −∑plogp appeared in physics before communication. Ludwig Boltzmann, explaining in the 1870s why heat flows from hot to cold, measured the disorder of a gas by the logarithm of the number of molecular arrangements consistent with what we can observe; J. Willard Gibbs (1902) wrote the version with probabilities, which has exactly Shannon's form. In the 1920s Leo Szilard connected a single bit of knowledge about a molecule to a definite amount of physical entropy. None of this was about messages.

Shannon came to the same formula from the other side, asking how to measure the uncertainty of a source, and proved in 1948 that any measure that's continuous in the probabilities, grows with the number of equally likely outcomes, and can be computed in stages (grouping) must be a multiple of it. His entropy was immediately useful because of what it predicted: compression to H bits per symbol and no further. The link back to physics was made by E. T. Jaynes (1957), who argued that statistical mechanics is simply inference with the maximum-entropy distribution consistent with what's known, and by Rolf Landauer (1961), who showed that erasing a bit has a minimum physical cost. The Beautiful Intersections shelf follows that thread.

The mental model

Try it yourself first: write your own model in the Mental Model Explorer, then compare.

Entropy is the average surprise of a source: how many yes-or-no questions, or binary digits, per symbol the best possible strategy needs on average. It's largest when every symbol is equally likely and zero when one is certain.

Question Answer
What is it? H =∑p(x)log21p(x), the expected value of surprise
Problem it solves One number for how much information a source produces, and so how far its output can be compressed
Parts A set of symbols, a probability for each, surprise per symbol, a weighted average
How it works Frequent symbols carry little surprise, rare ones a lot; weighting by frequency gives the average
Assumptions A fixed, known distribution; symbols independent (for order-0 entropy)
When they change Dependence between symbols lowers the entropy per symbol (ch07); unknown probabilities cost extra (ch11)
Where it fails Single messages, worst cases, and meaning: entropy is an average property of a model
Related ideas Surprise (ch01), expected value (ch03), codes (ch05), the source coding theorem (ch06)

What if?

What if we averaged probabilities instead of surprises?

Reason it through, then open

The average probability ∑p(x)2 (the chance that two independent draws match) is a real quantity, called the collision probability, and −log2∑p(x)2 is the collision entropy (Rényi entropy of order 2). It's always at most the Shannon entropy and it matters for hashing and for how fast a password guesser expects to succeed. But it doesn't add for independent sources in the way grouping requires, and it isn't the limit of compression. Rényi (1961) found a whole family of such entropies; Shannon's is the one with the grouping property, and the one coding theorems are about.

What if the probabilities you use are wrong?

Reason it through, then open

A code built for probabilities q when the true ones are p costs ∑p(x)log21q(x) bits per symbol on average, the cross-entropy, which is always at least the true entropy H(p). The excess, ∑p(x)log2p(x)q(x), is the Kullback–Leibler divergence: zero only when q=p. Chapter 11 builds on it; it's the quantity machine learning minimises when it fits a model to data.

What if a source had infinitely many symbols?

Reason it through, then open

Entropy can still be finite: a geometric distribution over the whole numbers 1, 2, 3, … with p(k)=2−k has entropy exactly 2 bits, since ∑k2−k=2. But it can also be infinite: probabilities falling slowly enough, like p(k) proportional to 1k(logk)2, add up to 1 while their surprises, weighted, don't add up to anything finite. A source like that can't be compressed to any fixed average number of bits per symbol, however clever the code.

Where the boundary is

Aspect Entropy of a source Surprise of a message
Belongs to A probability model of everything that might be sent One outcome
Formula ∑plog21p log21p
Can be larger than log2K? No Yes, for rare outcomes
Units Bits per symbol, on average Bits, for this outcome
Tells you The average cost of the best code The cost of this message under the best code, roughly
In the lab 0.469 bits for a 90/10 coin 0.152 bits for heads, 3.32 for tails

Derive it

Why grouping forces the logarithm, for equally likely outcomes.

  1. Let A(n) be the uncertainty of n equally likely outcomes. Shannon asked that A grow with n and that grouping hold.
  2. Take nk equally likely outcomes and group them into n groups of nk−1. Grouping says A(nk)=A(n)+A(nk−1): choose the group, then the outcome within it (each group equally likely, so the second stage always costs A(nk−1)). Repeating, A(nk)=kA(n).
  3. For any s and t at least 2 and any large m, pick k with sk≤tm<sk+1. Because A grows, kA(s)≤mA(t)<(k+1)A(s), so A(t)A(s) lies between km and k+1m.
  4. Taking logarithms of the same inequality, logtlogs lies between the same two bounds. So |A(t)A(s)−logtlogs|≤1m for every m: the two ratios are equal.
  5. So A(n)=clogn for a constant c>0. Grouping unequal probabilities as fractions of equally likely outcomes then gives H=−c∑plogp (continuity covers probabilities that aren't fractions).

How sure are we?

Claim How it's known Where from
0≤H≤log2K, with equality only for certainty and uniformity Theorem The chapter's proof from lny≤y−1
Entropy is the only measure with continuity, growth and grouping Theorem Shannon (1948), appendix 2; the derivation above
No code can average fewer than H binary digits per symbol Theorem Proved in chapter 5
Shakespeare's letters have order-0 entropy 4.19 bits Measured The chapter's lab, on Tiny Shakespeare
English carries about 1 bit per letter with full context Measured, roughly Shannon (1951) guessing experiments; later estimates from models vary from about 0.6 to 1.3
Plug-in estimates are biased low Theorem Jensen's inequality; measured in the lab
Von Neumann suggested the name Historical, anecdotal Tribus and McIrvine (1971), reporting Shannon

Still open

Estimating the entropy of natural language remains open in a practical sense: each better model (n-grams, then neural networks, then large language models) has lowered the measured bits per character, and nobody knows how low the true figure is. Estimating entropy from limited samples of distributions with many rare outcomes (words, species, genetic variants) is an active research area, with estimators that work far better than plug-in ones on small samples.

What would change your mind? The chapter says no code can average fewer than H bits per symbol. A code that did, on a long run of genuinely independent symbols from a known distribution, would contradict a theorem; what happens in practice is that someone measures H with the wrong model (ignoring context) and a compressor with a better model "beats" it. The claim is always relative to the true distribution.

Recall

What is the entropy of a source?

Its expected surprise, H = Σ p log₂(1/p), in bits per symbol.

What's the most entropy a source with K symbols can have?

log₂ K, only when all K are equally likely.

What's the entropy of a coin that lands heads 90 % of the time?

About 0.469 bits.

What does the grouping property say?

Entropy can be computed in stages: choose a group, then a member, weighting each later stage by its group's probability.

Why are entropy estimates from small samples too low?

Rare symbols are often missing and frequencies vary, so the sample looks more predictable than the source.

What's redundancy?

1 − H / log₂ K: the fraction of the alphabet's capacity a source doesn't use.

Reflect

Be honest with yourself; this stays in your browser. Anything you can't tick yet is what to revisit.