Claude Shannon and Information Theory
Claude Shannon (1916–2001) was an American mathematician and electrical engineer whose 1948 paper A Mathematical Theory of Communication founded the field of information theory — a framework for quantifying, storing, and transmitting information that underpins every digital system ever built. It matters profoundly to modern AI because the mathematical tools Shannon invented — entropy, mutual information, channel capacity — appear directly inside loss functions, compression algorithms, and the training objectives of neural networks. The counterintuitive fact: Shannon proved there is a hard mathematical limit to how efficiently information can be compressed, and another hard limit to how reliably it can be transmitted through a noisy channel — and both limits are achievable, even if you can never exceed them.
Information is a measurable physical quantity — just like mass or temperature — and the right unit to measure it in is the bit. The key insight is that "surprise" and "information" are the same thing: a message you were almost certain to receive carries almost no information, while a shocking, unexpected message carries a lot. Shannon made this precise: the rarer an event, the more information its occurrence conveys. This single idea connects probability directly to communication, compression, and — decades later — to how neural networks learn.
How It Works
At the heart of information theory is a deceptively simple formula. Suppose you have a source that produces messages drawn from an alphabet of symbols, each with some probability. Shannon asked: on average, how many bits do you need to encode one symbol?
Explanation: This is Shannon entropy — it computes the average number of bits needed to represent one symbol from source X, weighted by how often each symbol actually appears.
Symbols:
- — entropy of random variable , measured in bits
- — probability of the -th symbol occurring
- — logarithm base 2 (gives the result in bits; use natural log for nats)
- — sum over all possible symbols in the alphabet
A fair coin flip has maximum entropy: both outcomes equally likely, maximum surprise. A biased coin that lands heads 99% of the time has very low entropy — you're almost never surprised. The cross-entropy generalises this: instead of using the true distribution , you encode with a model distribution :
Explanation: Cross-entropy measures how many bits you waste when you use model q to encode data that actually comes from distribution p — the further q is from p, the higher the cost. This is exactly the cross-entropy loss function used to train classification neural networks in PyTorch and TensorFlow. Minimising it means making your model's predicted distribution as close as possible to the true distribution . ```python import math def shannon_entropy(probabilities): """ Calculate Shannon entropy in bits. probabilities: list of floats that sum to 1.0 """ return -sum(p * math.log2(p) for p in probabilities if p > 0)
# A fair coin: maximum entropy fair_coin = [0.5, 0.5] print(f"Fair coin entropy: {shannon_entropy(fair_coin):.3f} bits")
# → Fair coin entropy: 1.000 bits
# A biased coin: low entropy biased_coin = [0.99, 0.01] print(f"Biased coin entropy: {shannon_entropy(biased_coin):.3f} bits")
# → Biased coin entropy: 0.081 bits
# A 6-sided fair die: higher entropy fair_die = [1/6] * 6 print(f"Fair die entropy: {shannon_entropy(fair_die):.3f} bits")
# → Fair die entropy: 2.585 bits ``` Shannon also defined channel capacity — the maximum rate at which information can be reliably transmitted through a noisy channel:
Explanation: This is the Shannon–Hartley theorem; it says the maximum error-free data rate C through a channel equals its bandwidth B times a factor that grows with the signal-to-noise ratio S/N.
Symbols:
- — channel capacity in bits per second
- — bandwidth of the channel in Hz
- — signal-to-noise ratio (dimensionless)
This formula is why your Wi-Fi gets slower in a noisy environment — the ratio drops, reducing . ```python import math def channel_capacity(bandwidth_hz, snr): """ Shannon-Hartley theorem. bandwidth_hz: channel bandwidth in Hertz snr: signal-to-noise ratio (linear, not dB) Returns capacity in bits per second. """ return bandwidth_hz * math.log2(1 + snr)
# Typical Wi-Fi: 20 MHz bandwidth
# Good signal: SNR ≈ 100 (20 dB)
# Noisy signal: SNR ≈ 3 (5 dB) bw = 20e6 # 20 MHz print(f"Good signal capacity: {channel_capacity(bw, 100)/1e6:.1f} Mbps") print(f"Noisy signal capacity: {channel_capacity(bw, 3)/1e6:.1f} Mbps")
# → Good signal capacity: 132.9 Mbps
# → Noisy signal capacity: 40.0 Mbps ```
Shannon grew up in Gaylord, Michigan, tinkering with radios and building a telegraph from barbed wire to a friend's house half a mile away; he later earned degrees in electrical engineering and mathematics from MIT. His 1948 paper A Mathematical Theory of Communication, published in two parts in the Bell System Technical Journal, single-handedly created information theory — it defined entropy, channel capacity, and source coding theorems that remain the bedrock of every digital communications system today. A surprisingly playful character, Shannon was known for riding a unicycle through the hallways of Bell Labs while juggling, and he built a chess-playing machine called "Caissac" and a flame-throwing trumpet as personal side projects.
Intuition
Imagine you receive a text message from a friend. If the message says "the sun rose this morning," you learn almost nothing — you already knew that with near-certainty. But if the message says "I just won the lottery," your jaw drops: that's high-information content because it was very unlikely. Shannon's entropy is exactly that intuition, averaged over all the messages a source could send. Think of entropy as the "surprise budget" of a communication source. A weather forecast for the Sahara in July (always sunny) has near-zero entropy — no budget needed. A weather forecast for London (anything is possible) has high entropy — a big surprise budget is required. The entropy tells you the minimum number of yes/no questions you'd need to ask on average to identify which message was sent — which is also the minimum number of bits needed to encode it. For neural networks, cross-entropy loss works the same way: when the model is confidently wrong, cross-entropy is very high (big surprise). When the model is confidently right, cross-entropy is near zero. Training minimises the average surprise.
Historical Development
Origins · 1 minhow this was discovered
Why It Matters
Prerequisites
What This Leads To
See Also
Alan Turing and the Foundations of Computation · Maximum Likelihood Estimation · Entropy Regularisation in Reinforcement Learning · Huffman Coding and Data Compression · Perplexity as a Language Model Metric