This text aims at intuitively explaining and proving the main definitions and theorems of Shannon's information theory with limited prerequisites; this includes: cross/conditional entropy, KL-divergence, mutual information, asymptotic codelength property (variant of AEP), source and channel coding theorems. It contains a new constructive proof of the coding theorem for discrete memoryless channel and an other non constructive proof of achievability of Shannon's capacity for the bit-flip channel.
The target audience is "undergraduates/good high school students" but anyone is welcome here.
Find the coin
As a playful formalist, I would like to introduce the subject with a small game. ;)
A coin is hidden among four opaque cups. At each round, we ask yes/no questions to uncover the cup concealing the coin. Multiple rounds are played and we aim to minimize the number of questions asked.
We first assume the coin has 1 in 4 chances to be under each cup such that the best strategy is a binary search asking 2 questions per round.
But after playing a few rounds, we notice the coin has in fact 1 in 2 chance to be in the first cup, 1 in 4 to be in the last one and 1 in 8 to be in the others. If we update our questionnaire asking: "Is the coin in the first cup? Is the coin in the last cup? Is the coin in this remaining cup?” we will ask on average only 21+41×2+(81+81)×3=1.75 questions per round.
Now imagine playing the same game using only two cups with a 70% chance for the coin to be in the first cup and 30% chance to be in the other. Here, we must ask one question per round.
But let's change the rules of the game allowing questions relative to two simultaneous rounds. There is a 49% chance for the two coins to be in their first cups, 9% chance for them to be in their last cups and 21% for the two other cases. The best strategy will ask 21(0.49+0.21×2+(0.21+0.09)×3)=0.905 questions per coin.
Entropies and KL divergence
Given n cups and their probabilities to contain the coin p1,…,pn, as we increase the number of simultaneous rounds, the number of questions per coin of the best strategy will converge to,
This is the entropy of the distributionp and is denoted H(p). If a single-round optimal strategy exists, we can view it as a decision tree: −log2(pi) is the length of the branch we will follow with probability pi when the coin is found in the ith cup.
Now if we assume the wrong distribution q, the number of questions we ask on average is:
−i=1∑npilog2(qi)
This is the cross-entropyH(p,q) and it is not symmetric. As expected:
H(p,q)≥H(p)
The difference is called Kullback-Leibler divergence, we note:
DKL(p∥q)=H(p,q)−H(p)
In the rest of the text we will drop the 2 from log2 for simplicity.
This is left as an exercise but rest assured from that point on we will prove everything.
Source coding theorem (lower bound)
For a discrete random variable X, a binary encoding b of X is an injection from the domain of X to the set of binary strings. Noting BX=b(X) and BXi the binary random variable given by the ith bit when the length BX⩾i. For a such binary encoding we have:
Using the fact that for any B binary random variable H(B)≤1.
Source coding theorem (upper bound)
Given ϵ>0 and n>1, noting Xn a sequence of n random variables from a same distribution, there exists a binary encoding BXn such that:
nH(X)≤E[BXn]≤n(H(X)+ϵ)
From the conditional entropy formula we have H(Xn)=nH(X), so the left inequality is given by our previous result.
For the right hand side, we first notice that given some naturals l1≤⋯≤ln where ∑2−li≤1 we can build binary strings of lengths l1,…,ln such that no string is the prefix of another.
Indeed, 1−∑2−li is a multiple of 2−ln, such that adding 2ln−∑2ln−li times ln to our set of lengths we get ∑2−li=1. Then, if we prune an infinite binary tree at these lengths, the set of paths from the root to the leafs described using left/right instructions will form a valid prefix-distinct set of binary strings.
Now if we pick the lengths as ⌈−log2P(Xn=(x1,…,xn))⌉ then:
Given n>1, some sequence of n discrete random variables Xn and some logical statement S(Xn), we will say that S(Xn) holds almost surely asymptotically (a.s.a.) if we have:
n→∞limP(S(Xn))=1
Let m>1, using previous notation, we can encode Xnm=(X1n,…,Xmn) as BXnm=BX1n…BXmn since the encoding BXn is prefix-distinct.
Given a sequence of k discrete random variables Yk sampled from a conditional distribution P(Y=y∣X=x) we can similarly consider of the conditional encoding BYk∣Xk=xk.
With the weak law of large number we have a.s.a. H(Yk∣Xk=xk)∈[kH(Y∣X)±o(k)]. Pairing this result with the above construction we get a.s.a. BYk∣Xk=xk∈[kH(Y∣X)±o(k)].
Prefix tree rebalancing
BYk∣Xk=xk is a prefix distinct encoding as concatenation of prefix distinct encodings.
Given ϵ>0, we can then perform a rebalacing of the prefix distinct tree defining BYk∣Xk=xk as follow:
if BYk∣Xk=xk(yn)<k(H(Y∣X)−ϵ) pad it with ones to length k(H(Y∣X)−ϵ)
use the new internal nodes with a single child to graft branches pruned from length k(H(Y∣X)−ϵ)
We repeat these two operations till the level k(H(Y∣X)−ϵ) of the binary tree is "full" or there is no branch left to prune.
We can bound the increase in expected length from the padding step by P(BYk∣Xk=xk(yn)<k(H(Y∣X)−ϵ))H(X∣Y)k=∣o(k)∣, and the grafting step followed by the second padding step only decrease the expected length (inductively for following iterations).
For large enough k, the rebalancing procedure terminates with a full k(H(Y∣X)−ϵ) level since a.s.a. H(BYk∣Xk=xk)=H(Yk∣Xk=xk)∈[kH(Y∣X)±o(k)]. Let's pick such k.
Since this is valid for any ϵ>0 we can pick a suitable o(k) such that ϵ=∣o(k)∣/k.
Unification of prefix encodings using branch permutations
After the rebalancing we can view the prefix from BYk∣Xk=xk of length kH(Y∣X)−∣o(k)∣ as defining a family of surjections indexed by xk from the domain of Yk to binary strings of said length.
We can then consider the right inverses fxk (note we don't need the axiom of choice since all sets are finite) such that prefixkH(Y∣X)−o(k)(BYk∣Xk=xk)∘fxk=BYk∣Xk.
Note that BYk∣Xk is a function of yk that does not depend upon the realisation xk of Xk. Using H(BYk∣Xk=xk)∈[kH(Y∣X)±o(k)] we have H(BYk∣Xk)=kH(Y∣X)−∣o(k)∣.
Similarly, the suffix BYk∣Xk=xk′ has an entropy of ∣o(k)∣. We are now ready to dive into the channel coding theorem.
Channel capacity
A communication channel is modeled by a source of input messages X transmitted and received as output messages Y on the other end of the channel. The conditional distribution P(Y∣X) defines the reliability of the channel.
Given a fixed conditional distribution P(Y∣X), we can try to modify the distribution of the input messages P(X) to maximize the mutual information I(X,Y). This maximal mutual information is called the capacity of the channel.
Channel coding theorem
Given n pairs of discrete random variables sampled from a joint probability distribution, we note Xn and Yn the deinterlaced sequences.
Let (en) and (dn) be sequences of functions such that H(en(Xn)∣dn(Yn))=∣o(n)∣ and H(dn(Yn)∣en(Xn))=∣o(n)∣. If we note,
he,d=nsupn1H(en(Xn))=nsupn1H(dn(Yn))
then:
e,dsuphe,d=I(X,Y)
Channel coding proof (achievability)
For the rest of the proof we will note C=I(X,Y) and n>1.
We first remark we can encode (Xn,Yn) in two ways:
BXn∣YnBXn∣BXn∣YnBYn∣XnBX′
BYn∣XnBYn∣BYn∣XnBXn∣YnBY′
with H(BX′)=∣o(n)∣ and H(BY′)=∣o(n)∣ as concatenations of various suffixes.
And the bound is reached when P(Y=0)=1/2 that is when P(X=0)=1/2.
From now on, we will note h(p)=−plog2p−(1−p)log2(1−p).
Bonus 2: proof of achivability for the bit flip channel
The idea of the proof consists in taking a random set of binary strings of given length n and to show that if this set contains less than 2n(C−ϵ) strings, for any ϵ>0, we will be almost certain to recognize the strings after a transmission as n goes to infinity.
Let's assume η>0 is our targeted probability of error. If we transmit a random string of length n chosen among a set of size 2nR, the number of bit flips F will follow a binomial distribution with parameters n and p.
Now assuming ∣F−np∣<kp(1−p)n, we must find a condition on R such that the probability of having an other transmitted string in a radius of np+kp(1−p)n flips is lower than η/2.
Since the set of strings is chosen uniformly at random, the number of flips F′ from the original transmitted string to any other transmitted string will follow a binomial distribution of parameters n and 1/2. So we need:
perror=1−(1−P(F′<np+kp(1−p)n))2nR−1≤2η
Using the fact that for n>1, 1−(1−x)n is below its tangent nx at 0: