Text "mississippi" — Shannon entropy

exam standardempirical entropy of a string

Answer

1.8231 bits

Why this example is worth doing

The same string as the Huffman example, so the two tools can be compared directly on one input. The page is careful to call this the empirical zeroth-order entropy: it treats each character as independent, which is a poor model for English, where q is followed by u almost always. Real text has much lower entropy once context is taken into account, and the page says so rather than overclaiming.

Try your own input in the Shannon entropy. Bits per symbol for any distribution, with the surprisal of each symbol shown.

How the answer is reached

Shannon entropy of 4 symbols

4 symbols, 11 total occurrences. Divide by the total to get probabilities, then take −Σ p·log₂ p.

The surprisal column is the ideal code length; Huffman rounds it to whole bits. — Shannon entropy of 4 symbols
SymbolpSurprisal −log₂ p (bits)Contribution p·(−log₂ p)
i0.3636361.4594320.530702
m0.0909093.4594320.314494
p0.1818182.4594320.447169
s0.3636361.4594320.530702

H1.823068 bits/symbolthe probability-weighted mean of the surprisal column

Total information20.053748 bits11 symbols × H

Maximum possible H2.000000 bits/symbollog₂(4), reached only by the uniform distribution

H / log₂(m)0.911534how close to uniform this source is

Warning:

A symbol of probability 0 contributes exactly 0: the convention 0·log₂0 = 0 is a definition (the limit as p → 0), not an approximation. Evaluating it instead returns NaN, which is the usual bug on this page.

Source: C. E. Shannon, Bell System Technical Journal 27:379–423 (1948), Theorem 2

Compare with

Open this example in the Shannon entropy

The field arrives filled in with this example’s input.

Note:

Notation this page assumes

  • Bit strings are written most significant bit first, and bit 0 is the least significant bit.
  • A width is stated explicitly wherever it changes the answer; nothing is silently sign-extended or truncated.
  • Entropy is in bits per symbol — logarithms base 2 — and 0·log 0 is taken as 0.

Sources

  • Shannon, “A Mathematical Theory of Communication” (1948)