Part I · Chapter 2

Entropy: Average Surprise

One outcome has a surprise. A whole source of outcomes, a coin, a die, a weather station, a language, has an average surprise. That average is called entropy, and it will turn out to be the exact price of describing the source.

Suppose you promise to text a friend every evening to say whether your bus was late. On a route where the bus is late about half the time, every text is real news: your friend cannot guess it. On a route where the bus is late about once a month, nearly every text says "on time". Your friend could almost write them for you. The rare "late" is a jolt when it comes, but it hardly ever comes.

Which stream of texts carries more information per text, on average? Chapter 1 gave us the tool to answer: the surprise of each outcome, log₂(1/p) bits. Now we simply average it, weighting each outcome by how often it happens.

The coin that is not quite fair

Start with the simplest source there is: a coin, possibly bent. Slide the chance of heads and watch three things together: the two probabilities, the surprise of each face, and their weighted average, the entropy, tracing out an arch.

Interactive 2.1The Entropy Arch
Slide the coin's bias
probability of heads / tails surprise of each face (bits) entropy: the average surprise per flip
0.80
 
At 50/50 the arch peaks at exactly 1 bit per flip. Bend the coin and the rare face gets more surprising, yet it shows up so seldom that the average falls. A coin that lands heads about 89% of the time is worth only about half a bit per flip. The sample strip uses the same random draws as you slide, so you can watch it fill with heads.

Look at the two ends. A coin that always lands heads has zero entropy: you know the answer before it is flipped, so the flip tells you nothing. A fair coin is the most uncertain a two-sided thing can be. In between, the arch is smooth and symmetric: a 70/30 coin is exactly as unpredictable as a 30/70 coin, because it does not matter which face is the common one.

H = Σ p(x) · log₂( 1 / p(x) ) "Entropy is the surprise of each outcome, weighted by how often that outcome happens, added up." It is the average surprise, in bits per outcome.

For the bus question: the 50/50 route carries 1 bit per text. The once-a-month route (a late bus about 1 day in 30) carries about 0.21 bits per text. Most of its texts are "on time", which costs only a few hundredths of a bit each.

Entropy

Entropy is the average surprise of a source: how much you learn, on average, each time it produces an outcome.

Entropy belongs to the source, not to one message

Here is a distinction that trips up even careful people. Entropy is a property of a probability model: a coin with a given bias, a die with given weights, a weather station with given odds. A single message, say the ten flips HHHHHHHHHH, does not have an entropy. It has a surprise, and only relative to some model. Under a fair-coin model those ten heads have probability 1/1,024 and carry 10 bits of surprise, exactly like every other specific run of ten flips.

We will often compute an entropy from the letter counts of one particular text. When we do, we will say so plainly: it is the entropy of the letter-frequency model built from that text, the model that says "each character is drawn independently with these frequencies". That model can be a poor description of the real thing. The text "abababab" has two letters at 50% each, so its letter-frequency model has 1 bit per letter, even though anyone can see the pattern and predict every letter after the first. Keep that example in your pocket; it comes back in Chapters 5 and 7.

Dice, fair and loaded

With more outcomes there is more room for uncertainty. A fair coin has 1 bit; a fair four-sided die has log₂ 4 = 2 bits; a fair six-sided die has log₂ 6 ≈ 2.585 bits. In general, N equally likely outcomes have an entropy of log₂ N, and that is the most any N-outcome source can have. Load the die and the entropy can only go down.

Below you can load a die however you like. Drag the top of any bar up or down (or use the face selector and slider). The bottom strip splits the entropy into each face's contribution: its probability times its surprise.

Interactive 2.2The Loaded Die Designer
Drag the bars, or pick a preset
probability of each face surprise of each face entropy (filled) and the fair-die maximum, log₂ 6 (outline)
17
 
Notice the rare faces: their surprise is large, but their contribution is small, because they rarely happen. The fair die fills the outline exactly; every kind of loading leaves a gap. "Always six" collapses to zero bits.

Average surprise, earned roll by roll

"Average" deserves a test. If entropy really is the average surprise, then rolling the die many times and averaging the surprise of what actually comes up should drift toward the entropy. Roll the die you designed above and watch the running average settle.

Interactive 2.3The Running Average
Roll the die from 2.2, a few or many times
surprise of each roll (dots) and running average (line) entropy of the die you designed
 
Single rolls jump around: a rare face can cost 5 or 6 bits, a common one a fraction of a bit. The running average wobbles early and then hugs the entropy line. Change the die in 2.2 and the line moves; reset and roll again.

This is the law of large numbers at work: averages of many independent rolls settle near their expected value. Entropy is an expected value, the expected surprise. The Order from Chaos chapter of the probability book shows the same settling for other averages.

That settling is the seed of the most practical fact in this book. Over a long run of N rolls, the total surprise is almost always close to N × H bits. In Part II we will see that this total is also, almost exactly, the number of binary digits you need to record the rolls when you use the best possible code. Entropy is not just a measure of uncertainty; it is a price tag.

Two facts to carry forward

For N possible outcomes, entropy is highest, log₂ N bits, when all are equally likely. Any lopsidedness lowers it, and lower entropy means the source is easier to predict and cheaper to describe.

Intuition Check

A die is loaded so that six comes up half the time; faces one to five share the other half equally. How does its entropy compare with a fair coin's 1 bit?

Intuition Check

A fair coin is flipped ten times and lands HHHHHHHHHH. What is the entropy of that message?

Connections

What you now see

  • Entropy is the average surprise of a source, H = Σ p · log₂(1/p), in bits per outcome.
  • A coin's entropy traces an arch: 0 when it is certain, 1 bit when it is fair.
  • N equally likely outcomes give the maximum, log₂ N bits; loading the dice always lowers it.
  • Entropy belongs to a probability model, not to a single message. A message has a surprise under a model.
  • Averaging the surprise of many independent outcomes settles at the entropy, which is why it will become the price of compression.