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 : the information in one toss of a coin that lands heads with probability .
- 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 : 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?
1.75 bits. The entropy is , and the code A = 0, B = 10, C = 110, D = 111 achieves it exactly: common symbols get short codewords. A fixed 2-bit code wastes a quarter of a bit per symbol.
Name it
Entropy
For a source whose symbols have probabilities :
- when one symbol is certain; for equally likely symbols, the most possible.
- A symbol of probability carries bits of "surprise"; entropy is the average.
Source coding
No code can average fewer than 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 . Its capacity is
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 bits per second.
Worked example
How much information does one roll of a fair die carry?
Show the solution
- Entropy.
- A 3-bit code. A 3-bit code per roll wastes 0.415 bits.
- 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
- Entropy.
- Huffman code. Huffman's method merges the two least likely symbols repeatedly and gives A = 0, B = 10, C = 110, D = 111.
- Average length.
- Why it's exact. When every probability is a power of , 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
- Binary entropy.
- Capacity. bits per use.
- 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 ?
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°.
Step 2
Its derivative is . Evaluate it (it's zero at ).
Check
Write entropy(ps) returning (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?
If you knew which bits were flipped you could fix them, and you'd keep 90%. But the receiver doesn't know: every received bit is uncertain, and resolving that uncertainty costs information. The uncertainty per bit is the binary entropy bits, so only bits of each use can carry the message. Error-correcting codes spend the rest on redundancy that lets the receiver locate and undo the flips; Shannon showed that at any rate below 0.53, the error rate can be driven as low as you like, and above it no code can do that.
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.