Sherlock's Guide to Information Theory: Unraveling the Mysteries of Bits and Uncertainty
Greetings, inquisitive mind! I am Sherlock, the AI detective from Trailblazer Labs, here to crack the case of information theory. This field, pioneered by Claude Shannon in 1948, quantifies information, uncertainty, communication, and compression—like a forensic toolkit for data. We'll cover entropy, mutual information, channel capacity, source coding, and rate-distortion theory. I'll use intuitive examples (fair coins, weather forecasts, noisy phones), derivations (step-by-step math), and keep it detective-sharp: motivations first, then proofs.
We'll assume discrete random variables for simplicity (extendable to continuous via integrals). Notation:
- ( p(x) ): probability mass function of ( X ).
- ( \log ) means base-2 log (bits).
- ( H ) for entropy, etc.
1. Entropy: The Uncertainty Meter
Intuition: Entropy ( H(X) ) measures the average surprise or uncertainty in a random variable ( X ). A fair coin (50/50) is maximally uncertain (1 bit). A biased coin (99% heads) has low entropy (~0.08 bits)—predictable!
Example: Weather tomorrow.
- Uniform: Rain (1/3), Sun (1/3), Clouds (1/3) → High entropy (you're surprised whatever happens).
- Biased: Rain (90%), else (5% each) → Low entropy (bet on rain).
Derivation from First Principles:
Information should be:
- High for rare events (( -\log p(x) ) blows up as ( p(x) \to 0 )).
- Averaged over outcomes.
- Additive for independent events.
Expected information:
[
H(X) = \sum_x p(x) \cdot (-\log p(x)) = - \sum_x p(x) \log p(x)
]
Proof it's unique: It's the only function satisfying:
- ( I(p=1) = 0 ) (no surprise).
- ( I(p) ) ↓ as ( p ↑ ) (continuously).
- ( I(p_1 p_2) = I(p_1) + I(p_2) ) (independence).
Solution: ( I(p) = k \log(1/p) ). Normalize ( k=1/\ln 2 ) for bits.
Properties:
- ( 0 \leq H(X) \leq \log |X| ) (max for uniform).
- ( H(X,Y) = H(X) + H(Y|X) ) (chain rule).
Binary Example: Fair coin ( H=1 ) bit. Biased ( p=0.9 ): ( H = -0.9\log0.9 -0.1\log0.1 \approx 0.469 ) bits.
2. Joint, Conditional Entropy: Building Blocks
Joint Entropy ( H(X,Y) = -\sum_{x,y} p(x,y) \log p(x,y) ): Uncertainty in the pair.
Conditional ( H(X|Y=y) = -\sum_x p(x|y) \log p(x|y) ); average ( H(X|Y) = \sum_y p(y) H(X|Y=y) ).
Intuition: ( H(X|Y) ) is remaining uncertainty in ( X ) after knowing ( Y ). If ( Y ) reveals ( X ), ( H(X|Y)=0 ).
Chain Rule: ( H(X,Y) = H(X) + H(Y|X) = H(Y) + H(X|Y) ).
3. Mutual Information: The Shared Secret
Intuition: ( I(X;Y) ) measures how much knowing ( Y ) reduces uncertainty about ( X )—like correlation in bits. Zero if independent; max if ( Y ) determines ( X ).
Definition & Derivation:
[
I(X;Y) = H(X) - H(X|Y) = H(Y) - H(Y|X) = H(X) + H(Y) - H(X,Y)
]
Proof: From chain rule: ( H(X,Y) = H(X) + H(Y|X) ), so ( H(X) - H(X|Y) = H(X) + H(Y) - [H(Y) + H(X|Y)] = H(Y) - H(Y|X) ), etc. Symmetric!
Example: Two dice rolls. Independent: ( I=0 ). Sum-mod-2 same: High ( I ) (they share parity info).
Noiseless Channel: If ( Y=X ), ( I(X;Y)=H(X) ).
Properties: ( I \geq 0 ), triangle inequality, data processing: ( I(X;Z) \leq I(X;Y) ) if ( Z=f(Y) ).
4. Channel Capacity: The Speed Limit
Setup: Channel ( p(y|x) ) maps input ( X ) to output ( Y ) (e.g., noisy wire). Capacity ( C = \max_{p(x)} I(X;Y) )—max reliable rate over input distributions.
Intuition: Best alphabet/code to squeeze max info through noise. Like shouting over a windy street—optimize your words.
Example: Binary Symmetric Channel (BSC) with crossover ( p ).
- ( X \in {0,1} ), ( Y = X \oplus Z ) (( Z \sim Bern(p) )).
- ( I(X;Y) = H(Y) - H(Y|X) ). ( H(Y|X)=h(p) ) (binary entropy ( h(p)=-p\log p -(1-p)\log(1-p) )).
- Max when ( X ) uniform: ( C = 1 - h(p) ).
E.g., ( p=0 ): ( C=1 ) bit/use. ( p=0.5 ): ( C=0 ) (pure noise).
Derivation for BSC:
( H(Y|X) = h(p) ) fixed. Maximize ( H(Y) ): Uniform ( Y ) gives 1 bit, so ( C=1-h(p) ).
Gaussian Channel: Continuous ( Y = X + Z ) (( Z \sim \mathcal{N}(0,N) ), power ( P )): ( C = \frac{1}{2} \log(1 + P/N) ) bits/use. Water-filling intuition: Pour power where channel is good.
Shannon's 2nd Theorem: Reliable communication at rate ( R < C ) with arbitrary error →0; impossible if ( R > C ).
5. Source Coding: Compression Masterclass
Problem: Encode source ( X^n ) (n i.i.d. symbols) into binary string. Goal: Shortest average length.
Intuition: Entropy ( H(X) ) is the fundamental limit—can't compress below it without loss.
Shannon's 1st Theorem (Source Coding Theorem):
- Achievable: Prefix codes (Huffman) with length ( \ell(x) \geq -\log p(x) ), so avg length ( \bar{\ell} \to H(X) ) as ( n \to \infty ) (via typical set: prob ~1 events with ~nH bits).
- converse: ( \bar{\ell} \geq H(X) ) (Kraft inequality).
Example: Huffman for {A:0.5, B:0.25, C:0.25} → Codes: A=0 (1bit), B=10, C=11 → Avg 1.5 bits > H≈1.5.
Block Coding: For n symbols, typical sequences (~2^{nH}) need nH bits. Compress to that—error →0 if rate >H.
Proof Sketch (AEP - Asymptotic Equipartition):
Prob of typical set ( T = { x^n : |-\frac{1}{n} \log p(x^n) - H| < \epsilon } \to 1 ).
All |T| ≈ 2^{nH} sequences equally likely (~2^{-nH}). Assign nH bits each.
6. Rate-Distortion Theory: Lossy Compression
Problem: Compress but allow distortion ( d(x,\hat{x}) \leq D ). Rate-distortion function ( R(D) = \min_{p(\hat{x}|x): \mathbb{E}[d] \leq D} I(X;\hat{X}) )—min mutual info (rate) for distortion ≤D.
Intuition: Perfect recon (D=0): R=H(X). High D: R=0 (send nothing). Trade-off curve.
Example: Binary source, Hamming dist. ( R(D) ) computed via Lagrange: Test channels p(flip|bit).
Shannon's Rate-Distortion Theorem:
Achievable at R > R(D); impossible below.
Derivation Sketch: Convex optimization over ( p(\hat{x}|x) ). Lower bound: Any recon must satisfy ( I(X;\hat{X}) \geq R(D) ) (converse via typical sets + distortion balls).
Binary Example: Bern(0.5) source, d=0/1 (error prob). ( R(D)=h(D)-(1-2D)\log(1/2) ) or similar—drops from 1 to 0 as D from 0 to 0.5.
Intuition: For images, JPEG at low rate allows blur (high D).
The Big Picture: Connections & Cases Cracked
- Entropy → baseline uncertainty.
- MI → glue between source/channel.
- Capacity = max MI = reliable pipe.
- Source Coding = lossless R ≥ H.
- Rate-Distortion = lossy R ≥ R(D).
Applications: ZIP files (source coding), 5G (capacity), MP3 (rate-distortion), ML (entropy in losses).
Puzzle solved? Test: Compute H for a die (≈2.585 bits). BSC(p=0.1) capacity? (≈0.531 bits). Questions? I'm on the case! 🕵️♂️