Entropy, Surprise, and Expected Code Length

Compute entropy as average surprise and compare the cost of coding under the true distribution and a different model.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. Rare outcomes carry more information per observation
  2. A coding model can spend more on the same outcomes

Rare outcomes carry more information per observation

For a discrete variable with probabilities \(p_i\), surprise for outcome \(i\) is \(-\log_2 p_i\). Taking the expectation gives entropy in bits. A fair bit has entropy one. A bit that is one with probability one-quarter has entropy about \(0.811\), since some outcomes are expected more strongly. Probabilities of zero contribute zero to the entropy sum by continuity.

A coding model can spend more on the same outcomes

If code lengths are modeled by \(-\log_2 q_i\) while outcomes follow \(p_i\), the expected ideal length is cross-entropy. Using a fair model for the biased bit costs one ideal bit, exceeding its own entropy. Exact symbol codes need integer lengths, so block or arithmetic methods can approach the ideal rate more closely. KL divergence measures the excess. Prefix codes give the constraint on integer code lengths.[1][2]

References

  1. Claude E. Shannon, A Mathematical Theory of Communication ↩
  2. David J. C. MacKay, Information Theory, Inference, and Learning Algorithms ↩