Probability

Seven modules, from counting and Bayes' theorem to random variables, the central limit theorem, random vectors and Markov chains. Drag the figures, run the simulations, work through an example one step at a time, then check yourself. The book's information-theory chapters (entropy, coding, channels) now have their own page, Information Theory.

Follows the chapter order of D. Applebaum, Probability and Information: An Integrated Approach, 2nd ed. (Cambridge University Press, 2008), and covers its probability chapters (2–5 and 8–10); Chapter 1 is the book's introduction, and Chapters 6–7 and the information-theory sections of 8–10 are on the Information Theory page. Chapter and exercise numbers refer to that book; the questions and examples here are written for this page. Exercises from the book appear at the end of each module, with their numbers from the book and their statements restated in our own words. Logarithms are to base 2 throughout, so information is measured in bits.

InteractiveApplebaum, Ch. 2: Combinatorics

Counting selections

Before probabilities come counts. Choosing r things from n 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 k stages and stage i can be done in mi ways whatever happened before, the whole task can be done in m1m2⋯mk ways.

Applied to choosing r objects from n distinct ones:

nr⏟ordered, repeatsn!(n−r)!⏟ordered, no repeats(nr)=n!r!(n−r)!⏟unordered, no repeats(n+r−1r)⏟unordered, repeats

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

Multinomial coefficient. The number of ways to split N distinct objects into labelled groups of sizes n1,…,nk (with n1+⋯+nk=N) is (Nn1,…,nk)=N!n1!⋯nk!. The binomial coefficient is the case k=2.
Gamma function. Γ(x)=∫0∞tx−1e−tdt for x>0. Integration by parts gives Γ(x+1)=xΓ(x), and Γ(1)=1, so Γ(n+1)=n!: the gamma function extends the factorial to non-integers. A special value worth knowing is Γ(12)=π.

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.

  2. How many have exactly two of each subject?

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

  3. How many contain at least one physicist?

    Count the complement. The committees with no physicist are the (64)=15 all-mathematician ones, so the answer is 330−15=315. (Adding up the cases "exactly 1, 2, 3, 4 physicists" gives 100+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=3960. Or pick the chair (11), the secretary (10), then the other two members from the remaining nine: 11⋅10⋅(92)=110⋅36=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=64That counts the balls as distinguishable: it records which ball went where. Here only how many balls each box gets matters.
  2. (43)=4That forbids two balls in the same box. Boxes may hold several balls.
  3. (63)=20
  4. 4⋅3⋅2=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. Check it in the explorer with n=4, r=3, "unordered, repeats".

In the explorer, set n=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 three-element sets appears in all 3!=6 of its orders. So 60=10⋅6, which is exactly the identity n!(n−r)!=r!(nr).

Given Γ(x+1)=xΓ(x) and Γ(12)=π, what is Γ(52)?

  1. 32πYou used the recursion once. Γ(52)=32Γ(32), and Γ(32) still has to be reduced.
  2. 34π
  3. 158πThat is Γ(72): one step too many.
  4. It is undefined: (32)! makes no sense.The factorial is only defined for integers, but the gamma function is defined for every x>0.
Γ(52)=32⋅Γ(32)=32⋅12⋅Γ(12)=34π≈1.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. With AAA as one block there are 5 items, B, S, N, N and the block, so 5!2!=60 strings.

A sum of squaresCounting one thing two ways

Show that ∑k=0n(nk)2=(2nn) by counting something in two ways.

Hint

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

Solution

Choosing n of the 2n people can be done in (2nn) ways. Alternatively, choose k women and n−k men, in (nk)(nn−k)=(nk)2 ways, and add over k=0,…,n. Both count the same selections.

From Applebaum, Probability and Information: An Integrated Approach (2nd ed., Cambridge, 2008)

Numbers match the book. Each question is restated in our own words; the hints and solutions are written for this page.

Exercise 2.7Pascal's rule

Show that (nr)+(nr+1)=(n+1r+1), and explain what it has to do with Pascal's triangle.

Hint

Count the (r+1)-element subsets of {1,…,n+1} according to whether they contain n+1.

Solution

A subset of size r+1 of {1,…,n+1} either contains n+1 (then the other r elements are chosen from n: (nr) ways) or doesn't (all r+1 from n: (nr+1) ways). Adding gives (n+1r+1).

Algebraically: n!r!(n−r)!+n!(r+1)!(n−r−1)!=n!(r+1)!(n−r)!((r+1)+(n−r))=(n+1r+1).

In Pascal's triangle row n lists (n0),…,(nn), and the identity says each entry is the sum of the two entries just above it.

Exercise 2.11Choosing seven from ten

Seven of a team of ten are chosen for a conference. How many choices are there (a) with no restriction, (b) if two particular members may not both go, (c) if one particular member must go?

Hint

For (b), split by how many of the two go.

Solution

(a) (107)=120.

(b) Neither of the two goes: (87)=8. Exactly one goes: 2(86)=56. Total 64. (Equivalently 120−(85)=120−56=64, removing the choices with both.) If "only one" is read as "exactly one", the answer is 56.

(c) Choose the other six from nine: (96)=84.

Exercise 2.16Stars and bars

Show that the number of ways of putting r indistinguishable objects into n distinguishable containers is (n+r−1r).

Hint

Line up the r objects and n−1 dividers.

Solution

A placement corresponds to a row of r stars and n−1 bars: the stars before the first bar go in container 1, those between bars 1 and 2 in container 2, and so on. Conversely every such row gives a placement. A row is determined by choosing which r of the n+r−1 positions hold stars, so there are (n+r−1r).

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 B of subsets of a set S that contains S and is closed under finite unions, intersections and complements. Its laws include the distributive laws and de Morgan's laws, A∪B―=A¯∩B¯ and A∩B―=A¯∪B¯.
Measure. A function m:B→[0,∞) that is additive on disjoint sets: if A∩B=∅ then m(A∪B)=m(A)+m(B). Its total mass is m(S); a measure with total mass 1 is a probability measure.

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

  • m(∅)=0, and A⊆B implies m(A)≤m(B).
  • m(A∖B)=m(A)−m(A∩B), since A is the disjoint union of A∖B and A∩B.
  • If E1,…,En partition S, then m(A)=∑im(A∩Ei).
Inclusion–exclusion. m(A∪B)=m(A)+m(B)−m(A∩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).

Explore

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

Worked example

Use the counting measure on S={1,2,…,30}. Let A, B, C be the multiples of 2, 3 and 5 in S.

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

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

  2. Find the sizes of all the intersections.

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

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

    By inclusion–exclusion, 15+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=22.

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

    In the sum #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=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.

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

Check your understanding

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

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

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

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

On the subsets of a finite set, define m(A)=(#A)2. Is m 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}, {b}: m({a,b})=4 but m({a})+m({b})=2. Any c⋅#A with c≥0 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) for any A,B∈B.

Hint

Split A∪B into three disjoint pieces: A∖B, A∩B, B∖A.

Solution

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

A lower bound for an intersectionBonferroni's inequality

Show that P(A∩B)≥P(A)+P(B)−1 for any probability measure. A part goes through two checks, which it passes with probabilities 0.97 and 0.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)−1, since P(A∪B)≤1. For the checks, P(both)≥0.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.9215.

From Applebaum, Probability and Information: An Integrated Approach (2nd ed., Cambridge, 2008)

Numbers match the book. Each question is restated in our own words; the hints and solutions are written for this page.

Exercise 3.6Exclusive or

Define A△B=(A∪B)−(A∩B). (a) Use the Boolean laws to show A△B=B△A, A△∅=A, A△A=∅, A△S=A¯, and A∩(B△C)=(A∩B)△(A∩C). (b) Verify A△B=(A−B)∪(B−A).

Hint

Write X−Y=X∩Y¯ and use De Morgan and distributivity. Doing (b) first makes (a) easier.

Solution

(b) (A∪B)∩A∩B―=(A∪B)∩(A¯∪B¯)=(A∩B¯)∪(B∩A¯), using distributivity and A∩A¯=∅=B∩B¯.

(a) Symmetry is clear from either formula. A△∅=(A∩S)∪(∅∩A¯)=A. A△A=(A∩A¯)∪(A∩A¯)=∅. A△S=(A∩∅)∪(S∩A¯)=A¯. For the last law, (A∩B)△(A∩C)=(A∩B∩A∩C―)∪(A∩C∩A∩B―). Since A∩A∩C―=A∩(A¯∪C¯)=A∩C¯, this is (A∩B∩C¯)∪(A∩C∩B¯)=A∩(B△C).

Exercise 3.10Inclusion–exclusion for three sets

For any measure m and sets A,B,C, show m(A∪B∪C)=m(A)+m(B)+m(C)−m(A∩B)−m(A∩C)−m(B∩C)+m(A∩B∩C).

Hint

Apply the two-set formula m(X∪Y)=m(X)+m(Y)−m(X∩Y) with X=A, Y=B∪C.

Solution

m(A∪(B∪C))=m(A)+m(B∪C)−m(A∩(B∪C)). Now m(B∪C)=m(B)+m(C)−m(B∩C), and A∩(B∪C)=(A∩B)∪(A∩C), so m(A∩(B∪C))=m(A∩B)+m(A∩C)−m(A∩B∩C). Substituting gives the formula.

Exercise 3.16The law of total probability

Let E1,…,En partition S and A⊆S. Show E1∩A,…,En∩A partition A, and deduce P(A)=∑iP(A∩Ei).

Hint

Check the two defining properties of a partition: disjoint, and union is everything.

Solution

For i≠j, (Ei∩A)∩(Ej∩A)⊆Ei∩Ej=∅. And ⋃i(Ei∩A)=(⋃iEi)∩A=S∩A=A. So they partition A (ignoring any empty pieces). Additivity of P over disjoint sets gives P(A)=∑iP(A∩Ei).

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) and P(ill∣positive), and Bayes' theorem is the rule for turning one into the other.

The idea

Conditional probability. If P(A)>0, the probability of B given A is P(B∣A)=P(A∩B)P(A). (The book writes PA(B).) For fixed A, B↦P(B∣A) is itself a probability measure.
Total probability and Bayes. If E1,…,En partition S and each P(Ei)>0, then
P(A)=∑iP(A∣Ei)P(Ei),P(Ek∣A)=P(A∣Ek)P(Ek)∑iP(A∣Ei)P(Ei).
Independence. A and B are independent if P(A∩B)=P(A)P(B), that is, learning A does not change the probability of B. Three events are independent if each pair is and also P(A∩B∩C)=P(A)P(B)P(C); pairwise independence alone is not enough.

For a diagnostic test, E1=D (ill) and E2=D¯. The sensitivity is P(+∣D), the specificity is P(−∣D¯), and the prevalence P(D) is the prior. Bayes gives the posterior P(D∣+).

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.299.

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

    P(spam∣F)=0.2850.299≈0.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.
  4. Are "spam" and "flagged" independent? What would independence mean for the filter?

    No: P(spam∣F)≈0.953≠0.3=P(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−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∣+)?

  1. 0.99That is P(+∣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.090. The false positives come from the 999 healthy people, so they outnumber the true positives about ten to one.

A and B 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 A happens, you know for certain that B did not.
  2. No
  3. Only if P(A)+P(B)=1.Check the definition: P(A∩B) would have to equal P(A)P(B).
P(A∩B)=P(∅)=0, but P(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), not P(D∣+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 D, P(D∣+1,+2) is Bayes' formula with prior P(D∣+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/3, not 1/2. With Bayes: P(RR∣red)=1⋅131⋅13+12⋅13+0=23.

Pairwise is not enoughIndependence of three events

Toss two fair coins. Let A = "first coin heads", B = "second coin heads", C = "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. A∩B={HH}, A∩C={HH}, B∩C={HH}, each of probability 14=12⋅12. But A∩B∩C={HH} has probability 14≠18. Knowing A and B together determines C, even though each alone tells you nothing about it.

From Applebaum, Probability and Information: An Integrated Approach (2nd ed., Cambridge, 2008)

Numbers match the book. Each question is restated in our own words; the hints and solutions are written for this page.

Exercise 4.14Defective CDs

14% of a factory's CDs are defective. Machine X makes 11% of the output with 8% defective; machine Y makes 23% with 4% defective. A random CD is defective. What is the probability it came from X or Y?

Hint

Bayes: P(X∪Y∣D)=P((X∪Y)∩D)/P(D).

Solution

P(D∩X)=0.11×0.08=0.0088 and P(D∩Y)=0.23×0.04=0.0092. So P(X∪Y∣D)=(0.0088+0.0092)/0.14=0.018/0.14≈0.129. Only about 13% of the defects come from X and Y, so the suspicion is wrong.

Exercise 4.20Pairwise but not mutually independent

Two fair dice are thrown. A: the first shows 1, 2 or 3. B: the second shows 4, 5 or 6. C: both show at most 3, or both show at least 4. Show each pair is independent but P(A∩B∩C)≠P(A)P(B)P(C).

Hint

Each event has probability 1/2; count outcomes out of 36.

Solution

P(A)=P(B)=1/2, and P(C)=(9+9)/36=1/2.

A∩B: first ≤3, second ≥4: 9/36=1/4. A∩C: both ≤3: 1/4. B∩C: both ≥4: 1/4. Each equals the product 1/4, so the pairs are independent.

A∩B∩C needs the first ≤3 and second ≥4, and also both on the same side: impossible. So P(A∩B∩C)=0≠1/8.

Exercise 4.29A positive test for a rare disease

A test has P(Tp∣Dp)=P(Tn∣Da)=0.99. The disease has prevalence P(Dp)=0.0001. You test positive. Explain why P(Dp∣Tp) is the relevant number and compute it.

Hint

Bayes' theorem; most positives come from the large healthy population.

Solution

The question you care about is "given my positive result, how likely is the disease?", which is P(Dp∣Tp), not the test's sensitivity P(Tp∣Dp).

P(Dp∣Tp)=0.99×0.00010.99×0.0001+0.01×0.9999≈0.0098.

Less than 1%. A positive result raises the probability about a hundredfold, but false positives from the healthy 99.99% still swamp the true ones.

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 X from the sample space to R. For discrete X, its law is p(x)=P(X=x) and its cumulative distribution is F(x)=P(X≤x).
Mean and variance. E(X)=∑xxp(x) and Var(X)=E((X−μ)2)=E(X2)−E(X)2. Expectation is linear, Var(aX+b)=a2Var(X), and for independent X,Y, Var(X+Y)=Var(X)+Var(Y).

Three laws that come up again and again:

  • Binomial b(n,p): the number of successes in n independent trials, p(k)=(nk)pk(1−p)n−k; mean np, variance np(1−p).
  • Poisson π(λ): p(k)=e−λλk/k! for k=0,1,2,…; mean and variance both λ. It is the limit of b(n,λ/n) as n→∞: many trials, each rarely a success.
  • Geometric: the number of the trial on which the first success happens, p(r)=p(1−p)r−1 for r=1,2,…; mean 1/p, variance (1−p)/p2.
Averages settle down. If X1,X2,… are i.i.d. with mean μ and variance σ2, the sample mean X¯n has mean μ and variance σ2/n. So its typical distance from μ shrinks like 1/n. (The law of large numbers itself is proved in Chapter 8.)

Key terms in plain words

The ideas above without the symbols. Switch to Quiz me to test yourself: you see an explanation and pick the term it describes.

Random variable
A number determined by the outcome of a random experiment, such as the number of heads in ten coin flips.
Probability mass function
For a variable with countably many values, the list of possible values with the chance of each.
Cumulative distribution function
For each number x, the chance that the variable is at most x. It climbs from 0 to 1.
Expectation
The long-run average value: each possible value weighted by its chance. The one for a sum is the sum of the individual ones, always.
Variance
The average squared distance from the mean: how spread out the values are. For independent variables it adds up.
Binomial distribution
The number of successes in a fixed number of independent tries, each with the same chance of success.
Poisson distribution
The number of rare events in a fixed window when there are many chances, each unlikely. Its mean and variance are equal.
Geometric distribution
The number of tries up to and including the first success.

Explore

Law
the law p(k) relative frequency in your samples Poisson overlay
running mean X¯n E(X) and the band E(X)±σ/n

Worked example

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

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

    X∼b(200,0.01), so P(X=0)=0.99200≈0.1340.

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

    Match the means: λ=np=2. Then P(X=0)≈e−2≈0.1353, within about 1% of the exact value.

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

    Use the complement. Exactly: 1−(0.1340+0.2707+0.2720)≈0.3233. Poisson: 1−e−2(1+2+2)=1−5e−2≈0.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.98; the Poisson variance is λ=2. The factor 1−p is the only difference, and it tends to 1 as p→0 with np fixed. That is the regime in which the Poisson approximation is good.

Check your understanding

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

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

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

  1. 4That would be true of the variance of 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, so the standard deviation is σ/n. Four times as many draws halves it. That is the band drawn around E(X) in the right-hand plot.

X is uniform on {−1,0,1} and Y=X2. Which is true?

  1. They are independent, because they are uncorrelated.Uncorrelated only says E(XY)=E(X)E(Y). Compare P(Y=0∣X=0) with P(Y=0).
  2. They are uncorrelated but not independent.
  3. They are correlated, since Y is a function of X.Compute Cov(X,Y)=E(X3)−E(X)E(X2).
E(XY)=E(X3)=0=E(X)E(Y), so the covariance is 0. But P(Y=0∣X=0)=1≠13=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−1 for r≥1, then E(X)=1/p.

Hint

Differentiate ∑r≥0xr=11−x for |x|<1.

Solution

Differentiating gives ∑r≥1rxr−1=1(1−x)2. With x=1−p, E(X)=p∑r≥1r(1−p)r−1=p⋅1p2=1p. 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∼π(λ). Each email, independently, is spam with probability s. Show that the number of spam emails K is Poisson with mean λs.

Hint

Given N=n, K∼b(n,s). Sum over n≥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!,

where m=n−k. So K∼π(λs).

From Applebaum, Probability and Information: An Integrated Approach (2nd ed., Cambridge, 2008)

Numbers match the book. Each question is restated in our own words; the hints and solutions are written for this page.

Exercise 5.22Uncorrelated but dependent

X is uniform on {−2,−1,1,2} and Y=X2. Find the joint distribution and show X,Y are uncorrelated but not independent.

Hint

Compute E(XY)=E(X3) and compare a joint probability with the product of marginals.

Solution

The joint law puts mass 1/4 on each of (−2,4),(−1,1),(1,1),(2,4); Y is 1 or 4 with probability 1/2 each.

EX=0 and E(XY)=EX3=14(−8−1+1+8)=0, so Cov(X,Y)=0.

But P(X=1,Y=4)=0≠P(X=1)P(Y=4)=1/8, so they are not independent. Y is a function of X; correlation only detects linear dependence.

Exercise 5.23Defective items

Fifteen items are each defective with probability 0.3, independently. Find the probability that (a) exactly three are defective; (b) more than four are; (c) more than 11 are not defective; (d) fewer than five are defective; (e) between two and six (inclusive) are defective.

Hint

X∼Bin(15,0.3), P(X=k)=(15k)0.3k0.715−k. Rewrite (c) in terms of defectives.

Solution

(a) (153)(0.3)3(0.7)12≈0.170.

(b) P(X≥5)=1−P(X≤4)≈1−0.515=0.485.

(c) More than 11 good means at most 3 defective: P(X≤3)≈0.297.

(d) P(X≤4)≈0.515.

(e) P(2≤X≤6)=P(X≤6)−P(X≤1)≈0.869−0.035=0.834.

Exercise 5.36Poisson plus Poisson

If X∼π(λ) and Y∼π(μ) are independent, show X+Y∼π(λ+μ).

Hint

Convolve, and recognise the binomial theorem.

Solution
P(X+Y=n)=∑k=0ne−λλkk!⋅e−μμn−k(n−k)!=e−(λ+μ)n!∑k=0n(nk)λkμn−k=e−(λ+μ)(λ+μ)nn!.
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 n copies, and watch the histogram of the standardised sum turn into the normal curve.

The idea

Density. X has probability density function f if P(a≤X≤b)=∫abf(x)dx for all a≤b. Then E(X)=∫xf(x)dx and Var(X)=∫(x−μ)2f(x)dx. Examples: the uniform density on (a,b), and the exponential density λe−λx on [0,∞).
Chebyshev and the weak law. P(|X−μ|≥c)≤σ2/c2. Applied to the mean X¯n of n i.i.d. copies, whose variance is σ2/n: P(|X¯n−μ|≥c)→0 as n→∞, for every c>0.
Normal law. N(μ,σ2) has density 1σ2πe−(x−μ)2/2σ2. If X∼N(μ,σ2) then Z=(X−μ)/σ∼N(0,1), with distribution function Φ.
Central limit theorem. If X1,X2,… are i.i.d. with mean μ and finite variance σ2>0, and Sn=X1+⋯+Xn, then for every z
P(Sn−nμσn≤z)⟶Φ(z)(n→∞).
Entropy of a density. H(X)=−∫flog⁡fdx. For U(a,b) it is log⁡(b−a), which is negative when b−a<1; for N(μ,σ2) it is 12log⁡(2πeσ2), the largest possible for a density with variance σ2.

Key terms in plain words

The ideas above without the symbols. Switch to Quiz me to test yourself: you see an explanation and pick the term it describes.

Probability density
A curve whose area over an interval is the chance of landing in that interval. Its height is not itself a probability, and can be bigger than 1.
Chebyshev's inequality
A variable is rarely many standard deviations from its mean: the chance of being at least c away is at most the variance divided by c2.
Weak law of large numbers
The average of many independent copies of a variable gets close to its true mean, with probability tending to one.
Normal distribution
The bell curve, fixed by its centre and its spread. Subtracting the centre and dividing by the spread turns any one of them into the standard one.
Central limit theorem
Add up many independent copies of almost any variable, then centre and rescale the total: its distribution approaches the bell curve, whatever the original shape.
Differential entropy
A measure of how spread out or unpredictable a continuous distribution is. Among distributions with a given variance the bell curve has the most; unlike the discrete version, it can be negative.

Explore

Distribution of each term
The law of one term Xi.
histogram of (Sn−nμ)/σ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, and E(X2)=916, so σ2=916−494=3512≈2.917.

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

    E(S)=350 and Var(S)=100⋅3512≈291.7, so the standard deviation is about 17.08.

  3. Standardise and use the normal approximation.

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

    P(S≥379.5)≈1−Φ(29.517.08)=1−Φ(1.727)≈0.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.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 S is a sum of many independent pieces.

Check your understanding

X1,…,Xn are i.i.d. Uniform(0, 1). For large n, what does the CLT say about Sn=X1+⋯+Xn?

  1. It is approximately N(n/2, n/12).
  2. It is approximately 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).Run the simulator with the uniform law and n=2: the sum is already a triangle, not flat.
E(Sn)=n⋅12 and Var(Sn)=n⋅112, and the CLT says the shape is approximately normal. For n=12, S12−6 is a classical quick approximation to N(0,1).

Can a probability density function take values bigger than 1?

  1. Yes
  2. No, because f(x) is a probability.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) is 2 on the whole interval.
The uniform density on (0,12) equals 2 there, and still ∫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 of the uniform density on (0,12)?

  1. −1 bit
  2. It can't be negative, so 0.That is true for discrete entropy, where each pj≤1. A density can exceed 1, which makes −log⁡f negative.
  3. 1 bitCheck the sign: f=2 and −log⁡2=−1.
−∫01/22log⁡2dx=−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), with mean 200 and standard deviation 100=10. With a continuity correction, P(189.5≤S≤210.5)≈Φ(1.05)−Φ(−1.05)≈0.706. (The exact binomial value is also 0.706 to three places.)

From uniform to exponentialThe distribution-function method

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

Hint

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

Solution

For y≥0, P(Y>y)=P(U<e−y)=e−y. So FY(y)=1−e−y and fY(y)=e−y: Y is exponential with λ=1. This is how the simulator above generates exponential samples.

From Applebaum, Probability and Information: An Integrated Approach (2nd ed., Cambridge, 2008)

Numbers match the book. Each question is restated in our own words; the hints and solutions are written for this page.

Exercise 8.19Chebyshev's estimate

X has mean 2 and variance 1.6. Estimate P(X>5).

Hint

Without more information, Chebyshev is the tool.

Solution

P(X>5)≤P(|X−2|≥3)≤1.69≈0.18. This is an upper bound, not an approximation; one-sided Cantelli gives the sharper 1.61.6+9≈0.15.

Exercise 8.34Heads between 45% and 55%

A coin lands heads with probability 0.45. Estimate the probability that in 25 throws the proportion of heads is between 45% and 55%.

Hint

Between 11.25 and 13.75 heads means 12 or 13. Use the normal approximation with mean 11.25 and standard deviation 25⋅0.45⋅0.55≈2.49.

Solution

With the continuity correction, P(11.5≤X≤13.5)≈Φ(0.905)−Φ(0.100)≈0.817−0.540=0.28. The exact binomial value is P(X=12)+P(X=13)≈0.275. (Without the continuity correction one gets Φ(1.0)−Φ(0)≈0.34, a noticeably worse estimate at n=25.)

Exercise 8.37Entropy of the exponential distribution

Find the entropy of X∼E(λ).

Hint

−log⁡f(x)=−log⁡λ+λxlog⁡e, and EX=1/λ.

Solution

H(X)=−∫0∞λe−λxlog⁡(λe−λx)dx=−log⁡λ+λE(X)log⁡e=log⁡eλ. In nats this is 1−ln⁡λ. It can be negative (when λ>e), as differential entropies can.

Interactivevon Neumann (1951); Kook–Vempala–Zhang (2026), §3.3

Rejection sampling with a budget

To sample from a distribution restricted to a set you can only test membership in, propose from the unrestricted distribution and throw away proposals that miss. The result is exact. The cost is random, and averaging that cost over many starting points can make it infinite.

The idea

The task. Given a point y, a step size h and a set X⊂Rn that you can query (“is x∈X?”), draw from N(y,hI) conditioned on landing in X. Rejection sampling repeats: propose x′∼N(y,hI); if x′∈X, stop and output x′; otherwise try again. Each trial succeeds independently with probability

ℓ=Pr(y+hZ∈X),Z∼N(0,In).

The output has exactly the right law. Summing over the trial k at which the first success happens,
Pr(output∈A)=∑k≥1(1−ℓ)k−1Pr(x′∈A∩X)=Pr(x′∈A∩X)ℓ=Pr(x′∈A∣x′∈X).
The number of trials G is geometric. Pr(G=k)=(1−ℓ)k−1ℓ, with mean EG=1/ℓ. A point just outside a thin part of X can have tiny ℓ and an enormous expected cost.
A budget of N trials. Stop after N failures and declare failure. Then
Pr(failure)=(1−ℓ)N≤e−Nℓ,Emin{G,N}=1−(1−ℓ)Nℓ≤min{1ℓ,N}.
The budget trades a small chance of failure for a guaranteed bound on the work.

The general version. To sample a density p using proposals from a density g with p≤Mg, accept a proposal x with probability p(x)/(Mg(x)). The acceptance probability is 1/M, and accepted points have density exactly p. Restricting to a set is the case p=g1X/ℓ, M=1/ℓ, where the acceptance test is just “is x∈X?”.

Why the budget is not optional. In a sampler the start y is itself random. The expected cost is then E[1/ℓ(y)], which can be infinite even though every single ℓ(y) is positive. That happens when y lands in regions of tiny conductance with probability comparable to that conductance. On the Sampling Nonconvex Bodies page this is exactly what happens: the average of 1/ℓ over a stationary forward step equals Vol(Rn)/Vol(X)=∞.

Explore

Drag y. proposals inside X (accepted) and outside (rejected). The dashed circle has radius 2h, the typical length of a step in the plane.
Pr(G=k) for the current ℓ. the bars beyond the budget N: their total is the failure probability.

Worked example

A point with local conductance ℓ=14 and a budget of N=6 trials.

  1. How many trials does it take on average without a budget?

    EG=1/ℓ=4.

  2. What is the chance of failure with the budget?

    (3/4)6≈0.178, about one in six. The bound e−Nℓ=e−1.5≈0.223 is close.

  3. How many trials are used on average with the budget?

    (1−(3/4)6)/14≈3.29: a little below 4, because the long runs are cut off at 6.

  4. How large must N be for failure probability at most 10−3?

    Need (3/4)N≤10−3, i.e. N≥ln⁡(1000)/ln⁡(4/3)≈24.0, so N=25. The e−Nℓ bound asks for N≥4ln⁡1000≈27.6, a little more.

Check your understanding

Rejection sampling with a budget fails with probability 0.01. Conditioned on succeeding, is the output still exactly distributed as N(y,hI) restricted to X?

  1. Yes: given that some trial among the first N succeeds, the first successful trial is still a fresh proposal conditioned on landing in X.
  2. No: the budget biases the output towards points that are easy to reach.Every trial has the same law, so which trial succeeds first is independent of where it lands.
Truncation changes how often you get an output, not what the output looks like. Bias appears only later, when y is random and failures are more likely from some y than others.

The start y is random with ℓ(y) uniform on (0,1]. What is the expected number of trials without a budget?

  1. 2.That is 1/E[ℓ]. The expected cost is E[1/ℓ], which is larger.
  2. Infinite: E[1/ℓ]=∫01du/u=∞.
  3. ln⁡2.The integral ∫01du/u diverges at 0.
Every individual y has finite expected cost, but rare y with tiny ℓ cost so much that the average diverges. A budget N caps the cost at ∫01min(1/u,N)du=1+ln⁡N.

In the figure, drag y deep inside the set and then far outside it. What happens to ℓ, and why does a larger spread h not always help?

  1. ℓ is near 1 inside and tiny far outside. A larger spread helps a point just outside reach X, but it also sends proposals from a point inside out of X.
  2. ℓ is always about 12 near the set.That holds only right at a flat piece of boundary; corners and thin parts change it.
This tension is why samplers tie the step size to how thin the set is: here, to the arm width.

Practice

The truncated meanCompute E min(G, N)

Show that Emin{G,N}=(1−(1−ℓ)N)/ℓ for G geometric with success probability ℓ.

Outline
  1. For a nonnegative integer variable, EM=∑k≥0Pr(M>k).
    Why?

    M=∑k≥01{M>k}; take expectations.

  2. Pr(min{G,N}>k)=(1−ℓ)k for k<N, and 0 for k≥N.
    Why?

    G>k means the first k trials all failed.

  3. Sum the geometric series ∑k=0N−1(1−ℓ)k.
    Why?

    It equals (1−(1−ℓ)N)/ℓ.

Exactness of the general methodAccept with probability p/(Mg)

Let p≤Mg. Propose x∼g and accept with probability p(x)/(Mg(x)). Show that the acceptance probability is 1/M and that accepted points have density p.

Outline
  1. Pr(accept,x∈A)=∫Ag(x)p(x)Mg(x)dx=1M∫Ap.
    Why?

    Condition on the proposal x, then integrate over it.

  2. Take A=Rn to get Pr(accept)=1/M, then divide.
    Why?

    Pr(x∈A∣accept)=∫Ap.

Key terms in plain words

The ideas above without the symbols. Switch to Quiz me to test yourself: you see an explanation and pick the term it describes.

Rejection sampling
Drawing from an easy distribution and keeping a draw only if it passes a test, so that the kept draws follow the harder distribution exactly.
Local conductance
The chance that one proposal from a given point lands inside the set: the success probability of each trial.
Geometric distribution
The number of independent tries needed until the first success; its average is one over the success probability.
Trial budget
A cap on the number of tries, after which the procedure gives up, making the work bounded at the price of a small failure probability.
InteractiveApplebaum, Ch. 9: Random vectors

Random vectors and conditional densities

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

The idea

Joint density. P((X,Y)∈A)=∬Af(x,y)dxdy. The marginal densities are fX(x)=∫f(x,y)dy and fY(y)=∫f(x,y)dx.
Independence. X and Y are independent exactly when f(x,y)=fX(x)fY(y).
Conditional density. Where fX(x)>0, fY∣x(y)=f(x,y)fX(x): the slice of the joint density along X=x, rescaled to have area 1.
Bivariate normal. With standard normal marginals and correlation ρ∈(−1,1),
f(x,y)=12π1−ρ2exp(−x2−2ρxy+y22(1−ρ2)),Y∣X=x ∼ N(ρx, 1−ρ2).
Information. Conditional entropy and mutual information carry over: H(Y∣X)=−∬flog⁡fY∣x(y)dxdy and I(X;Y)=H(Y)−H(Y∣X)≥0. For the bivariate normal, I(X;Y)=−12log⁡(1−ρ2). For a channel that adds independent noise Z∼N(0,N) to an input of variance P, the capacity is 12log⁡(1+P/N), attained by a normal input.

Explore

Contours of f(x,y) and 500 sample points. Drag the vertical line to choose x.
fY fY∣x, the rescaled slice

Worked example

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

  1. What is the joint density? Find fX.

    The disc has area π, so f=1π inside it. For |x|<1, the vertical line at x meets the disc in an interval of length 21−x2, so fX(x)=2π1−x2.

  2. Find the conditional density of Y given X=x.

    fY∣x(y)=1/π(2/π)1−x2=121−x2 for |y|<1−x2: uniform on the chord. Its spread depends on x.

  3. Compute Cov(X,Y).

    The disc is symmetric under y↦−y, so E(Y)=0 and E(XY)=0. Hence Cov(X,Y)=0: uncorrelated.

  4. Are X and Y independent?

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

Check your understanding

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

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

f(x,y)=x+y on the unit square 0<x,y<1. Are X and Y 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 x and y.Symmetry says X and Y have the same law, not that they are independent.
fX(x)=x+12 and fY(y)=y+12, and (x+12)(y+12)≠x+y in general (at x=y=0 the left side is 14, the right 0).

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

  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)→∞. As ρ→1, X pins Y down to ever more decimal places, and each extra decimal place is more information.

Practice

A waiting-time pairMarginals and conditionals

(X,Y) has joint density f(x,y)=e−y for 0<x<y. Find fX, fY and both conditional densities.

Solution

fX(x)=∫x∞e−ydy=e−x for x>0, and fY(y)=∫0ye−ydx=ye−y for y>0. Then fY∣x(y)=e−(y−x) for y>x, so given X=x, Y−x is exponential with λ=1. And fX∣y(x)=1y for 0<x<y: given Y=y, X is uniform on (0,y).

Is more power worth it?The Gaussian channel

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

Solution

At P/N=100: 12log⁡201101≈0.496, so about half a bit more, on top of 12log⁡101≈3.33. At P/N=0.01: C goes from 12log⁡1.01≈0.00718 to 12log⁡1.02≈0.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.

From Applebaum, Probability and Information: An Integrated Approach (2nd ed., Cambridge, 2008)

Numbers match the book. Each question is restated in our own words; the hints and solutions are written for this page.

Exercise 9.17Correlation of the bivariate normal

For the bivariate normal vector with parameters μ1,μ2,σ1,σ2,ρ, show ρ(X,Y)=ρ. Deduce that X,Y are independent iff E(XY)=E(X)E(Y).

Hint

Standardise to U=(X−μ1)/σ1, V=(Y−μ2)/σ2. Conditionally on U=u, V is normal with mean ρu.

Solution

The density of (U,V) factors as ϕ(u)⋅11−ρ2ϕ(v−ρu1−ρ2) (complete the square in the exponent). So E(V∣U)=ρU and E(UV)=E(U⋅ρU)=ρ. Hence Cov(X,Y)=ρσ1σ2 and ρ(X,Y)=ρ.

If E(XY)=EXEY, the covariance is 0, so ρ=0 and the density becomes ϕ(u)ϕ(v) (in standardised form): a product, so independent. The converse holds for any independent pair.

Exercise 9.22Sums of independent normals

Show that if X∼N(μ1,σ12) and Y∼N(μ2,σ22) are independent, X+Y is normal, and find its mean and variance.

Hint

Moment generating functions multiply for independent sums.

Solution

MX(t)=eμ1t+σ12t2/2, similarly for Y. By independence MX+Y(t)=MX(t)MY(t)=e(μ1+μ2)t+(σ12+σ22)t2/2, the MGF of N(μ1+μ2,σ12+σ22). Since the MGF determines the distribution, X+Y∼N(μ1+μ2,σ12+σ22).

Exercise 9.27Entropy of the bivariate normal

Using H(X,Y)=H(X)+HX(Y), compute the entropy of the bivariate normal vector.

Hint

X∼N(μ1,σ12), and given X=x, Y is normal with variance σ22(1−ρ2) whatever x is. A normal with variance s2 has entropy 12log⁡(2πes2).

Solution

H(X)=12log⁡(2πeσ12). The conditional entropy HX(Y) averages the entropy of the conditional law over x, and that is 12log⁡(2πeσ22(1−ρ2)) for every x. So

H(X,Y)=log⁡(2πeσ1σ21−ρ2)=12log⁡((2πe)2detΣ).

As |ρ|→1 the entropy goes to −∞: the distribution collapses onto a line.

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,… on a finite state space with P(Xn+1=j∣Xn=i, Xn−1,…,X0)=Pij, depending only on i and j. The transition matrix P has non-negative entries and rows summing to 1.
Chapman–Kolmogorov. The n-step transition probabilities satisfy Pij(m+n)=∑kPik(m)Pkj(n), so P(n)=Pn. If π(n) is the law of Xn, written as a row vector, then π(n)=π(0)Pn.
Invariant distribution. A law ρ with ρP=ρ. If the chain starts with law ρ, every Xn has law ρ and the process is stationary. If some power Pm has all entries positive, ρ is unique and π(n)→ρ from every starting law.
Entropy rate. h=limn→∞1nH(X0,…,Xn−1). For a stationary Markov chain,
h=H(X1∣X0)=−∑iρi∑jPijlog⁡Pij,

the average, under ρ, of the entropies of the rows of P. It satisfies h≤H(ρ), with equality exactly when all the rows are equal, that is, when the Xn are i.i.d.

Explore

The chain, and a simulated path: state 0 state 1
P(Xn=0∣X0=0) P(Xn=0∣X0=1) ρ0

Worked example

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

P=(1212014121401212).
  1. Starting from 0, what is the law of X2?

    It is the first row of P2: (12⋅12+12⋅14, 12⋅12+12⋅12, 12⋅14)=(38,12,18).

  2. Find the invariant distribution.

    Solve ρP=ρ. The first column gives ρ0=12ρ0+14ρ1, so ρ1=2ρ0; by symmetry ρ1=2ρ2. With ρ0+ρ1+ρ2=1: ρ=(14,12,14). P2 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.25 bits per step.

  4. Compare with H(ρ) and interpret.

    H(ρ)=14⋅2+12⋅1+14⋅2=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)=a and P(1→0)=b, with a+b>0. What is ρ0, the long-run fraction of time in state 0?

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

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

  1. Yes, to 12Starting 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) is invariant.
  3. No, and there is no invariant distribution.Check (12,12)P.
Pn 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) still gives the long-run fraction of time in each state.

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

  1. h≤H(ρ)
  2. h≥H(ρ)h=H(X1∣X0), and conditioning cannot increase entropy on average.
  3. h=H(ρ)Only when X1 is independent of X0. Try a=0.1, b=0.3.
h=H(X1∣X0)≤H(X1)=H(ρ), with equality exactly when X1 and X0 are independent, which for a Markov chain means every row of P equals ρ. For two states that is the line a+b=1.

Practice

A walk around a cycleDoubly stochastic matrices

A particle on the cycle 0,1,…,N−1 (N≥3) steps one place clockwise or anticlockwise with probability 12 each. Show that the uniform law is invariant and find the entropy rate. For which N does P(Xn=0∣X0=0) converge?

Solution

Every column of P also sums to 1, so 1N(1,…,1)P=1N(1,…,1). Each row has two entries 12, so h=1 bit per step, while H(ρ)=log⁡N. For even N the chain alternates between even and odd states, so P(Xn=0∣X0=0)=0 for odd n and there is no convergence. For odd N some power of P is positive and the probability tends to 1N.

A sticky chainEntropy rate of two states

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

Solution

ρ=(0.30.4,0.10.4)=(0.75,0.25). h=0.75Hb(0.1)+0.25Hb(0.3)≈0.75⋅0.469+0.25⋅0.881=0.572 bits, while H(ρ)=Hb(0.25)≈0.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.

From Applebaum, Probability and Information: An Integrated Approach (2nd ed., Cambridge, 2008)

Numbers match the book. Each question is restated in our own words; the hints and solutions are written for this page.

Exercise 10.14Invariant distributions

Decide whether each chain has an invariant distribution and find it: (a) (0.70.30.40.6); (b) (1/21/41/41/81/23/83/81/43/8); (c) (01002/31/31/65/60).

Hint

Solve πP=π with ∑πi=1. A finite chain always has at least one invariant distribution; all three here are irreducible, so it's unique.

Solution

(a) 0.3π1=0.4π2, so π=(4/7,3/7).

(b) Each column sums to 1 (the matrix is doubly stochastic), so the uniform π=(1/3,1/3,1/3) is invariant.

(c) The equations give π1=16π3 and π3=13π2. So π∝(1,18,6): π=(0.04,0.72,0.24).

Exercise 10.23Entropy rates

Compute the entropy rates h=∑iπiH(Pi⋅) of the stationary chains in Exercise 10.14.

Hint

Weight the entropy of each row by the invariant probability of that state.

Solution

(a) h=47Hb(0.3)+37Hb(0.4)≈47(0.881)+37(0.971)≈0.920 bits.

(b) Row entropies 1.5, ≈1.406, ≈1.561; averaged uniformly, h≈1.489 bits.

(c) Row entropies 0, Hb(1/3)≈0.918, Hb(1/6)≈0.650. So h≈0.72(0.918)+0.24(0.650)≈0.817 bits.

Exercise 10.24Bounds on the entropy rate

For a stationary Markov chain on N states, show 0≤h(X)≤log⁡N. When does equality hold?

Hint

h=∑iπiH(Pi⋅) is an average of entropies of distributions on N points.

Solution

Each H(Pi⋅) lies in [0,log⁡N], and the πi are weights summing to 1, so h∈[0,log⁡N].

h=0 iff every row with πi>0 is deterministic (the chain moves deterministically from every state it visits). h=log⁡N iff every row with πi>0 is uniform; for an irreducible chain this means Pij=1/N for all i,j, i.e. i.i.d. uniform symbols.