Probability and Information

Eleven modules, from counting and Bayes' theorem to entropy, coding, channel capacity, the central limit theorem and Markov chains. Drag the figures, run the simulations, watch a Huffman code being built, work through an example one step at a time, then check yourself with concept questions and practice problems.

Follows the chapter order of D. Applebaum, Probability and Information: An Integrated Approach, 2nd ed. (Cambridge University Press, 2008), and covers Chapters 2–10; Chapter 1 is the book's introduction and has no module. Chapter and exercise numbers refer to that book; the questions and examples here are written for this page. Logarithms are to base 2 throughout, so information is measured in bits.

InteractiveApplebaum, Ch. 2: Combinatorics

Counting selections

Before probabilities come counts. Choosing rr things from nn can be done in four ways, depending on whether order matters and whether repeats are allowed. Each gives a different formula, and the formulas are related by simple overcounting factors that you can see by listing every selection.

The idea

Multiplication principle. If a task is done in kk stages and stage ii can be done in mim_i ways whatever happened before, the whole task can be done in m1m2⋯mkm_1 m_2\cdots m_k ways.

Applied to choosing rr objects from nn distinct ones:

nr⏟ordered, repeatsn!(n−r)!⏟ordered, no repeats(nr)=n!r!(n−r)!⏟unordered, no repeats(n+r−1r)⏟unordered, repeats\underbrace{n^r}_{\text{ordered, repeats}} \qquad \underbrace{\frac{n!}{(n-r)!}}_{\text{ordered, no repeats}} \qquad \underbrace{\binom{n}{r}=\frac{n!}{r!\,(n-r)!}}_{\text{unordered, no repeats}} \qquad \underbrace{\binom{n+r-1}{r}}_{\text{unordered, repeats}}

The third comes from the second: every unordered selection of rr different objects can be put in order in r!r! ways, so the ordered count is r!r! times too big. The fourth is "stars and bars": a selection with repeats is a row of rr stars split into nn groups by n−1n-1 bars, and we choose which rr of the n+r−1n+r-1 positions are stars.

Multinomial coefficient. The number of ways to split NN distinct objects into labelled groups of sizes n1,…,nkn_1,\dots,n_k (with n1+⋯+nk=Nn_1+\dots+n_k=N) is (Nn1,…,nk)=N!n1!⋯nk!\displaystyle\binom{N}{n_1,\dots,n_k}=\frac{N!}{n_1!\cdots n_k!}. The binomial coefficient is the case k=2k=2.
Gamma function. Γ(x)=∫0∞tx−1e−tdt\Gamma(x)=\int_0^\infty t^{x-1}e^{-t}\,dt for x>0x>0. Integration by parts gives Γ(x+1)=xΓ(x)\Gamma(x+1)=x\,\Gamma(x), and Γ(1)=1\Gamma(1)=1, so Γ(n+1)=n!\Gamma(n+1)=n!: the gamma function extends the factorial to non-integers. A special value worth knowing is Γ(12)=π\Gamma(\tfrac12)=\sqrt\pi.

Explore

Kind of selection
Every selection, listed. Selections that use the same set of objects share a colour.

Worked example

A committee of 4 is chosen from 6 mathematicians and 5 physicists.

  1. How many committees are possible with no restriction?

    Order doesn't matter and nobody is chosen twice: (114)=11⋅10⋅9⋅84!=330\binom{11}{4}=\dfrac{11\cdot10\cdot9\cdot8}{4!}=330.

  2. How many have exactly two of each subject?

    Choose the mathematicians, then the physicists, and multiply: (62)(52)=15⋅10=150\binom62\binom52=15\cdot10=150.

  3. How many contain at least one physicist?

    Count the complement. The committees with no physicist are the (64)=15\binom64=15 all-mathematician ones, so the answer is 330−15=315330-15=315. (Adding up the cases "exactly 1, 2, 3, 4 physicists" gives 100+150+60+5=315100+150+60+5=315 too.)

  4. Now the committee also needs a chair and a secretary, two different members. How many ways are there to form the committee and fill both posts?

    Two ways to count, which must agree. Pick the committee (330 ways), then the chair (4) and the secretary (3): 330⋅12=3960330\cdot12=3960. Or pick the chair (11), the secretary (10), then the other two members from the remaining nine: 11⋅10⋅(92)=110⋅36=396011\cdot10\cdot\binom92=110\cdot36=3960.

Check your understanding

In how many ways can 3 identical balls be placed in 4 different boxes, if a box may hold any number of balls?

  1. 43=644^3=64That counts the balls as distinguishable: it records which ball went where. Here only how many balls each box gets matters.
  2. (43)=4\binom43=4That forbids two balls in the same box. Boxes may hold several balls.
  3. (63)=20\binom63=20
  4. 4⋅3⋅2=244\cdot3\cdot2=24That is an ordered selection without repeats.
A placement is an unordered selection of 3 boxes with repeats allowed. Stars and bars: 3 stars and 3 bars in a row, so (4+3−13)=(63)=20\binom{4+3-1}{3}=\binom63=20. Check it in the explorer with n=4, r=3n=4,\ r=3, "unordered, repeats".

In the explorer, set n=5, r=3n=5,\ r=3 and "ordered, no repeats". The 60 arrangements fall into colour blocks. What are the blocks?

  1. 6 blocks of 10The other way round. A block is one set of 3 objects; how many orders does such a set have?
  2. 10 blocks of 6
  3. 20 blocks of 3Three objects can be ordered in more than 3 ways.
Each of the (53)=10\binom53=10 three-element sets appears in all 3!=63!=6 of its orders. So 60=10⋅660=10\cdot6, which is exactly the identity n!(n−r)!=r!(nr)\frac{n!}{(n-r)!}=r!\binom nr.

Given Γ(x+1)=xΓ(x)\Gamma(x+1)=x\,\Gamma(x) and Γ(12)=π\Gamma(\frac12)=\sqrt\pi, what is Γ(52)\Gamma(\frac52)?

  1. 32π\frac32\sqrt\piYou used the recursion once. Γ(52)=32Γ(32)\Gamma(\frac52)=\frac32\Gamma(\frac32), and Γ(32)\Gamma(\frac32) still has to be reduced.
  2. 34π\frac34\sqrt\pi
  3. 158π\frac{15}{8}\sqrt\piThat is Γ(72)\Gamma(\frac72): one step too many.
  4. It is undefined: (32)!(\frac32)! makes no sense.The factorial is only defined for integers, but the gamma function is defined for every x>0x>0.
Γ(52)=32⋅Γ(32)=32⋅12⋅Γ(12)=34π≈1.329\Gamma(\frac52)=\frac32\cdot\Gamma(\frac32)=\frac32\cdot\frac12\cdot\Gamma(\frac12)=\frac34\sqrt\pi\approx1.329.

Practice

Rearranging a wordMultinomial coefficients

How many different strings can be made by rearranging all the letters of BANANAS? In how many of them are the three A's next to each other?

Hint

Swapping two equal letters gives the same string. For the second part, glue AAA into a single block.

Solution

There are 7 letters: A three times, N twice, B and S once. The count is 7!3!2!1!1!=504012=420\dfrac{7!}{3!\,2!\,1!\,1!}=\dfrac{5040}{12}=420. With AAA as one block there are 5 items, B, S, N, N and the block, so 5!2!=60\dfrac{5!}{2!}=60 strings.

A sum of squaresCounting one thing two ways

Show that ∑k=0n(nk)2=(2nn)\displaystyle\sum_{k=0}^{n}\binom nk^2=\binom{2n}{n} by counting something in two ways.

Hint

A group has nn women and nn men. Count the ways to choose nn people from it, sorted by how many women are chosen. Use (nk)=(nn−k)\binom nk=\binom n{n-k}.

Solution

Choosing nn of the 2n2n people can be done in (2nn)\binom{2n}n ways. Alternatively, choose kk women and n−kn-k men, in (nk)(nn−k)=(nk)2\binom nk\binom n{n-k}=\binom nk^2 ways, and add over k=0,…,nk=0,\dots,n. Both count the same selections.

More practice: Applebaum, Exercises 2.7, 2.11 and 2.16.

InteractiveApplebaum, Ch. 3: Sets and measures

Sets and measures

A probability is a special kind of measure: a rule that gives each set a size, so that the sizes of non-overlapping pieces add up. Everything else, from the complement rule to inclusion–exclusion, follows from that one property. Below, the measure of a region is its share of the rectangle's area.

The idea

Boolean algebra. A collection ℬ\mathcal B of subsets of a set SS that contains SS and is closed under finite unions, intersections and complements. Its laws include the distributive laws and de Morgan's laws, A∪B=A‾∩B‾\overline{A\cup B}=\bar A\cap\bar B and A∩B=A‾∪B‾\overline{A\cap B}=\bar A\cup\bar B.
Measure. A function m:ℬ→[0,∞)m:\mathcal B\to[0,\infty) that is additive on disjoint sets: if A∩B=⌀A\cap B=\varnothing then m(A∪B)=m(A)+m(B)m(A\cup B)=m(A)+m(B). Its total mass is m(S)m(S); a measure with total mass 1 is a probability measure.

Examples: the counting measure #A\#A on a finite set, length on unions of intervals, area in the plane. From additivity alone:

  • m(⌀)=0m(\varnothing)=0, and A⊆BA\subseteq B implies m(A)≤m(B)m(A)\le m(B).
  • m(A∖B)=m(A)−m(A∩B)m(A\smallsetminus B)=m(A)-m(A\cap B), since AA is the disjoint union of A∖BA\smallsetminus B and A∩BA\cap B.
  • If E1,…,EnE_1,\dots,E_n partition SS, then m(A)=∑im(A∩Ei)m(A)=\sum_i m(A\cap E_i).
Inclusion–exclusion. m(A∪B)=m(A)+m(B)−m(A∩B)m(A\cup B)=m(A)+m(B)-m(A\cap B), and for three sets
m(A∪B∪C)=m(A)+m(B)+m(C)−m(A∩B)−m(A∩C)−m(B∩C)+m(A∩B∩C).m(A\cup B\cup C)=m(A)+m(B)+m(C)-m(A\cap B)-m(A\cap C)-m(B\cap C)+m(A\cap B\cap C).

Explore

Drag the discs. The shaded region is the chosen event; its measure is its area as a fraction of the rectangle SS.
Event

Worked example

Use the counting measure on S={1,2,…,30}S=\{1,2,\dots,30\}. Let AA, BB, CC be the multiples of 2, 3 and 5 in SS.

  1. Find #A\#A, #B\#B, #C\#C.

    #A=15\#A=15, #B=10\#B=10, #C=6\#C=6.

  2. Find the sizes of all the intersections.

    A number is in A∩BA\cap B exactly when it is a multiple of 6, so #(A∩B)=5\#(A\cap B)=5. Similarly #(A∩C)=3\#(A\cap C)=3 (multiples of 10), #(B∩C)=2\#(B\cap C)=2 (multiples of 15) and #(A∩B∩C)=1\#(A\cap B\cap C)=1 (just 30).

  3. How many numbers in SS are divisible by at least one of 2, 3, 5?

    By inclusion–exclusion, 15+10+6−5−3−2+1=2215+10+6-5-3-2+1=22. Check: the numbers coprime to 30 are 1, 7, 11, 13, 17, 19, 23, 29, which is 8 numbers, and 30−8=2230-8=22.

  4. How many are divisible by exactly one of them?

    In the sum #A+#B+#C=31\#A+\#B+\#C=31, a number in exactly two sets is counted twice and the number in all three is counted three times. In the pairwise sum 5+3+2=105+3+2=10, a number in exactly two sets is counted once and the triple point three times. So

    #(exactly one)=31−2⋅10+3⋅1=14.\#(\text{exactly one}) = 31 - 2\cdot10 + 3\cdot1 = 14.

    Check directly: 15 multiples of 2, minus those also divisible by 3 or 5 (5+3−1=75+3-1=7) leaves 8; for 3 it is 10−(5+2−1)=410-(5+2-1)=4; for 5 it is 6−(3+2−1)=26-(3+2-1)=2. Total 8+4+2=148+4+2=14.

Check your understanding

PP is a probability measure with P(A)=0.5P(A)=0.5 and P(B)=0.4P(B)=0.4. Which values can P(A∪B)P(A\cup B) take?

  1. Only 0.90.9That assumes AA and BB don't overlap. Drag the discs on top of each other and watch m(A∪B)m(A\cup B).
  2. Any value in [0,0.9][0,0.9]A⊆A∪BA\subseteq A\cup B, so monotonicity forces P(A∪B)≥P(A)P(A\cup B)\ge P(A).
  3. Any value in [0.5,0.9][0.5,0.9]
  4. Any value in [0.5,1][0.5,1]Inclusion–exclusion gives P(A∪B)=0.9−P(A∩B)≤0.9P(A\cup B)=0.9-P(A\cap B)\le0.9.
P(A∪B)=0.9−P(A∩B)P(A\cup B)=0.9-P(A\cap B), and P(A∩B)P(A\cap B) can be anything from 0 (disjoint) up to 0.40.4 (when B⊆AB\subseteq A). So P(A∪B)P(A\cup B) ranges over [0.5,0.9][0.5,0.9].

Which condition guarantees m(A∖B)=m(A)−m(B)m(A\smallsetminus B)=m(A)-m(B)?

  1. None; it always holds.Drag BB so that it sticks out of AA, and compare m(A∖B)m(A\smallsetminus B) with m(A)−m(B)m(A)-m(B).
  2. B⊆AB\subseteq A
  3. AA and BB are disjoint.Then A∖B=AA\smallsetminus B=A, so m(A∖B)=m(A)m(A\smallsetminus B)=m(A), not m(A)−m(B)m(A)-m(B) (unless m(B)=0m(B)=0).
In general m(A∖B)=m(A)−m(A∩B)m(A\smallsetminus B)=m(A)-m(A\cap B). If B⊆AB\subseteq A then A∩B=BA\cap B=B, giving m(A)−m(B)m(A)-m(B).

On the subsets of a finite set, define m(A)=(#A)2m(A)=(\#A)^2. Is mm a measure?

  1. Yes: it is never negative.Non-negativity is only half of the definition. Check additivity on two disjoint one-point sets.
  2. Yes: it is built from the counting measure, which is a measure.A function of a measure need not be a measure. Test it on disjoint sets.
  3. No: additivity fails.
For disjoint one-point sets {a}\{a\}, {b}\{b\}: m({a,b})=4m(\{a,b\})=4 but m({a})+m({b})=2m(\{a\})+m(\{b\})=2. Any c⋅#Ac\cdot\#A with c≥0c\ge0 is a measure; squaring breaks additivity.

Practice

Proving inclusion–exclusionFrom additivity alone

Using only additivity on disjoint sets, prove m(A∪B)+m(A∩B)=m(A)+m(B)m(A\cup B)+m(A\cap B)=m(A)+m(B) for any A,B∈ℬA,B\in\mathcal B.

Hint

Split A∪BA\cup B into three disjoint pieces: A∖BA\smallsetminus B, A∩BA\cap B, B∖AB\smallsetminus A.

Solution

Write a=m(A∖B)a=m(A\smallsetminus B), c=m(A∩B)c=m(A\cap B), b=m(B∖A)b=m(B\smallsetminus A). Additivity gives m(A∪B)=a+b+cm(A\cup B)=a+b+c, m(A)=a+cm(A)=a+c and m(B)=b+cm(B)=b+c. So both sides equal a+b+2ca+b+2c.

A lower bound for an intersectionBonferroni's inequality

Show that P(A∩B)≥P(A)+P(B)−1P(A\cap B)\ge P(A)+P(B)-1 for any probability measure. A part goes through two checks, which it passes with probabilities 0.970.97 and 0.950.95. Nothing is known about how the checks are related. What can you say about the probability that it passes both?

Solution

From inclusion–exclusion, P(A∩B)=P(A)+P(B)−P(A∪B)≥P(A)+P(B)−1P(A\cap B)=P(A)+P(B)-P(A\cup B)\ge P(A)+P(B)-1, since P(A∪B)≤1P(A\cup B)\le1. For the checks, P(both)≥0.97+0.95−1=0.92P(\text{both})\ge0.97+0.95-1=0.92. The bound holds whatever the dependence between the checks, and it is attained when the two sets of failures are disjoint. If the checks were independent, the answer would be exactly 0.97⋅0.95=0.92150.97\cdot0.95=0.9215.

More practice: Applebaum, Exercises 3.6, 3.10 and 3.16.

InteractiveApplebaum, Ch. 4: Probability

Conditional probability and Bayes' theorem

A test that is right 99% of the time can still be wrong most of the time it says "positive". The resolution is the difference between P(positive|ill)P(\text{positive}\mid\text{ill}) and P(ill|positive)P(\text{ill}\mid\text{positive}), and Bayes' theorem is the rule for turning one into the other.

The idea

Conditional probability. If P(A)>0P(A)>0, the probability of BB given AA is P(B|A)=P(A∩B)P(A)P(B\mid A)=\dfrac{P(A\cap B)}{P(A)}. (The book writes PA(B)P_A(B).) For fixed AA, B↦P(B|A)B\mapsto P(B\mid A) is itself a probability measure.
Total probability and Bayes. If E1,…,EnE_1,\dots,E_n partition SS and each P(Ei)>0P(E_i)>0, then
P(A)=∑iP(A|Ei)P(Ei),P(Ek|A)=P(A|Ek)P(Ek)∑iP(A|Ei)P(Ei).P(A)=\sum_{i}P(A\mid E_i)\,P(E_i), \qquad P(E_k\mid A)=\frac{P(A\mid E_k)\,P(E_k)}{\sum_i P(A\mid E_i)\,P(E_i)}.
Independence. AA and BB are independent if P(A∩B)=P(A)P(B)P(A\cap B)=P(A)P(B), that is, learning AA does not change the probability of BB. Three events are independent if each pair is and also P(A∩B∩C)=P(A)P(B)P(C)P(A\cap B\cap C)=P(A)P(B)P(C); pairwise independence alone is not enough.

For a diagnostic test, E1=DE_1=D (ill) and E2=D‾E_2=\bar D. The sensitivity is P(+|D)P(+\mid D), the specificity is P(−|D‾)P(-\mid\bar D), and the prevalence P(D)P(D) is the prior. Bayes gives the posterior P(D|+)P(D\mid +).

Explore

ill, tests positive ill, tests negative healthy, tests positive healthy, tests negative · expected numbers in 1000 people, rounded

Worked example

30% of the email reaching an inbox is spam. A filter flags 95% of spam, and also flags 2% of genuine email.

  1. What fraction of all email gets flagged?

    By total probability, P(F)=0.95⋅0.3+0.02⋅0.7=0.285+0.014=0.299P(F)=0.95\cdot0.3+0.02\cdot0.7=0.285+0.014=0.299.

  2. A message is flagged. What is the probability it is spam?

    P(spam|F)=0.2850.299≈0.953.P(\text{spam}\mid F)=\frac{0.285}{0.299}\approx0.953.

    About 1 flagged message in 21 is genuine.

  3. A message is not flagged. What is the probability it is spam?

    P(spam|F‾)=0.05⋅0.31−0.299=0.0150.701≈0.021.P(\text{spam}\mid\bar F)=\frac{0.05\cdot0.3}{1-0.299}=\frac{0.015}{0.701}\approx0.021.
  4. Are "spam" and "flagged" independent? What would independence mean for the filter?

    No: P(spam|F)≈0.953≠0.3=P(spam)P(\text{spam}\mid F)\approx0.953\ne0.3=P(\text{spam}). Independence would mean that a flag carries no information about whether the message is spam, which happens exactly when the filter flags spam and genuine mail at the same rate. Try that in the explorer: set sensitivity =1−=1-specificity and the posterior equals the prior.

Check your understanding

A test has sensitivity and specificity both 0.99, and 1 person in 1000 has the disease. Roughly what is P(D|+)P(D\mid +)?

  1. 0.99That is P(+|D)P(+\mid D). The question asks for the reverse conditional probability.
  2. 0.5Count the positives in 1000 people: about 1 true positive and about 10 false ones.
  3. About 0.09
  4. 0.001That is the prior. A positive result should raise it.
P(D|+)=0.99⋅0.0010.99⋅0.001+0.01⋅0.999=0.000990.01098≈0.090P(D\mid+)=\dfrac{0.99\cdot0.001}{0.99\cdot0.001+0.01\cdot0.999}=\dfrac{0.00099}{0.01098}\approx0.090. The false positives come from the 999 healthy people, so they outnumber the true positives about ten to one.

AA and BB are disjoint events, each with positive probability. Can they be independent?

  1. Yes: they have nothing to do with each other.Disjoint does not mean unrelated: if AA happens, you know for certain that BB did not.
  2. No
  3. Only if P(A)+P(B)=1P(A)+P(B)=1.Check the definition: P(A∩B)P(A\cap B) would have to equal P(A)P(B)P(A)P(B).
P(A∩B)=P(⌀)=0P(A\cap B)=P(\varnothing)=0, but P(A)P(B)>0P(A)P(B)>0. Disjoint events with positive probability are strongly dependent.

A patient tests positive, then takes a second test of the same kind, whose result given the disease status is independent of the first, and is positive again. How should the probability be updated?

  1. Use the posterior after the first test as the prior and apply Bayes again.
  2. Multiply the first posterior by the sensitivity.That gives P(D∩+2|+1)P(D\cap+_2\mid+_1), not P(D|+1,+2)P(D\mid+_1,+_2). You still have to divide by the probability of the second positive.
  3. The second test adds nothing new.It is independent given the disease status, so it is fresh evidence. Use the retest button in the explorer.
Because the tests are conditionally independent given DD, P(D|+1,+2)P(D\mid+_1,+_2) is Bayes' formula with prior P(D|+1)P(D\mid+_1). In the 1-in-1000 example the posterior goes from about 0.09 to about 0.91.

Practice

Three cardsConditioning on what you see

One card is red on both sides, one is white on both sides, and one is red on one side and white on the other. A card is drawn at random and placed on the table with a random side up. The visible side is red. What is the probability that the other side is red too?

Hint

Condition on the face you see, not on the card. There are six equally likely faces.

Solution

Of the six equally likely faces, three are red. Two of those belong to the red–red card. So P(other side red|red seen)=2/3P(\text{other side red}\mid\text{red seen})=2/3, not 1/21/2. With Bayes: P(RR|red)=1⋅131⋅13+12⋅13+0=23P(RR\mid\text{red})=\dfrac{1\cdot\frac13}{1\cdot\frac13+\frac12\cdot\frac13+0}=\frac23.

Pairwise is not enoughIndependence of three events

Toss two fair coins. Let AA = "first coin heads", BB = "second coin heads", CC = "the coins show the same face". Show that each pair of these events is independent, but the three are not.

Solution

Each event has probability 12\frac12. A∩B={HH}A\cap B=\{HH\}, A∩C={HH}A\cap C=\{HH\}, B∩C={HH}B\cap C=\{HH\}, each of probability 14=12⋅12\frac14=\frac12\cdot\frac12. But A∩B∩C={HH}A\cap B\cap C=\{HH\} has probability 14≠18\frac14\ne\frac18. Knowing AA and BB together determines CC, even though each alone tells you nothing about it.

More practice: Applebaum, Exercises 4.14, 4.20 and 4.29.

SimulationApplebaum, Ch. 5: Discrete random variables

Discrete random variables

A random variable's law says how likely each value is; its mean and variance summarise where the values sit and how far they spread. Draw samples below and watch the histogram settle onto the law and the running average settle onto the mean.

The idea

Random variable. A function XX from the sample space to ℝ\R. For discrete XX, its law is p(x)=P(X=x)p(x)=P(X=x) and its cumulative distribution is F(x)=P(X≤x)F(x)=P(X\le x).
Mean and variance. E(X)=∑xxp(x)E(X)=\sum_x x\,p(x) and Var(X)=E((X−μ)2)=E(X2)−E(X)2\mathrm{Var}(X)=E\big((X-\mu)^2\big)=E(X^2)-E(X)^2. Expectation is linear, Var(aX+b)=a2Var(X)\mathrm{Var}(aX+b)=a^2\mathrm{Var}(X), and for independent X,YX,Y, Var(X+Y)=Var(X)+Var(Y)\mathrm{Var}(X+Y)=\mathrm{Var}(X)+\mathrm{Var}(Y).

Three laws that come up again and again:

  • Binomial b(n,p)b(n,p): the number of successes in nn independent trials, p(k)=(nk)pk(1−p)n−kp(k)=\binom nk p^k(1-p)^{n-k}; mean npnp, variance np(1−p)np(1-p).
  • Poisson π(λ)\pi(\lambda): p(k)=e−λλk/k!p(k)=e^{-\lambda}\lambda^k/k! for k=0,1,2,…k=0,1,2,\dots; mean and variance both λ\lambda. It is the limit of b(n,λ/n)b(n,\lambda/n) as n→∞n\to\infty: many trials, each rarely a success.
  • Geometric: the number of the trial on which the first success happens, p(r)=p(1−p)r−1p(r)=p(1-p)^{r-1} for r=1,2,…r=1,2,\dots; mean 1/p1/p, variance (1−p)/p2(1-p)/p^2.
Averages settle down. If X1,X2,…X_1,X_2,\dots are i.i.d. with mean μ\mu and variance σ2\sigma^2, the sample mean X‾n\bar X_n has mean μ\mu and variance σ2/n\sigma^2/n. So its typical distance from μ\mu shrinks like 1/n1/\sqrt n. (The law of large numbers itself is proved in Chapter 8.)

Explore

Law
the law p(k)p(k) relative frequency in your samples Poisson overlay
running mean X‾n\bar X_n E(X)E(X) and the band E(X)±σ/nE(X)\pm\sigma/\sqrt n

Worked example

A batch contains 200 chips, each defective with probability 0.01 independently of the others. Let XX be the number of defective chips.

  1. What is the law of XX? Find P(X=0)P(X=0).

    X∼b(200,0.01)X\sim b(200,0.01), so P(X=0)=0.99200≈0.1340P(X=0)=0.99^{200}\approx0.1340.

  2. Approximate the same probability with a Poisson law. Which λ\lambda?

    Match the means: λ=np=2\lambda=np=2. Then P(X=0)≈e−2≈0.1353P(X=0)\approx e^{-2}\approx0.1353, within about 1% of the exact value.

  3. Estimate P(X≥3)P(X\ge3) both ways.

    Use the complement. Exactly: 1−(0.1340+0.2707+0.2720)≈0.32331-(0.1340+0.2707+0.2720)\approx0.3233. Poisson: 1−e−2(1+2+2)=1−5e−2≈0.32331-e^{-2}(1+2+2)=1-5e^{-2}\approx0.3233. They agree to four decimal places.

  4. Compare the variances. Why is the Poisson variance a little larger?

    The binomial variance is np(1−p)=1.98np(1-p)=1.98; the Poisson variance is λ=2\lambda=2. The factor 1−p1-p is the only difference, and it tends to 1 as p→0p\to0 with npnp fixed. That is the regime in which the Poisson approximation is good.

Check your understanding

X∼b(10,0.3)X\sim b(10,0.3) and Y∼b(10,0.3)Y\sim b(10,0.3) are independent. What is the law of X+YX+Y?

  1. b(20,0.3)b(20,0.3)
  2. b(10,0.6)b(10,0.6)Adding the two counts adds the numbers of trials, not the success probabilities. X+YX+Y can be as large as 20.
  3. It is not binomial.Think of XX and YY as counting successes in two separate runs of independent trials.
X+YX+Y counts successes in 20 independent trials, each with success probability 0.3. Check: the mean is 3+3=6=20⋅0.33+3=6=20\cdot0.3 and the variance is 2.1+2.1=4.2=20⋅0.3⋅0.72.1+2.1=4.2=20\cdot0.3\cdot0.7.

In the simulator, the running mean wanders around E(X)E(X). If you quadruple the number of draws, by what factor does its typical distance from E(X)E(X) shrink?

  1. 4That would be true of the variance of X‾n\bar X_n, not its standard deviation.
  2. 2
  3. It doesn't shrink; each draw is as random as the last.Each draw is, but the average of many draws is much less variable.
Var(X‾n)=σ2/n\mathrm{Var}(\bar X_n)=\sigma^2/n, so the standard deviation is σ/n\sigma/\sqrt n. Four times as many draws halves it. That is the band drawn around E(X)E(X) in the right-hand plot.

XX is uniform on {−1,0,1}\{-1,0,1\} and Y=X2Y=X^2. Which is true?

  1. They are independent, because they are uncorrelated.Uncorrelated only says E(XY)=E(X)E(Y)E(XY)=E(X)E(Y). Compare P(Y=0|X=0)P(Y=0\mid X=0) with P(Y=0)P(Y=0).
  2. They are uncorrelated but not independent.
  3. They are correlated, since YY is a function of XX.Compute Cov(X,Y)=E(X3)−E(X)E(X2)\mathrm{Cov}(X,Y)=E(X^3)-E(X)E(X^2).
E(XY)=E(X3)=0=E(X)E(Y)E(XY)=E(X^3)=0=E(X)E(Y), so the covariance is 0. But P(Y=0|X=0)=1≠13=P(Y=0)P(Y=0\mid X=0)=1\ne\frac13=P(Y=0). Correlation only detects linear dependence.

Practice

Mean of the geometric lawDifferentiating a series

Show that if p(r)=p(1−p)r−1p(r)=p(1-p)^{r-1} for r≥1r\ge1, then E(X)=1/pE(X)=1/p.

Hint

Differentiate ∑r≥0xr=11−x\sum_{r\ge0}x^r=\frac1{1-x} for |x|<1|x|<1.

Solution

Differentiating gives ∑r≥1rxr−1=1(1−x)2\sum_{r\ge1}r x^{r-1}=\frac1{(1-x)^2}. With x=1−px=1-p, E(X)=p∑r≥1r(1−p)r−1=p⋅1p2=1pE(X)=p\sum_{r\ge1}r(1-p)^{r-1}=p\cdot\frac1{p^2}=\frac1p. On average a fair die takes 6 rolls to show its first six.

Thinning a Poisson countTotal probability with random variables

The number of emails arriving in an hour is N∼π(λ)N\sim\pi(\lambda). Each email, independently, is spam with probability ss. Show that the number of spam emails KK is Poisson with mean λs\lambda s.

Hint

Given N=nN=n, K∼b(n,s)K\sim b(n,s). Sum over n≥kn\ge k.

Solution
P(K=k)=∑n≥ke−λλnn!(nk)sk(1−s)n−k=e−λ(λs)kk!∑m≥0(λ(1−s))mm!=e−λs(λs)kk!,P(K=k)=\sum_{n\ge k}e^{-\lambda}\frac{\lambda^n}{n!}\binom nk s^k(1-s)^{n-k}=e^{-\lambda}\frac{(\lambda s)^k}{k!}\sum_{m\ge0}\frac{(\lambda(1-s))^m}{m!}=e^{-\lambda s}\frac{(\lambda s)^k}{k!},

where m=n−km=n-k. So K∼π(λs)K\sim\pi(\lambda s).

More practice: Applebaum, Exercises 5.22, 5.23 and 5.36.

InteractiveApplebaum, Ch. 6: Information and entropy

Information and entropy

A rare event is more informative than a common one. Entropy is the average information in the outcome of a random variable: how many yes/no questions, on average, it takes to pin down the outcome. Drag the bars below and find the shapes with the most and the least entropy.

The idea

Information. The information in an event of probability pp is I=−log⁡pI=-\log p bits. Two independent events carry the sum of their informations, because probabilities multiply and logarithms turn products into sums.
Entropy. For XX with law p1,…,pnp_1,\dots,p_n,
H(X)=E(I(X))=−∑j=1npjlog⁡pj,with 0log⁡0=0.H(X)=E\big(I(X)\big)=-\sum_{j=1}^n p_j\log p_j, \qquad\text{with } 0\log 0=0.

It depends only on the probabilities, not on the values XX takes. For a Bernoulli variable, Hb(p)=−plog⁡p−(1−p)log⁡(1−p)H_b(p)=-p\log p-(1-p)\log(1-p), which is 1 bit at p=12p=\frac12.

Bounds. 0≤H(X)≤log⁡n0\le H(X)\le\log n. The lower bound holds exactly when one outcome is certain, the upper exactly when XX is uniform.
Maximum entropy principle. Among all laws on values x1,…,xnx_1,\dots,x_n with a given mean, the one of largest entropy is the Gibbs law
pj=e−βxjZ(β),Z(β)=∑je−βxj,p_j=\frac{e^{-\beta x_j}}{Z(\beta)}, \qquad Z(\beta)=\sum_j e^{-\beta x_j},

with β\beta chosen to give the right mean. It is the "least committal" law consistent with what you know. In statistical mechanics the xjx_j are energies and this is the Boltzmann distribution.

Explore

Drag the bars (outcomes j=1,…,6j=1,\dots,6) up and down; the heights are rescaled to sum to 1. Above each bar is the information −log⁡pj-\log p_j of that outcome, in bits. The dashed outline is the maximum-entropy law with the same mean as yours.

Worked example

Three fair coins are tossed. Let XX be the number of heads.

  1. Write down the law of XX.

    P(X=0)=P(X=3)=18P(X=0)=P(X=3)=\frac18 and P(X=1)=P(X=2)=38P(X=1)=P(X=2)=\frac38.

  2. How much information is there in learning X=0X=0? In learning X=1X=1?

    −log⁡18=3-\log\frac18=3 bits, and −log⁡38=log⁡83≈1.415-\log\frac38=\log\frac83\approx1.415 bits.

  3. Compute H(X)H(X).

    H(X)=2⋅18⋅3+2⋅38⋅1.415≈0.75+1.061=1.811 bits.H(X)=2\cdot\tfrac18\cdot3+2\cdot\tfrac38\cdot1.415\approx0.75+1.061=1.811\ \text{bits}.
  4. The full outcome (e.g. HTH) has 3 bits of entropy. Where did the other 1.19 bits go?

    The full outcome is uniform on 8 sequences, so it has log⁡8=3\log8=3 bits. XX is a function of it and forgets the order of the heads, which is why H(X)<3H(X)<3. In general H(f(Y))≤H(Y)H(f(Y))\le H(Y): processing can only lose information. The missing 3−1.811=1.1893-1.811=1.189 bits is the average information in "which order", given the count.

Check your understanding

Which law on four outcomes has more entropy: (0.5,0.5,0,0)(0.5,0.5,0,0) or (0.4,0.2,0.2,0.2)(0.4,0.2,0.2,0.2)?

  1. The first, because it is uniform.It is uniform only on two of the four outcomes, which gives log⁡2=1\log2=1 bit.
  2. The second
  3. They are equal.Compute both: one is exactly 1 bit.
H(0.5,0.5,0,0)=1H(0.5,0.5,0,0)=1 bit, while H(0.4,0.2,0.2,0.2)=0.4log⁡2.5+0.6log⁡5≈1.922H(0.4,0.2,0.2,0.2)=0.4\log2.5+0.6\log5\approx1.922 bits. Spreading probability over more outcomes matters more than being exactly uniform.

XX takes values 1,…,61,\dots,6. Let Y=10X+7Y=10X+7. How does H(Y)H(Y) compare with H(X)H(X)?

  1. H(Y)=H(X)H(Y)=H(X)
  2. H(Y)=10H(X)H(Y)=10\,H(X)That is how the variance would scale (by 10210^2, in fact). Entropy only sees the probabilities.
  3. H(Y)>H(X)H(Y)>H(X), since YY is more spread out.Entropy does not measure spread of values; relabelling the outcomes changes nothing.
x↦10x+7x\mapsto10x+7 is one-to-one, so YY has the same list of probabilities as XX and the same entropy. Entropy measures uncertainty about which outcome occurs, not how far apart the outcomes are.

Among all laws on {1,…,6}\{1,\dots,6\} with mean 3.5, which has the largest entropy?

  1. The uniform law
  2. p3=p4=12p_3=p_4=\frac12It has mean 3.5 but only 1 bit of entropy. Try it in the explorer.
  3. A Gibbs law with β>0\beta>0With β>0\beta>0 the weights e−βje^{-\beta j} favour small values, so the mean is below 3.5.
The uniform law has the largest entropy of all, log⁡6≈2.585\log6\approx2.585 bits, and its mean is 3.5. It is the Gibbs law with β=0\beta=0. Press "Uniform", then "Replace with the max-entropy law": nothing changes.

Practice

The Bernoulli entropyA calculus check

Show that Hb(p)H_b(p) has its maximum at p=12p=\frac12 and is symmetric about it. Compute Hb(0.1)H_b(0.1).

Solution

Hb(p)=Hb(1−p)H_b(p)=H_b(1-p) by its formula. In natural logs, ddp(−pln⁡p−(1−p)ln⁡(1−p))=ln⁡1−pp\frac{d}{dp}\big(-p\ln p-(1-p)\ln(1-p)\big)=\ln\frac{1-p}{p}, which is positive for p<12p<\frac12, zero at 12\frac12 and negative after. So the maximum is Hb(12)=1H_b(\frac12)=1 bit. Hb(0.1)=0.1log⁡10+0.9log⁡109≈0.332+0.137=0.469H_b(0.1)=0.1\log10+0.9\log\frac{10}9\approx0.332+0.137=0.469 bits.

Why uniform is the maximumThe Gibbs inequality

Using ln⁡x≤x−1\ln x\le x-1 (equality only at x=1x=1), show that H(X)≤log⁡nH(X)\le\log n, with equality only for the uniform law.

Hint

Look at H(X)−log⁡n=∑jpjlog⁡1npjH(X)-\log n=\sum_j p_j\log\frac{1}{np_j}, summing over the jj with pj>0p_j>0.

Solution

In natural logs, ∑jpjln⁡1npj≤∑jpj(1npj−1)=∑pj>01n−1≤0\sum_j p_j\ln\frac1{np_j}\le\sum_j p_j\big(\frac1{np_j}-1\big)=\sum_{p_j>0}\frac1n-1\le0. Equality needs npj=1np_j=1 for every jj with pj>0p_j>0, and needs every jj to have pj>0p_j>0; that is the uniform law. Dividing by ln⁡2\ln2 converts to bits.

More practice: Applebaum, Exercises 6.5, 6.6, 6.13 and 6.16.

InteractiveApplebaum, Ch. 6: Information and entropy (§6.3)

Joint entropy and mutual information

How much does knowing XX tell you about YY? Mutual information answers in bits: it is the drop in uncertainty about YY once XX is known. Reshape a joint law by dragging the dividers of the mosaic below and watch the entropies add up.

The idea

Joint and conditional entropy. For a pair (X,Y)(X,Y) with joint law pjk=P(X=xj,Y=yk)p_{jk}=P(X=x_j,Y=y_k),
H(X,Y)=−∑j,kpjklog⁡pjk,H(Y|X)=∑jP(X=xj)H(Y|X=xj).H(X,Y)=-\sum_{j,k}p_{jk}\log p_{jk}, \qquad H(Y\mid X)=\sum_j P(X=x_j)\,H(Y\mid X=x_j).

H(Y|X=xj)H(Y\mid X=x_j) is the entropy of the conditional law of YY given X=xjX=x_j, and H(Y|X)H(Y\mid X) is its average over xjx_j. (The book writes HX(Y)H_X(Y).)

Chain rule. H(X,Y)=H(X)+H(Y|X)H(X,Y)=H(X)+H(Y\mid X): learning the pair is learning XX, then learning YY given XX.
Mutual information.
I(X;Y)=H(Y)−H(Y|X)=H(X)+H(Y)−H(X,Y)=∑j,kpjklog⁡pjkP(X=xj)P(Y=yk).I(X;Y)=H(Y)-H(Y\mid X)=H(X)+H(Y)-H(X,Y)=\sum_{j,k}p_{jk}\log\frac{p_{jk}}{P(X=x_j)P(Y=y_k)}.
Properties. I(X;Y)=I(Y;X)≥0I(X;Y)=I(Y;X)\ge0, with equality exactly when XX and YY are independent. Equivalently H(Y|X)≤H(Y)H(Y\mid X)\le H(Y): on average, conditioning cannot increase uncertainty.

Explore

Start from:
Each rectangle's area is pjkp_{jk}. Drag the vertical divider to set P(X=0)P(X=0), and each horizontal divider to set P(Y=0|X=x)P(Y=0\mid X=x).
H(X|Y)H(X\mid Y) I(X;Y)I(X;Y) H(Y|X)H(Y\mid X), in bits

Worked example

XX and YY take values 0 and 1 with joint law p00=12p_{00}=\frac12, p01=14p_{01}=\frac14, p10=0p_{10}=0, p11=14p_{11}=\frac14.

  1. Find the marginal laws and their entropies.

    P(X=0)=34P(X=0)=\frac34, P(X=1)=14P(X=1)=\frac14, so H(X)=Hb(14)≈0.811H(X)=H_b(\frac14)\approx0.811. P(Y=0)=P(Y=1)=12P(Y=0)=P(Y=1)=\frac12, so H(Y)=1H(Y)=1.

  2. Find H(X,Y)H(X,Y).

    H(X,Y)=12log⁡2+14log⁡4+14log⁡4=0.5+0.5+0.5=1.5H(X,Y)=\frac12\log2+\frac14\log4+\frac14\log4=0.5+0.5+0.5=1.5 bits.

  3. Compute H(Y|X)H(Y\mid X) from its definition, and check the chain rule.

    Given X=0X=0, YY is 0 or 1 with probabilities 23,13\frac23,\frac13, so H(Y|X=0)=Hb(13)≈0.918H(Y\mid X=0)=H_b(\frac13)\approx0.918. Given X=1X=1, Y=1Y=1 for certain, so H(Y|X=1)=0H(Y\mid X=1)=0. Then H(Y|X)=34⋅0.918≈0.689H(Y\mid X)=\frac34\cdot0.918\approx0.689, and indeed H(X)+H(Y|X)≈0.811+0.689=1.5H(X)+H(Y\mid X)\approx0.811+0.689=1.5.

  4. Find I(X;Y)I(X;Y) two ways.

    H(Y)−H(Y|X)≈1−0.689=0.311H(Y)-H(Y\mid X)\approx1-0.689=0.311, and H(X)+H(Y)−H(X,Y)≈0.811+1−1.5=0.311H(X)+H(Y)-H(X,Y)\approx0.811+1-1.5=0.311 bits. Set the mosaic to these numbers (P(X=0)=0.75P(X=0)=0.75, P(Y=0|X=0)=23P(Y=0\mid X=0)=\frac23, P(Y=0|X=1)=0P(Y=0\mid X=1)=0) to check.

Check your understanding

I(X;Y)=0I(X;Y)=0. What can you conclude?

  1. XX and YY are independent.
  2. YY is a function of XX.Then H(Y|X)=0H(Y\mid X)=0 and I(X;Y)=H(Y)I(X;Y)=H(Y), the largest it can be.
  3. One of them is constant.That is enough for I=0I=0 but not necessary. In the mosaic, line the two horizontal dividers up.
I(X;Y)=∑pjklog⁡pjkpjqkI(X;Y)=\sum p_{jk}\log\frac{p_{jk}}{p_jq_k} is zero exactly when pjk=pjqkp_{jk}=p_jq_k for every j,kj,k. In the mosaic, that means the two horizontal dividers are at the same height: the conditional law of YY doesn't depend on XX.

XX is a fair bit and Y=XY=X. What is I(X;Y)I(X;Y)?

  1. 0YY tells you XX exactly. That is the opposite of independence.
  2. 1 bit
  3. 2 bitsThat is H(X)+H(Y)H(X)+H(Y). But H(X,Y)=1H(X,Y)=1, not 0, so subtract it.
H(Y|X)=0H(Y\mid X)=0, so I=H(Y)=1I=H(Y)=1 bit. A variable shares all of its information with itself: I(X;X)=H(X)I(X;X)=H(X).

Which of these always holds?

  1. H(Y|X)≤H(Y)H(Y\mid X)\le H(Y)
  2. H(Y|X=x)≤H(Y)H(Y\mid X=x)\le H(Y) for every value xxTry "Y depends on X only sometimes": a rare value of XX after which YY is a fair coin.
  3. H(X,Y)≥H(X)+H(Y)H(X,Y)\ge H(X)+H(Y)The inequality goes the other way: H(X,Y)=H(X)+H(Y)−I(X;Y)H(X,Y)=H(X)+H(Y)-I(X;Y).
Only the average over xx is guaranteed to drop. If X=0X=0 with probability 0.9 and then Y=0Y=0, but X=1X=1 makes YY a fair coin, then H(Y)=Hb(0.05)≈0.286H(Y)=H_b(0.05)\approx0.286 while H(Y|X=1)=1H(Y\mid X=1)=1. Learning a particular, surprising value can make you less sure.

Practice

Two formulas for IExpanding the logarithm

Show that ∑j,kpjklog⁡pjkpjqk=H(X)+H(Y)−H(X,Y)\displaystyle\sum_{j,k}p_{jk}\log\frac{p_{jk}}{p_jq_k}=H(X)+H(Y)-H(X,Y), where pjp_j, qkq_k are the marginals.

Solution

Split the logarithm: ∑pjklog⁡pjk−∑pjklog⁡pj−∑pjklog⁡qk\sum p_{jk}\log p_{jk}-\sum p_{jk}\log p_j-\sum p_{jk}\log q_k. The first sum is −H(X,Y)-H(X,Y). In the second, summing over kk first gives ∑jpjlog⁡pj=−H(X)\sum_j p_j\log p_j=-H(X); similarly the third is −H(Y)-H(Y). So the total is −H(X,Y)+H(X)+H(Y)-H(X,Y)+H(X)+H(Y).

The last bitA function of a random variable

XX is uniform on {0,1,2,3}\{0,1,2,3\} and Y=Xmod2Y=X\bmod2. Find H(X)H(X), H(Y)H(Y), H(Y|X)H(Y\mid X), H(X|Y)H(X\mid Y) and I(X;Y)I(X;Y).

Solution

H(X)=2H(X)=2, H(Y)=1H(Y)=1. YY is determined by XX, so H(Y|X)=0H(Y\mid X)=0. Given YY, XX is uniform on two values, so H(X|Y)=1H(X\mid Y)=1. Then I(X;Y)=H(Y)−H(Y|X)=1I(X;Y)=H(Y)-H(Y\mid X)=1 bit, and the chain rule checks: H(X,Y)=H(X)=2=H(Y)+H(X|Y)H(X,Y)=H(X)=2=H(Y)+H(X\mid Y).

More practice: Applebaum, Exercises 6.8 and 6.10.

InteractiveApplebaum, Ch. 7: Communication (§§7.1–7.2, 7.5)

Channels and capacity

A noisy channel garbles some of what is sent. The mutual information between input and output measures how much gets through, and the sender can tune it by choosing how often to send each symbol. The best achievable value is the channel's capacity, and Shannon's theorem says it is a hard speed limit for reliable communication.

The idea

Channel. A source sends a symbol XX; the receiver gets YY. The channel is described by the conditional probabilities P(Y=y|X=x)P(Y=y\mid X=x), which are fixed. The sender chooses the input law P(X=x)P(X=x).
Capacity. C=max⁡I(X;Y)C=\max I(X;Y), the maximum over all input laws.

In the binary symmetric channel each bit is flipped with probability ε\varepsilon, independently. If P(X=1)=pP(X=1)=p, then P(Y=1)=p(1−ε)+(1−p)εP(Y=1)=p(1-\varepsilon)+(1-p)\varepsilon, and H(Y|X)=Hb(ε)H(Y\mid X)=H_b(\varepsilon) whatever was sent, so

I(X;Y)=Hb(p(1−ε)+(1−p)ε)−Hb(ε),C=1−Hb(ε),I(X;Y)=H_b\big(p(1-\varepsilon)+(1-p)\varepsilon\big)-H_b(\varepsilon), \qquad C=1-H_b(\varepsilon),

with the maximum at p=12p=\frac12, which makes YY uniform.

Shannon's coding theorem. Send blocks of nn bits through the channel, using 2nR2^{nR} of the possible blocks as codewords (a rate of RR message bits per channel use). If R<CR<C, then for large nn there are codes whose probability of a decoding error is as small as you like. Above capacity this is impossible.

Explore

Right-hand plot
The channel. Line widths show the joint probabilities P(X=x,Y=y)P(X=x,Y=y).

Worked example

In a "Z-channel", a 0 is always received correctly, but a 1 arrives as 0 with probability 12\frac12. Find its capacity and the input law that achieves it.

  1. With P(X=1)=pP(X=1)=p, find the law of YY.

    Y=1Y=1 only if a 1 was sent and survived: P(Y=1)=p2P(Y=1)=\frac p2.

  2. Find H(Y|X)H(Y\mid X).

    Given X=0X=0, YY is certain: entropy 0. Given X=1X=1, YY is a fair coin: entropy 1. So H(Y|X)=(1−p)⋅0+p⋅1=pH(Y\mid X)=(1-p)\cdot0+p\cdot1=p.

  3. Write I(X;Y)I(X;Y) as a function of pp and maximise it.

    I(p)=Hb(p2)−pI(p)=H_b(\frac p2)-p. Using ddqHb(q)=log⁡1−qq\frac{d}{dq}H_b(q)=\log\frac{1-q}{q},

    I′(p)=12log⁡1−p/2p/2−1=0⟺2−pp=4⟺p=25.I'(p)=\tfrac12\log\frac{1-p/2}{p/2}-1=0 \iff \frac{2-p}{p}=4 \iff p=\tfrac25.
  4. What is the capacity? What is surprising about the optimal input?

    C=Hb(0.2)−0.4≈0.722−0.4=0.322C=H_b(0.2)-0.4\approx0.722-0.4=0.322 bits, which equals log⁡54\log\frac54. The best input sends 1 only 40% of the time: since 1s are the unreliable symbol, it pays to use them less. For the symmetric channel the optimum is always 12\frac12, but in general the capacity-achieving input need not be uniform.

Check your understanding

A binary symmetric channel has ε=12\varepsilon=\frac12. What is its capacity?

  1. 0
  2. 12\frac12 bit, since half the bits arrive correctlyThey do, but the receiver can't tell which half. Set ε to 0.5 and look at the output law.
  3. 1 bitThat is the capacity of a perfect channel.
With ε=12\varepsilon=\frac12, YY is a fair coin whatever was sent, so YY is independent of XX and I(X;Y)=0I(X;Y)=0 for every input law. Indeed 1−Hb(12)=01-H_b(\frac12)=0.

A binary symmetric channel flips each bit with probability 0.9. How does its capacity compare with a channel that flips with probability 0.1?

  1. It is the same.
  2. It is nearly zero.The receiver can flip every bit back. That turns it into a channel with ε = 0.1.
  3. It is lower than at ε = 0.5.The capacity is smallest at 0.5. Look at the capacity curve.
Hb(0.9)=Hb(0.1)H_b(0.9)=H_b(0.1), so both have capacity 1−0.469=0.5311-0.469=0.531 bits. A channel that is almost always wrong is almost as useful as one that is almost always right; only one that is unpredictable is useless.

Why is the capacity defined as a maximum over input laws?

  1. The channel's noise is fixed, but the sender can choose how often to use each input symbol.
  2. Because I(X;Y)I(X;Y) is the same for every input law, so the maximum is just that value.Move the p slider: I(X;Y)I(X;Y) changes with the input law.
  3. To make the capacity independent of the noise.The capacity depends on the noise; for the symmetric channel it is 1−Hb(ε)1-H_b(\varepsilon).
I(X;Y)I(X;Y) depends on the channel and on the input law. Maximising over the part the sender controls leaves a number that describes the channel alone.

Practice

A ternary channelCapacity by symmetry

Inputs and outputs are {0,1,2}\{0,1,2\}. Each input jj arrives as jj or as j+1(mod3)j+1\pmod3, with probability 12\frac12 each. Find the capacity.

Hint

H(Y|X)H(Y\mid X) does not depend on the input law. Which input law makes H(Y)H(Y) as large as possible?

Solution

H(Y|X=j)=1H(Y\mid X=j)=1 for each jj, so H(Y|X)=1H(Y\mid X)=1. H(Y)≤log⁡3H(Y)\le\log3, with equality when YY is uniform, which happens when XX is uniform. So C=log⁡3−1≈0.585C=\log3-1\approx0.585 bits.

The repetition codeReliable, but slow

Over a binary symmetric channel with ε=0.1\varepsilon=0.1, each message bit is sent three times and decoded by majority vote. Find the probability of a decoding error and the rate. How does this compare with what Shannon's theorem allows?

Solution

Decoding fails if at least two of the three copies are flipped: 3ε2(1−ε)+ε3=0.027+0.001=0.0283\varepsilon^2(1-\varepsilon)+\varepsilon^3=0.027+0.001=0.028. The rate is 13\frac13 bit per use. The capacity is 1−Hb(0.1)≈0.5311-H_b(0.1)\approx0.531, so Shannon's theorem promises codes with rate up to about 0.53 and error probability as small as we like. Repetition buys reliability by giving up rate, and longer repetition makes the rate tend to 0; good codes avoid this.

More practice: Applebaum, Exercises 7.1, 7.2 and 7.5.

Animated lessonApplebaum, Ch. 7: Communication (§§7.3–7.4)

Prefix codes and Huffman coding

To compress a source, give common symbols short codewords and rare ones long codewords. Entropy is the floor: no code can beat HH bits per symbol on average. Huffman's algorithm builds the best possible prefix code by repeatedly merging the two least likely symbols. Watch it work.

The idea

Prefix-free code. A binary code in which no codeword is the beginning of another. Such a code can be decoded as the bits arrive, with no separators. Codewords correspond to leaves of a binary tree: 0 for left, 1 for right.
Kraft–McMillan inequality. A binary prefix-free code with codeword lengths l1,…,lnl_1,\dots,l_n exists if and only if ∑j2−lj≤1\sum_j 2^{-l_j}\le1. (McMillan: the inequality also holds for every uniquely decodable code.)
Noiseless coding theorem. For a source with law p1,…,pnp_1,\dots,p_n, every uniquely decodable code has average length E(L)=∑jpjlj≥HE(L)=\sum_j p_jl_j\ge H. There is a prefix-free code with E(L)<H+1E(L)<H+1: take lj=⌈−log⁡pj⌉l_j=\lceil-\log p_j\rceil (Shannon–Fano lengths).
Huffman's algorithm. Start with each symbol as a one-node tree with its probability. Repeatedly join the two trees of smallest probability under a new root, whose probability is their sum, until one tree remains. The resulting code has the smallest E(L)E(L) of all prefix-free codes.

E(L)=HE(L)=H exactly when every pjp_j is a power of 12\frac12. Otherwise the gap can be shrunk by coding blocks of mm symbols at a time, which gives H≤E(L)/m<H+1mH\le E(L)/m<H+\frac1m bits per symbol.

Watch

Source (six symbols)
the two trees being merged trees still waiting codeword lengths at the end
  1. Six symbols, sorted by probability. Each one starts as a tree on its own.
  2. Merge the two least likely trees. The new node's probability is their sum.
  3. Repeat with the trees that remain: again take the two smallest.
  4. And again. A merged node is treated exactly like a symbol.
  5. After this merge only two trees are left.
  6. The last merge makes the root.
  7. Label left branches 0 and right branches 1. Each codeword is the path from the root to its symbol. Compare the average length with the entropy.

Worked example

A source emits five symbols with probabilities 0.4, 0.2, 0.15, 0.15, 0.10.4,\ 0.2,\ 0.15,\ 0.15,\ 0.1. Build a Huffman code and compare it with the entropy and with the Shannon–Fano lengths.

  1. Carry out the merges.

    0.1+0.15=0.250.1+0.15=0.25. Now the smallest are 0.150.15 and 0.20.2: 0.350.35. Then 0.25+0.35=0.60.25+0.35=0.6. Finally 0.4+0.6=10.4+0.6=1.

  2. Read off the codeword lengths and the average length.

    The symbol of probability 0.4 joins only at the last merge: length 1. The other four sit two merges below the 0.6 node: length 3 each. So E(L)=0.4⋅1+0.6⋅3=2.2E(L)=0.4\cdot1+0.6\cdot3=2.2 bits. One valid code is 0, 100, 101, 110, 1110,\ 100,\ 101,\ 110,\ 111. Kraft: 12+4⋅18=1\frac12+4\cdot\frac18=1.

  3. Compute the entropy.

    H=0.4log⁡2.5+0.2log⁡5+2⋅0.15log⁡10.15+0.1log⁡10≈0.529+0.464+0.821+0.332=2.146H=0.4\log2.5+0.2\log5+2\cdot0.15\log\frac1{0.15}+0.1\log10\approx0.529+0.464+0.821+0.332=2.146 bits. So H≤E(L)<H+1H\le E(L)<H+1, with a gap of only about 0.05 bits.

  4. What do the Shannon–Fano lengths ⌈−log⁡pj⌉\lceil-\log p_j\rceil give?

    Lengths 2,3,3,3,42,3,3,3,4, so E(L)=0.8+0.6+0.45+0.45+0.4=2.7E(L)=0.8+0.6+0.45+0.45+0.4=2.7 bits. It also lies within 1 bit of HH, as the theorem promises, but Huffman does half a bit better.

Check your understanding

Is there a binary prefix-free code for four symbols with codeword lengths 1, 2, 2, 3?

  1. Yes, for example 0, 10, 11, 110110 begins with 11, which is another codeword.
  2. No
  3. Yes, as long as the shortest word goes to the most likely symbolWhether the lengths are possible doesn't depend on the probabilities at all.
12+14+14+18=98>1\frac12+\frac14+\frac14+\frac18=\frac98>1, so Kraft–McMillan rules it out. Lengths 1, 2, 3, 3 would work: 0, 10, 110, 111.

A source has two symbols with probabilities 0.9 and 0.1, so H≈0.469H\approx0.469 bits. What is the average length of its Huffman code?

  1. 0.469 bitsCodeword lengths are whole numbers, and each symbol needs at least one bit.
  2. 1 bit
  3. Somewhere between 0.469 and 1, depending on the codeWith two symbols the only sensible code is 0 and 1.
The code is {0,1}\{0,1\}, with E(L)=1E(L)=1, more than twice the entropy. Coding pairs of symbols brings it down to 0.645 bits per symbol (see the first practice problem); longer blocks get closer still.

For which sources does the Huffman code achieve E(L)=HE(L)=H exactly?

  1. When every probability is a power of 12\frac12
  2. When the source is uniformTry three equally likely symbols: H=log⁡3≈1.585H=\log3\approx1.585, but the best code has lengths 1, 2, 2 and E(L)=53E(L)=\frac53.
  3. Always, since Huffman codes are optimalOptimal among codes, but codes have whole-number lengths, and HH usually isn't of that form.
E(L)−H=∑pj(lj+log⁡pj)E(L)-H=\sum p_j(l_j+\log p_j) vanishes only if lj=−log⁡pjl_j=-\log p_j for each jj, which needs pj=2−ljp_j=2^{-l_j}. Try the "dyadic" source in the animation.

Practice

Coding pairsThe extension of a source

For the source with probabilities 0.9 and 0.1, code pairs of independent symbols. Build the Huffman code for the four pairs and find the average length per original symbol.

Solution

The pairs have probabilities 0.81, 0.09, 0.09, 0.01. Merge 0.01+0.09=0.100.01+0.09=0.10, then 0.09+0.10=0.190.09+0.10=0.19, then 0.19+0.810.19+0.81. Lengths: 1, 2, 3, 3, so E(L)=0.81+0.18+0.27+0.03=1.29E(L)=0.81+0.18+0.27+0.03=1.29 bits per pair, or 0.645 bits per symbol, against H≈0.469H\approx0.469. The bound says blocks of length mm are within 1m\frac1m of HH per symbol.

Likely symbols get short wordsAn exchange argument

Show that in a code of minimal average length, if pi>pjp_i>p_j then li≤ljl_i\le l_j.

Solution

Suppose pi>pjp_i>p_j but li>ljl_i>l_j. Swap the two codewords. The code is still prefix-free, and the average length changes by pilj+pjli−pili−pjlj=−(pi−pj)(li−lj)<0p_il_j+p_jl_i-p_il_i-p_jl_j=-(p_i-p_j)(l_i-l_j)<0. So the original code was not minimal.

More practice: Applebaum, Exercises 7.9, 7.12 and 7.15.

SimulationApplebaum, Ch. 8: Random variables with probability density functions

Densities and the central limit theorem

Add up many independent random quantities and, whatever their own shape, the sum looks normal. That is the central limit theorem, and it is why the bell curve is everywhere. Pick a lopsided distribution below, add nn copies, and watch the histogram of the standardised sum turn into the normal curve.

The idea

Density. XX has probability density function ff if P(a≤X≤b)=∫abf(x)dxP(a\le X\le b)=\int_a^b f(x)\,dx for all a≤ba\le b. Then E(X)=∫xf(x)dxE(X)=\int xf(x)\,dx and Var(X)=∫(x−μ)2f(x)dx\mathrm{Var}(X)=\int(x-\mu)^2f(x)\,dx. Examples: the uniform density on (a,b)(a,b), and the exponential density λe−λx\lambda e^{-\lambda x} on [0,∞)[0,\infty).
Chebyshev and the weak law. P(|X−μ|≥c)≤σ2/c2P(|X-\mu|\ge c)\le\sigma^2/c^2. Applied to the mean X‾n\bar X_n of nn i.i.d. copies, whose variance is σ2/n\sigma^2/n: P(|X‾n−μ|≥c)→0P(|\bar X_n-\mu|\ge c)\to0 as n→∞n\to\infty, for every c>0c>0.
Normal law. N(μ,σ2)N(\mu,\sigma^2) has density 1σ2πe−(x−μ)2/2σ2\dfrac{1}{\sigma\sqrt{2\pi}}e^{-(x-\mu)^2/2\sigma^2}. If X∼N(μ,σ2)X\sim N(\mu,\sigma^2) then Z=(X−μ)/σ∼N(0,1)Z=(X-\mu)/\sigma\sim N(0,1), with distribution function Φ\Phi.
Central limit theorem. If X1,X2,…X_1,X_2,\dots are i.i.d. with mean μ\mu and finite variance σ2>0\sigma^2>0, and Sn=X1+⋯+XnS_n=X_1+\dots+X_n, then for every zz
P(Sn−nμσn≤z)⟶Φ(z)(n→∞).P\!\left(\frac{S_n-n\mu}{\sigma\sqrt n}\le z\right)\longrightarrow\Phi(z)\qquad(n\to\infty).
Entropy of a density. H(X)=−∫flog⁡fdxH(X)=-\int f\log f\,dx. For U(a,b)U(a,b) it is log⁡(b−a)\log(b-a), which is negative when b−a<1b-a<1; for N(μ,σ2)N(\mu,\sigma^2) it is 12log⁡(2πeσ2)\frac12\log(2\pi e\sigma^2), the largest possible for a density with variance σ2\sigma^2.

Explore

Distribution of each term
The law of one term XiX_i.
histogram of (Sn−nμ)/σn(S_n-n\mu)/\sigma\sqrt n standard normal density

Worked example

A fair die is rolled 100 times. Estimate the probability that the total is at least 380.

  1. Find the mean and variance of a single roll.

    μ=3.5\mu=3.5, and E(X2)=916E(X^2)=\frac{91}6, so σ2=916−494=3512≈2.917\sigma^2=\frac{91}6-\frac{49}4=\frac{35}{12}\approx2.917.

  2. Find the mean and standard deviation of the total SS.

    E(S)=350E(S)=350 and Var(S)=100⋅3512≈291.7\mathrm{Var}(S)=100\cdot\frac{35}{12}\approx291.7, so the standard deviation is about 17.0817.08.

  3. Standardise and use the normal approximation.

    SS takes whole-number values, so "S≥380S\ge380" is the same as "S≥379.5S\ge379.5" (a continuity correction). Then

    P(S≥379.5)≈1−Φ(29.517.08)=1−Φ(1.727)≈0.042.P(S\ge379.5)\approx1-\Phi\!\left(\frac{29.5}{17.08}\right)=1-\Phi(1.727)\approx0.042.

    The exact value, from convolving the die's law 100 times, is 0.0420.

  4. What does Chebyshev's inequality give? Why is it so much weaker?

    P(|S−350|≥30)≤291.7/900≈0.32P(|S-350|\ge30)\le291.7/900\approx0.32, and that bounds both tails together. Chebyshev uses only the variance, so it must hold for every distribution with that variance, including very spread-out ones. The CLT uses the fact that SS is a sum of many independent pieces.

Check your understanding

X1,…,XnX_1,\dots,X_n are i.i.d. Uniform(0, 1). For large nn, what does the CLT say about Sn=X1+⋯+XnS_n=X_1+\dots+X_n?

  1. It is approximately N(n/2, n/12)N(n/2,\ n/12).
  2. It is approximately N(1/2, 1/12)N(1/2,\ 1/12).Those are the mean and variance of one term. For a sum of independent terms, means add and variances add.
  3. It is approximately uniform on (0,n)(0,n).Run the simulator with the uniform law and n=2n=2: the sum is already a triangle, not flat.
E(Sn)=n⋅12E(S_n)=n\cdot\frac12 and Var(Sn)=n⋅112\mathrm{Var}(S_n)=n\cdot\frac1{12}, and the CLT says the shape is approximately normal. For n=12n=12, S12−6S_{12}-6 is a classical quick approximation to N(0,1)N(0,1).

Can a probability density function take values bigger than 1?

  1. Yes
  2. No, because f(x)f(x) is a probability.f(x)f(x) is a probability per unit length. Only its integrals are probabilities.
  3. Only at finitely many points.The uniform density on (0,12)(0,\frac12) is 2 on the whole interval.
The uniform density on (0,12)(0,\frac12) equals 2 there, and still ∫f=1\int f=1. A density must be non-negative and integrate to 1; it can be as tall as it likes on a short interval.

What is the entropy −∫flog⁡f-\int f\log f of the uniform density on (0,12)(0,\frac12)?

  1. −1-1 bit
  2. It can't be negative, so 0.That is true for discrete entropy, where each pj≤1p_j\le1. A density can exceed 1, which makes −log⁡f-\log f negative.
  3. 1 bitCheck the sign: f=2f=2 and −log⁡2=−1-\log2=-1.
−∫01/22log⁡2dx=−1-\int_0^{1/2}2\log2\,dx=-1. Continuous entropy is not a count of bits and can be negative. Differences of such entropies, such as mutual information, are still meaningful and non-negative.

Practice

Four hundred tossesNormal approximation to the binomial

A fair coin is tossed 400 times. Estimate the probability that the number of heads is between 190 and 210 inclusive.

Solution

The count is b(400,12)b(400,\frac12), with mean 200 and standard deviation 100=10\sqrt{100}=10. With a continuity correction, P(189.5≤S≤210.5)≈Φ(1.05)−Φ(−1.05)≈0.706P(189.5\le S\le210.5)\approx\Phi(1.05)-\Phi(-1.05)\approx0.706. (The exact binomial value is also 0.706 to three places.)

From uniform to exponentialThe distribution-function method

Let UU be uniform on (0,1)(0,1) and Y=−ln⁡UY=-\ln U. Find the density of YY.

Hint

Compute P(Y>y)P(Y>y) for y≥0y\ge0 first.

Solution

For y≥0y\ge0, P(Y>y)=P(U<e−y)=e−yP(Y>y)=P(U<e^{-y})=e^{-y}. So FY(y)=1−e−yF_Y(y)=1-e^{-y} and fY(y)=e−yf_Y(y)=e^{-y}: YY is exponential with λ=1\lambda=1. This is how the simulator above generates exponential samples.

More practice: Applebaum, Exercises 8.19, 8.34 and 8.37.

InteractiveApplebaum, Ch. 9: Random vectors

Random vectors and conditional densities

Two random quantities measured together have a joint density. Slicing it at X=xX=x gives the conditional density of YY, and how much narrower that slice is than YY's own density measures how much XX tells you about YY. For the bivariate normal everything is explicit.

The idea

Joint density. P((X,Y)∈A)=∬Af(x,y)dxdyP\big((X,Y)\in A\big)=\iint_A f(x,y)\,dx\,dy. The marginal densities are fX(x)=∫f(x,y)dyf_X(x)=\int f(x,y)\,dy and fY(y)=∫f(x,y)dxf_Y(y)=\int f(x,y)\,dx.
Independence. XX and YY are independent exactly when f(x,y)=fX(x)fY(y)f(x,y)=f_X(x)f_Y(y).
Conditional density. Where fX(x)>0f_X(x)>0, fY|x(y)=f(x,y)fX(x)f_{Y\mid x}(y)=\dfrac{f(x,y)}{f_X(x)}: the slice of the joint density along X=xX=x, rescaled to have area 1.
Bivariate normal. With standard normal marginals and correlation ρ∈(−1,1)\rho\in(-1,1),
f(x,y)=12π1−ρ2exp⁡(−x2−2ρxy+y22(1−ρ2)),Y|X=x ∼ N(ρx, 1−ρ2).f(x,y)=\frac{1}{2\pi\sqrt{1-\rho^2}}\exp\!\left(-\frac{x^2-2\rho xy+y^2}{2(1-\rho^2)}\right), \qquad Y\mid X=x\ \sim\ N(\rho x,\ 1-\rho^2).
Information. Conditional entropy and mutual information carry over: H(Y|X)=−∬flog⁡fY|x(y)dxdyH(Y\mid X)=-\iint f\log f_{Y\mid x}(y)\,dx\,dy and I(X;Y)=H(Y)−H(Y|X)≥0I(X;Y)=H(Y)-H(Y\mid X)\ge0. For the bivariate normal, I(X;Y)=−12log⁡(1−ρ2)I(X;Y)=-\frac12\log(1-\rho^2). For a channel that adds independent noise Z∼N(0,N)Z\sim N(0,N) to an input of variance PP, the capacity is 12log⁡(1+P/N)\frac12\log(1+P/N), attained by a normal input.

Explore

Contours of f(x,y)f(x,y) and 500 sample points. Drag the vertical line to choose xx.
fYf_Y fY|xf_{Y\mid x}, the rescaled slice

Worked example

A point (X,Y)(X,Y) is chosen uniformly in the unit disc x2+y2<1x^2+y^2<1. Find the marginal and conditional densities, and decide whether XX and YY are correlated, and whether they are independent.

  1. What is the joint density? Find fXf_X.

    The disc has area π\pi, so f=1πf=\frac1\pi inside it. For |x|<1|x|<1, the vertical line at xx meets the disc in an interval of length 21−x22\sqrt{1-x^2}, so fX(x)=2π1−x2f_X(x)=\frac2\pi\sqrt{1-x^2}.

  2. Find the conditional density of YY given X=xX=x.

    fY|x(y)=1/π(2/π)1−x2=121−x2f_{Y\mid x}(y)=\dfrac{1/\pi}{(2/\pi)\sqrt{1-x^2}}=\dfrac{1}{2\sqrt{1-x^2}} for |y|<1−x2|y|<\sqrt{1-x^2}: uniform on the chord. Its spread depends on xx.

  3. Compute Cov(X,Y)\mathrm{Cov}(X,Y).

    The disc is symmetric under y↦−yy\mapsto-y, so E(Y)=0E(Y)=0 and E(XY)=0E(XY)=0. Hence Cov(X,Y)=0\mathrm{Cov}(X,Y)=0: uncorrelated.

  4. Are XX and YY independent?

    No. At (0.9,0.9)(0.9,0.9), outside the disc, f=0f=0, but fX(0.9)fY(0.9)>0f_X(0.9)f_Y(0.9)>0. Equivalently, the conditional law of YY changes with xx. (For the bivariate normal, by contrast, ρ=0\rho=0 does give independence: set ρ=0\rho=0 above and the slice matches fYf_Y for every xx.)

Check your understanding

(X,Y)(X,Y) is standard bivariate normal with ρ=0.8\rho=0.8. Given X=1X=1, what is the law of YY?

  1. N(1, 0.36)N(1,\ 0.36)The conditional mean is ρx\rho x, not xx. Move the slice to x=1x=1 and read off the peak.
  2. N(0.8, 0.36)N(0.8,\ 0.36)
  3. N(0.8, 1)N(0.8,\ 1)Knowing XX also narrows the spread of YY: the conditional variance is 1−ρ21-\rho^2.
Y|X=x∼N(ρx,1−ρ2)=N(0.8,0.36)Y\mid X=x\sim N(\rho x,1-\rho^2)=N(0.8,0.36). The mean is pulled toward 0 compared with xx (regression to the mean), and the variance doesn't depend on xx.

f(x,y)=x+yf(x,y)=x+y on the unit square 0<x,y<10<x,y<1. Are XX and YY independent?

  1. Yes, because the density lives on a rectangle.A rectangular range is needed for independence, but not enough. The density itself must factor.
  2. No
  3. Yes, by symmetry in xx and yy.Symmetry says XX and YY have the same law, not that they are independent.
fX(x)=x+12f_X(x)=x+\frac12 and fY(y)=y+12f_Y(y)=y+\frac12, and (x+12)(y+12)≠x+y(x+\frac12)(y+\frac12)\ne x+y in general (at x=y=0x=y=0 the left side is 14\frac14, the right 0).

What happens to I(X;Y)I(X;Y) for the bivariate normal as ρ→1\rho\to1?

  1. It tends to infinity.
  2. It tends to 1 bit.1 bit is the most two binary variables can share. Continuous variables can share far more.
  3. It tends to 0.The variables become more strongly dependent, not less. Slide ρ toward 0.95.
−12log⁡(1−ρ2)→∞-\frac12\log(1-\rho^2)\to\infty. As ρ→1\rho\to1, XX pins YY down to ever more decimal places, and each extra decimal place is more information.

Practice

A waiting-time pairMarginals and conditionals

(X,Y)(X,Y) has joint density f(x,y)=e−yf(x,y)=e^{-y} for 0<x<y0<x<y. Find fXf_X, fYf_Y and both conditional densities.

Solution

fX(x)=∫x∞e−ydy=e−xf_X(x)=\int_x^\infty e^{-y}dy=e^{-x} for x>0x>0, and fY(y)=∫0ye−ydx=ye−yf_Y(y)=\int_0^y e^{-y}dx=ye^{-y} for y>0y>0. Then fY|x(y)=e−(y−x)f_{Y\mid x}(y)=e^{-(y-x)} for y>xy>x, so given X=xX=x, Y−xY-x is exponential with λ=1\lambda=1. And fX|y(x)=1yf_{X\mid y}(x)=\frac1y for 0<x<y0<x<y: given Y=yY=y, XX is uniform on (0,y)(0,y).

Is more power worth it?The Gaussian channel

Using C=12log⁡(1+P/N)C=\frac12\log(1+P/N), find how much the capacity increases when the signal power PP is doubled, first at P/N=100P/N=100, then at P/N=0.01P/N=0.01.

Solution

At P/N=100P/N=100: 12log⁡201101≈0.496\frac12\log\frac{201}{101}\approx0.496, so about half a bit more, on top of 12log⁡101≈3.33\frac12\log101\approx3.33. At P/N=0.01P/N=0.01: CC goes from 12log⁡1.01≈0.00718\frac12\log1.01\approx0.00718 to 12log⁡1.02≈0.01429\frac12\log1.02\approx0.01429, almost exactly double. At low signal-to-noise ratio capacity is roughly proportional to power; at high ratio, each doubling adds only half a bit.

More practice: Applebaum, Exercises 9.17, 9.22 and 9.27.

SimulationApplebaum, Ch. 10: Markov chains and their entropy

Markov chains and entropy rate

A Markov chain forgets everything except where it is now. That one rule makes it settle into an equilibrium from any start, and it makes the information it produces per step easy to compute. Set the two switching probabilities and watch the chain converge.

The idea

Markov chain. A sequence X0,X1,…X_0,X_1,\dots on a finite state space with P(Xn+1=j|Xn=i, Xn−1,…,X0)=PijP(X_{n+1}=j\mid X_n=i,\ X_{n-1},\dots,X_0)=P_{ij}, depending only on ii and jj. The transition matrix PP has non-negative entries and rows summing to 1.
Chapman–Kolmogorov. The nn-step transition probabilities satisfy Pij(m+n)=∑kPik(m)Pkj(n)P^{(m+n)}_{ij}=\sum_kP^{(m)}_{ik}P^{(n)}_{kj}, so P(n)=PnP^{(n)}=P^n. If π(n)\pi^{(n)} is the law of XnX_n, written as a row vector, then π(n)=π(0)Pn\pi^{(n)}=\pi^{(0)}P^n.
Invariant distribution. A law ρ\rho with ρP=ρ\rho P=\rho. If the chain starts with law ρ\rho, every XnX_n has law ρ\rho and the process is stationary. If some power PmP^m has all entries positive, ρ\rho is unique and π(n)→ρ\pi^{(n)}\to\rho from every starting law.
Entropy rate. h=limn→∞⁡1nH(X0,…,Xn−1)h=\lim_{n\to\infty}\frac1nH(X_0,\dots,X_{n-1}). For a stationary Markov chain,
h=H(X1|X0)=−∑iρi∑jPijlog⁡Pij,h=H(X_1\mid X_0)=-\sum_i\rho_i\sum_jP_{ij}\log P_{ij},

the average, under ρ\rho, of the entropies of the rows of PP. It satisfies h≤H(ρ)h\le H(\rho), with equality exactly when all the rows are equal, that is, when the XnX_n are i.i.d.

Explore

The chain, and a simulated path: state 0 state 1
P(Xn=0|X0=0)P(X_n=0\mid X_0=0) P(Xn=0|X0=1)P(X_n=0\mid X_0=1) ρ0\rho_0

Worked example

A particle moves on the states 0,1,20,1,2 with transition matrix

P=(1212014121401212).P=\begin{pmatrix}\frac12&\frac12&0\\ \frac14&\frac12&\frac14\\ 0&\frac12&\frac12\end{pmatrix}.
  1. Starting from 0, what is the law of X2X_2?

    It is the first row of P2P^2: (12⋅12+12⋅14, 12⋅12+12⋅12, 12⋅14)=(38,12,18)\big(\frac12\cdot\frac12+\frac12\cdot\frac14,\ \frac12\cdot\frac12+\frac12\cdot\frac12,\ \frac12\cdot\frac14\big)=\big(\frac38,\frac12,\frac18\big).

  2. Find the invariant distribution.

    Solve ρP=ρ\rho P=\rho. The first column gives ρ0=12ρ0+14ρ1\rho_0=\frac12\rho_0+\frac14\rho_1, so ρ1=2ρ0\rho_1=2\rho_0; by symmetry ρ1=2ρ2\rho_1=2\rho_2. With ρ0+ρ1+ρ2=1\rho_0+\rho_1+\rho_2=1: ρ=(14,12,14)\rho=(\frac14,\frac12,\frac14). P2P^2 has all entries positive, so this is the limit from any start.

  3. Compute the entropy rate.

    The rows have entropies 1, 1.5 and 1 bits. So h=14⋅1+12⋅1.5+14⋅1=1.25h=\frac14\cdot1+\frac12\cdot1.5+\frac14\cdot1=1.25 bits per step.

  4. Compare with H(ρ)H(\rho) and interpret.

    H(ρ)=14⋅2+12⋅1+14⋅2=1.5H(\rho)=\frac14\cdot2+\frac12\cdot1+\frac14\cdot2=1.5 bits. An i.i.d. sequence with the same one-step law would produce 1.5 bits per step; the chain produces only 1.25, because each step is partly predictable from the last. A source like this can be compressed to about 1.25 bits per symbol, but only by a code that uses the previous symbol.

Check your understanding

The two-state chain above has P(0→1)=aP(0\to1)=a and P(1→0)=bP(1\to0)=b, with a+b>0a+b>0. What is ρ0\rho_0, the long-run fraction of time in state 0?

  1. ba+b\dfrac{b}{a+b}
  2. aa+b\dfrac{a}{a+b}A large aa means the chain leaves 0 quickly, so it should spend less time there, not more.
  3. 12\frac12, by symmetryThe two states are only symmetric when a=ba=b.
In equilibrium the flow out of 0 balances the flow in: ρ0a=ρ1b\rho_0a=\rho_1b. With ρ0+ρ1=1\rho_0+\rho_1=1 this gives ρ0=b/(a+b)\rho_0=b/(a+b).

Take a=b=1a=b=1: the chain switches state at every step. Starting from 0, does P(Xn=0)P(X_n=0) converge?

  1. Yes, to 12\frac12Starting from 0, the chain is at 0 at every even time and at 1 at every odd time. Set both sliders to 1.
  2. No, it alternates between 1 and 0, although (12,12)(\frac12,\frac12) is invariant.
  3. No, and there is no invariant distribution.Check (12,12)P(\frac12,\frac12)P.
PnP^n alternates between the identity and the swap matrix, so no power has all entries positive and the convergence theorem doesn't apply. The chain is periodic. Its invariant law (12,12)(\frac12,\frac12) still gives the long-run fraction of time in each state.

For a stationary Markov chain with invariant law ρ\rho, which is always true?

  1. h≤H(ρ)h\le H(\rho)
  2. h≥H(ρ)h\ge H(\rho)h=H(X1|X0)h=H(X_1\mid X_0), and conditioning cannot increase entropy on average.
  3. h=H(ρ)h=H(\rho)Only when X1X_1 is independent of X0X_0. Try a=0.1, b=0.3a=0.1,\ b=0.3.
h=H(X1|X0)≤H(X1)=H(ρ)h=H(X_1\mid X_0)\le H(X_1)=H(\rho), with equality exactly when X1X_1 and X0X_0 are independent, which for a Markov chain means every row of PP equals ρ\rho. For two states that is the line a+b=1a+b=1.

Practice

A walk around a cycleDoubly stochastic matrices

A particle on the cycle 0,1,…,N−10,1,\dots,N-1 (N≥3N\ge3) steps one place clockwise or anticlockwise with probability 12\frac12 each. Show that the uniform law is invariant and find the entropy rate. For which NN does P(Xn=0|X0=0)P(X_n=0\mid X_0=0) converge?

Solution

Every column of PP also sums to 1, so 1N(1,…,1)P=1N(1,…,1)\frac1N(1,\dots,1)P=\frac1N(1,\dots,1). Each row has two entries 12\frac12, so h=1h=1 bit per step, while H(ρ)=log⁡NH(\rho)=\log N. For even NN the chain alternates between even and odd states, so P(Xn=0|X0=0)=0P(X_n=0\mid X_0=0)=0 for odd nn and there is no convergence. For odd NN some power of PP is positive and the probability tends to 1N\frac1N.

A sticky chainEntropy rate of two states

Compute ρ\rho, hh and H(ρ)H(\rho) for the two-state chain with a=0.1a=0.1, b=0.3b=0.3. Check your answers in the explorer.

Solution

ρ=(0.30.4,0.10.4)=(0.75,0.25)\rho=(\frac{0.3}{0.4},\frac{0.1}{0.4})=(0.75,0.25). h=0.75Hb(0.1)+0.25Hb(0.3)≈0.75⋅0.469+0.25⋅0.881=0.572h=0.75\,H_b(0.1)+0.25\,H_b(0.3)\approx0.75\cdot0.469+0.25\cdot0.881=0.572 bits, while H(ρ)=Hb(0.25)≈0.811H(\rho)=H_b(0.25)\approx0.811 bits. The chain stays put most of the time, which makes it more predictable than an i.i.d. sequence spending the same fraction of time in each state.

More practice: Applebaum, Exercises 10.14, 10.23 and 10.24.