A1149 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

A11 · Lesson 49 · Information and entropy

How many bits a random source really produces

A fair coin toss carries one bit of information, and a fair die about 2.6 bits. A biased coin that lands heads 99% of the time carries much less: you can nearly predict it, so seeing it tells you little. Shannon made this exact. The entropy of a random source, in bits per symbol, is the smallest average number of bits any code can use to describe it, and the same quantity sets how much information a noisy channel can carry. It's where probability becomes the theory of compression and communication.

  • The curve is the binary entropy H(p)=−plog2⁡p−(1−p)log2⁡(1−p): the information in one toss of a coin that lands heads with probability p.
  • It peaks at 1 bit for a fair coin and falls to 0 for a coin that always lands the same way.
  • The readout also gives the capacity of a binary channel that flips each bit with probability p: 1−H(p) bits per use.

Predict

A source emits A, B, C and D with probabilities 0.5, 0.25, 0.125 and 0.125. What is the fewest bits per symbol any code can average?

Name it

Entropy

For a source whose symbols have probabilities pi:

H=−∑ipilog2⁡pibits per symbol
  • H=0 when one symbol is certain; H=log2⁡n for n equally likely symbols, the most possible.
  • A symbol of probability p carries −log2⁡p bits of "surprise"; entropy is the average.

Source coding

No code can average fewer than H bits per symbol (without losing information), and codes like Huffman's come within one bit of it, or arbitrarily close when they encode blocks of symbols. That's the limit for every lossless compressor.

Channel capacity

A binary symmetric channel flips each bit with probability p. Its capacity is

C=1−H(p)bits per use

Shannon's theorem: below that rate, codes exist that make the error rate as small as you like; above it, they can't. For the Gaussian channel the capacity is Blog2⁡(1+SNR) bits per second.

Worked example

How much information does one roll of a fair die carry?

Show the solution
  1. Entropy. H=log2⁡6=2.585bits
  2. A 3-bit code. A 3-bit code per roll wastes 0.415 bits.
  3. Five rolls together. Coding five rolls together into one number from 0 to 7775 needs 13 bits, 2.6 per roll, nearly the limit.

Answer one roll carries 2.585 bits.

Worked example

A source emits A, B, C, D with probabilities 0.5, 0.25, 0.125, 0.125. Find its entropy and a code that achieves it.

Show the solution
  1. Entropy. H=0.5(1)+0.25(2)+0.125(3)+0.125(3)=1.75bits
  2. Huffman code. Huffman's method merges the two least likely symbols repeatedly and gives A = 0, B = 10, C = 110, D = 111.
  3. Average length. L¯=0.5+0.5+0.375+0.375=1.75bits
  4. Why it's exact. When every probability is a power of 12, the code meets the entropy exactly.

Answer the entropy is 1.75 bits, and the code A = 0, B = 10, C = 110, D = 111 achieves it.

Worked example

A channel flips 10% of its bits. What is its capacity?

Show the solution
  1. Binary entropy. H(0.1)=−0.1log2⁡0.1−0.9log2⁡0.9=0.332+0.137=0.469bits
  2. Capacity. C=1−0.469=0.531 bits per use.
  3. What it means. With good enough codes, about 53 bits of message can be sent reliably for every 100 sent over this channel, despite one in ten being wrong.

Answer the capacity is 0.531 bits per use.

Check

A source picks one of 10 symbols, all equally likely. What is its entropy?

Check

A coin lands heads with probability 0.1. How much information does one toss carry?

Check

A binary channel flips each bit with probability 0.05. What is its capacity per use?

Check

A channel has bandwidth 3 kHz and an SNR of 20 dB. What is its Shannon capacity?

Write units the way you normally would: 1.5 kb/s, 1500 b/s and 0.0015 Mb/s are the same answer.

Check

A source emits three symbols with probabilities 0.5, 0.3 and the rest.

(a)

What is its entropy?

(b)

What average length does the code 0, 10, 11 give?

Check

Find the binary entropy and where it peaks.

Step 1

What is H(p)?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Check

Write entropy(ps) returning −∑plog2⁡p (skipping zeros). Set h1 for a fair die and h2 for the probabilities 0.5, 0.25, 0.125, 0.125.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

Why does a channel that flips 10% of bits carry far less than 90% of a bit per use?

Practice

Keep practicing

7 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.