Contents / Information Theory / Entropy Rates and the AEP
Chapter 3
Entropy Rates and the AEP
Information per symbol for a process with memory, and the asymptotic equipartition property that makes long sequences predictable in bulk.
Introduction
Information per symbol for a process with memory, and the asymptotic equipartition property that makes long sequences predictable in bulk.
3.1Entropy Rate of a Stationary Process
For a single random variable, entropy is the uncertainty per draw. A process is different: its symbols are usually dependent, so the useful question is not how uncertain one symbol is but how much new uncertainty each additional symbol contributes. That long-run average per symbol is the entropy rate, and it, not the single-symbol entropy, is the number that governs the compressibility of real files — whose symbols are anything but independent.
Definition 3.1 (Entropy rate). For a discrete-time stochastic process define, when the limits exist,
The first is the per-symbol block rate, the second the conditional rate.
Definition 3.2 (Stationary process). A process is stationary if its finite-dimensional distributions are shift-invariant: for every and every ,
The two rates look different — one averages a whole block, the other looks one symbol ahead — but for a stationary process they exist and coincide. The proof is a good illustration of how the chain rule and "conditioning reduces entropy" combine.
Lemma 3.3 (The conditional entropies decrease). For a stationary process, is non-increasing in and therefore converges (it is bounded below by ).
Proof. Conditioning on more reduces entropy, so
since the left side conditions on one extra variable. Stationarity says the right side equals , because the block has the same joint law as . Hence the sequence is non-increasing, and being non-negative it converges.∎
Lemma 3.4 (Cesàro mean). If then .
Proof. Given choose with for . For ,
where is a fixed number. Taking makes the whole expression less than .∎
Theorem 3.5 (The two rates agree). For a stationary process both limits in Definition Entropy rate exist and
Proof. The conditional rate exists by Lemma The conditional entropies decrease. The chain rule writes the block entropy as a sum of exactly those conditional entropies:
The right side is the Cesàro mean of a convergent sequence, so by Lemma Cesàro mean it converges to the same limit . Hence exists and equals .∎
Corollary 3.7 (The rate is below the marginal entropy). For a stationary process, , with equality if and only if the process is i.i.d.
Proof. Each term by conditioning-reduces-entropy and stationarity; averaging preserves the bound. Equality for every requires independent of its past for every , which with stationarity is exactly independence with a common marginal.∎
Intuition. Memory is redundancy, and redundancy is compressibility. Written English has a per-letter marginal entropy of about bits, but its entropy rate — measured by how well people predict the next letter given the text so far — is closer to bits. The three-bit gap is grammar, spelling and meaning, and it is exactly what a good compressor harvests.
Example 3.8 (A memoryless source). An i.i.d. source has per-symbol entropy bits. Find its entropy rate.
Solution. Independence makes the chain rule collapse: for every , so and
giving bits/symbol. Note that the rate is attained at every block length, not merely in the limit — for an i.i.d. source there is nothing to be gained by coding long blocks other than amortising the of the source coding theorem. □□
3.2Entropy Rate of a Markov Chain
The most important computable case is a Markov chain, where the entire past is summarised by the current state.
Definition 3.9 (Stationary Markov chain). A process is a Markov chain if for all . It is time-invariant if that transition law does not depend on , and stationary if in addition the marginal law satisfies for all .
Theorem 3.10 (Entropy rate of a Markov chain). For a stationary Markov chain with stationary distribution and transition matrix ,
For a stationary Markov chain of order , .
Proof. By Theorem The two rates agree, . The Markov property makes the conditioning collapse: given , the variable is independent of , so , and stationarity makes this the same number for every , namely . The sequence is constant, so its limit is that constant. Expanding the definition of conditional entropy with gives the displayed formula. The order- case is identical with the state taken to be the last symbols.∎
Example 3.11 (A sticky binary chain). A binary chain stays in its current state with probability and flips with probability . Find the stationary distribution, the marginal entropy, and the entropy rate.
Solution. Symmetry gives , which we check: . ✓ So the marginal entropy is bit.
From either state the next symbol is a Bernoulli decision to flip, so for each , and
Sanity check: , as Corollary The rate is below the marginal entropy requires, and the gap of bits per symbol is precisely — the predictability that memory supplies. A file of a million such symbols compresses to about kbit, not Mbit. □□
Example 3.12 (An asymmetric two-state chain). A chain has , . Find and the entropy rate.
Solution. Stationarity requires (balance of flow across the cut), so , giving and hence .
From state the next symbol is Bernoulli, contributing ; from state it is Bernoulli, contributing . Weighting,
Sanity check: the marginal entropy is bits, and indeed . □□
Pitfall. The entropy rate is not the entropy of the stationary distribution. ignores the transition structure entirely and is only an upper bound. In the sticky chain above, while the rate is — a factor of two.
Remark. A hidden Markov process — a function of a Markov chain, observed through noise — need not be Markov of any finite order, and its entropy rate has no closed form. It can be sandwiched: , where is the initial hidden state, and both bounds converge to the rate. Establishing that sandwich is beyond this chapter.
3.3The AEP, Compression, and the Continuous Analogue
The entropy rate is not only an average; for well-behaved processes it is the value that essentially every long realisation exhibits. That is the content of the asymptotic equipartition property.
Write for the set of sequences whose per-symbol code length lies within of — the typical set. It is defined carefully, and its size pinned down, in Definition Typical set below; here we need only the name.
Theorem 3.13 (Asymptotic equipartition property, i.i.d. case). Let be i.i.d. with entropy on a finite alphabet. Then
and consequently for every : the typical set eventually carries essentially all of the probability.
Proof. Independence factors the joint mass function, so
an average of i.i.d. random variables with common mean and finite variance (the alphabet is finite). The weak law of large numbers gives convergence in probability to , which is the first claim, and membership of is precisely the event , so its probability tends to . The weak law itself is proved in the next section, and the counting consequences — that is about — in the section after that.∎
Intuition. Of the possible sequences, only about are ever seen, and they are all roughly equally likely. Compression is therefore just indexing: number the typical sequences and send the index, which needs bits. Everything else is handled by an escape code whose cost vanishes because its probability does.
Indexing the typical set is how the entropy rate becomes an achievable compression rate, and the last section of this chapter carries that construction out and measures its length. The matching claim that no scheme beats the rate — Shannon's source coding theorem, in both directions, with its Fano converse — is the subject of the next chapter, Source Coding and the Entropy Bound. Here we use only the achievability side, and only as arithmetic for sizing files.
Example 3.14 (Sizing a file from its rate). A source with entropy rate bits/symbol emits symbols. How large is the compressed file, and what would using the marginal entropy of bits/symbol have predicted?
Solution. The block entropy is about bits bytes kB, and no scheme does sustainably better — that is the converse half of the source coding theorem, proved in the next chapter.
Using the marginal entropy instead would predict bits kB. That estimate is an upper bound, not the truth: it ignores the memory, and the kB difference is exactly the redundancy a model of the dependence recovers. □□
Everything in this chapter has assumed a discrete alphabet. The continuous analogue is genuinely different, and the differences are worth stating because they are a standard source of error.
Definition 3.15 (Differential entropy). For a random variable with density on ,
where is the support of , whenever the integral exists. (The lower-case here is the traditional notation and unfortunately collides with the binary entropy function ; the argument tells them apart — a random variable means differential entropy, a number in means the binary entropy.)
Theorem 3.16 (Differential entropy of a uniform and a Gaussian). If is uniform on then . If is Gaussian with variance then .
Proof. Uniform: on , so .
Gaussian: with ,
whose expectation is . Dividing by converts nats to bits.∎
Pitfall. Differential entropy is not a limit of discrete entropies and it does not inherit their properties.
- It can be negative: the uniform on has bit.
- It is not invariant under relabelling: , whereas discrete entropy is unchanged by any injective map. Differential entropy therefore depends on the units in which is measured.
- It is not the number of bits needed to describe ; describing a real number exactly takes infinitely many bits. The correct statement is that an -bit uniform quantisation of has discrete entropy approximately .
Remark. What survives the passage to densities is precisely the relative quantities. Relative entropy is still non-negative, still infinite on support mismatch, and still invariant under a change of variables, because the Jacobian cancels between numerator and denominator. Mutual information inherits all of this: it is non-negative, invariant under smooth invertible relabelling of either variable, and satisfies the data processing inequality unchanged. This is the deeper reason to regard , rather than , as the fundamental object: is the special case that only exists when a canonical uniform reference measure does.
Summary. So far: for a stationary process the entropy rate exists, equals the limiting one-step conditional entropy, is at most the marginal entropy with equality only in the i.i.d. case, and equals for a stationary Markov chain. The AEP says that a long realisation exhibits that rate, and differential entropy is the continuous analogue that keeps the formula but loses the interpretation. The rest of the chapter makes the AEP quantitative: where it comes from, how large the typical set is, and what compressor it hands us.
3.4The Law of Large Numbers for Information
Entropy was introduced as the expected surprise of a single draw. To say anything about files we need a per-symbol quantity that survives dependence between symbols.
Recall the entropy rate of Definition Entropy rate, which for a stationary process also equals , the conditional entropy of the next symbol given the entire past. That is an average over the whole ensemble; what a compressor actually meets is one string, so we need a per-string quantity beside it.
For an i.i.d. source the chain rule gives immediately, so : the entropy rate is the ordinary single-symbol entropy. For a source with memory the two differ, and the difference is exactly the redundancy that a model of the memory can harvest.
Definition 3.17 (Sample information rate). For a string of positive probability, the sample information rate is
the number of bits per symbol an ideal code would spend on this particular string. The random variable is the empirical rate of the string actually produced.
The entropy rate is an expectation, ; the sample information rate is the random quantity being averaged. The AEP says that the random quantity concentrates on its mean — that essentially every long string costs the same number of bits per symbol.
Theorem 3.18 (Weak law of large numbers). If are i.i.d. with finite mean , then in probability: for every ,
Proof. We prove the case of finite variance , which is all we need here: a finite alphabet makes a bounded random variable. The sample mean has mean and, by independence, variance , so Chebyshev's inequality gives
(The general finite-mean case is Khinchin's theorem and requires a truncation argument, which we do not need.)∎
Theorem 3.19 (AEP, quantitative form). Let be i.i.d. on a finite alphabet, write , and let
be the varentropy of the source. Then for every and every ,
Letting recovers Theorem Asymptotic equipartition property, i.i.d. case, now with an explicit rate.
Proof. Independence factorises the joint mass function, , and the logarithm turns the product into a sum:
The summands are i.i.d. functions of i.i.d. variables, and are bounded because the alphabet is finite and every symbol that can actually be observed has . Their common mean is
and their common variance is , by the definition above. So is exactly the sample mean of Theorem Weak law of large numbers with and , and the Chebyshev step of that proof gives the displayed bound — at every , not merely in the limit.∎
That is the whole trick, and it is worth saying twice: the AEP is the weak law of large numbers applied to the random variable "surprise". The varentropy is the constant that says how long a block must be before the law bites. A nearly uniform source has small and concentrates almost at once; a source with one rare, very surprising symbol has large and needs long blocks before its typical set is worth anything. That is why the asymptotic statements of this chapter are careful to be asymptotic.
Remark (Beyond independence). For a general stationary ergodic process the same conclusion holds, in the stronger almost-sure form
This is the Shannon–McMillan–Breiman theorem. Its proof is genuinely harder — it rests on the Birkhoff ergodic theorem together with a martingale-convergence argument for the conditional densities — and is beyond the scope of this chapter. We use it only to state results in their natural generality; every proof given here is carried out in the i.i.d. case, where the weak law suffices.
Intuition. Toss a biased coin a million times. You cannot predict the sequence, but you can predict its cost: almost every outcome you will ever see takes about the same number of bits to write down, namely per toss.
Strings that are much cheaper (all heads) or much more expensive exist, but their total probability is negligible. Compression is the art of budgeting for the ordinary strings and merely coping with the rest.
Example 3.20 (Sample rate of a specific string). A memoryless binary source has and . Compute and the sample information rate of the particular string .
Solution. The entropy is
The string has eight 1s and two 0s, so
and its sample information rate is
Sanity check: the string has exactly the expected composition (80% ones), so its rate lands exactly on . A string with five 1s and five 0s would give bits/symbol, far above — atypical, and correspondingly improbable.□
Pitfall (The AEP is not "all sequences are equally likely"). The AEP says that the logarithm of the probability, divided by , concentrates. It does not say probabilities are equal: two typical strings of length may have probabilities differing by a factor of and still both be typical, because is small. "Equipartition" is a statement about bits per symbol, not about total probability.
3.5The Typical Set and How Big It Is
The AEP is a statement about a limit in probability. To use it we convert it into a statement about a set — the strings whose rate is close to .
Definition 3.21 (Typical set). For and , the typical set consists of the strings whose sample information rate is within of the entropy:
equivalently the strings with
The two displays say the same thing; the second is the form used in every proof, so it is worth memorising. Typicality is defined relative to a source: a string is not typical or atypical in itself, only with respect to a distribution.
Theorem 3.22 (Properties of the typical set). Let be i.i.d. with entropy . For every :
- Probability. for all sufficiently large .
- Upper bound on size. for every .
- Lower bound on size. for all sufficiently large .
Proof. (1) is a restatement of the AEP: convergence in probability of to means precisely that the probability of the event exceeds once is large enough.
(2) Every typical string has probability at least , and probabilities of disjoint outcomes cannot sum past one:
Rearranging gives the bound, and note that it holds for every , not only for large .
(3) Run the same computation from the other side. For large enough that (1) holds,
using the upper bound valid on the typical set. Rearranging gives (3).∎
Clauses (2) and (3) pin the size of the typical set between and : to first order in the exponent, . The whole space has strings, and with equality only for the uniform distribution. So unless the source is uniform, the typical set is an exponentially vanishing fraction of the space that nevertheless captures all but of the probability.
Intuition. Picture the space of all length- strings as a vast warehouse. The typical set is one small room inside it. Almost every string the source ever emits is found in that room, and the room holds about objects, so a shelf label of bits is enough to name any of them.
The rest of the warehouse is enormous but effectively empty: you may ignore it at the cost of an error probability you choose in advance.
Example 3.23 (The typical set of a biased coin). For the source , with and , estimate the size of the typical set and its share of the binary strings.
Solution. The entropy is
By clauses (2) and (3), the size lies between roughly and ; the natural estimate is .
The fraction of the space is therefore about
Sanity check by direct counting. Typical strings are those with about ones; the number with exactly ones is , the same order as once the neighbouring compositions (roughly to ones) admitted by the -window are added. The two computations agree, as they must: the AEP for a binary source is the law of large numbers for the number of ones.□
Theorem 3.25 (No smaller high-probability set exists). Fix and let be any sequence of sets with . Then for every and all sufficiently large ,
No high-probability set can be essentially smaller than the typical set: about strings are needed, whatever shape the set is given.
Proof. Write . Since and for any prescribed once is large, the union bound gives
Every string in has , so
Hence and
for large, because lets us choose with , making the last term vanish.∎
This theorem is the reason the typical set is the right object and not merely a convenient one. One might hope to beat it by taking the most probable strings instead, with ; the theorem says any such set has probability tending to zero.
Pitfall (The most probable string is usually atypical). For the single most probable string of length is , with probability . Its sample information rate is , nowhere near , so it is not typical for small . The typical set is not the set of likely strings; it is the set of strings of likely composition. High-probability sets are assembled from many mid-probability strings, not from the few champions.
3.6Compressing with the Typical Set
We can now build a compressor. It is crude — a lookup table of astronomical size — but it proves that the entropy rate is achievable, and every later algorithm is an attempt to obtain the same rate with feasible resources.
Method 3.26 (Typical-set block code). Fix and a block length . Split into the typical set and its complement, and encode a block as follows.
- If : emit the flag bit , followed by the index of in a fixed enumeration of , written in bits.
- Otherwise: emit the flag bit , followed by the index of in , written in bits.
The decoder reads the flag bit and looks the index up in the corresponding table, so the code is lossless — every string is recovered exactly.
The flag bit is what makes the two branches decodable, and it is the price of admitting that atypical strings exist. Note that this scheme never errs: appears in the length, not in a failure probability.
Theorem 3.27 (Expected length of the typical-set code). Let be the length in bits produced by the typical-set block code. For every there is an such that for all ,
Proof. Split the expectation over the two branches. On the typical set the length is at most (one flag bit and at most one bit lost to the ceiling); on the complement it is at most . Therefore
Bounding the first probability by and, for large , the second by ,
Given , choose and then ; for the right-hand side is at most .∎
Corollary 3.28 (Entropy is an achievable description length). For any source satisfying the AEP with entropy rate , and any , there exist lossless codes with expected description length at most bits per symbol for all sufficiently large block lengths.
The corollary is the achievability half of the source coding theorem, obtained before the theorem is even stated. What the next part adds is precision about what kind of code is allowed, and a matching converse.
Intuition. The compressor is a phone book. All the ordinary strings are listed in it, and to send one you send its page-and-line number. The occasional bizarre string is not in the book, so you prefix it with "not in the book" and spell it out in full.
Spelling out is expensive, but you do it so rarely that on average it costs nothing.
Example 3.29 (Rate of a typical-set code for a video frame). A residual video frame of pixels is modelled as an i.i.d. source over a -level alphabet with bits per pixel. Compare the raw size, the typical branch, and the average overhead of the atypical branch if .
Solution. There are pixels.
Raw. At bits per pixel: bits MB.
Typical branch. with negligible at this : bits kB — a ratio of .
Atypical branch. It costs bits but occurs with probability , contributing bits per pixel to the average — one percent of the -bit budget.
Average rate: bits per pixel.
Sanity check: the average exceeds by bits per pixel, consistent with the overhead term in the proof above with , namely — the right order. The typical-set bound is not a fiction; it is what the arithmetic actually gives.□
Remark (Why this code is never built). The table has about entries. For the frame above that is entries — more than the number of atoms in any number of universes. The typical-set code is an existence argument. The rest of this chapter is about obtaining the same rate with an algorithm that runs in linear time and constant memory; remarkably, this turns out to be possible.
- Using the single-symbol entropy for a source with memory. It overestimates the true cost; the entropy rate is the correct number and is strictly smaller unless the source is i.i.d.
- Assuming the rate always exists. Stationarity is what guarantees it. A non-stationary process can have oscillating forever.
- Confusing the entropy rate with the entropy of the stationary distribution. ignores the transitions and is only an upper bound.
- **Believing can increase.** For a stationary process it is non-increasing in — that is Lemma *The conditional entropies decrease*, and it is what makes the limit exist. (Both and are non-increasing, and the first is below the second.)
- Reading the AEP as "all long sequences are equally likely". It says the *log-probabilities per symbol* concentrate. Two typical sequences can still differ in probability by a factor of .
- Carrying discrete intuitions into differential entropy. can be negative, changes under scaling, and is not a description length.
- **Thinking every sequence has probability exactly . ** Only typical ones have probability close to that *on the exponential scale*, and even they vary by subexponential factors. Atypical strings can be far more or far less likely.
- Confusing the size of the typical set with the size of the support. The support is usually all of ; the typical set is the exponentially smaller subset of size about .
- Dropping the ergodicity or stationarity hypothesis. Without it the entropy rate may not exist, and the concentration in the AEP can fail outright.
- **Treating the AEP as exact at finite . ** It is asymptotic. For short blocks the atypical branch is not negligible and one needs explicit finite- bounds (Chebyshev, or a Chernoff bound).
- Confusing the AEP with the central limit theorem. Both concern , but the AEP is a law of large numbers (the mean converges); the CLT describes the -scale fluctuations around it, which govern finite-blocklength corrections.
- Assuming typicality is a property of a string. It is a property of a string *and* a distribution. The all-ones string is typical for and wildly atypical for a fair coin.