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.
Counting selections
Before probabilities come counts. Choosing
The idea
Applied to choosing
The third comes from the second: every unordered selection of
Explore
Worked example
A committee of 4 is chosen from 6 mathematicians and 5 physicists.
How many committees are possible with no restriction?
Order doesn't matter and nobody is chosen twice:
.How many have exactly two of each subject?
Choose the mathematicians, then the physicists, and multiply:
.How many contain at least one physicist?
Count the complement. The committees with no physicist are the
all-mathematician ones, so the answer is . (Adding up the cases "exactly 1, 2, 3, 4 physicists" gives too.)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):
. Or pick the chair (11), the secretary (10), then the other two members from the remaining nine: .
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?
That counts the balls as distinguishable: it records which ball went where. Here only how many balls each box gets matters. That forbids two balls in the same box. Boxes may hold several balls. That is an ordered selection without repeats.
In the explorer, set
- 6 blocks of 10The other way round. A block is one set of 3 objects; how many orders does such a set have?
- 10 blocks of 6
- 20 blocks of 3Three objects can be ordered in more than 3 ways.
Given
You used the recursion once. , and still has to be reduced. That is : one step too many.- It is undefined:
makes no sense.The factorial is only defined for integers, but the gamma function is defined for every .
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
A sum of squaresCounting one thing two ways
Show that
Hint
A group has
Solution
Choosing
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
Hint
Count the
Solution
A subset of size
Algebraically:
In Pascal's triangle row
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)
(b) Neither of the two goes:
(c) Choose the other six from nine:
Exercise 2.16Stars and bars
Show that the number of ways of putting
Hint
Line up the
Solution
A placement corresponds to a row of
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
Examples: the counting measure
, and implies . , since is the disjoint union of and .- If
partition , then .
Explore
Worked example
Use the counting measure on
Find
, , . , , .Find the sizes of all the intersections.
A number is in
exactly when it is a multiple of 6, so . Similarly (multiples of 10), (multiples of 15) and (just 30).How many numbers in
are divisible by at least one of 2, 3, 5?By inclusion–exclusion,
. Check: the numbers coprime to 30 are 1, 7, 11, 13, 17, 19, 23, 29, which is 8 numbers, and .How many are divisible by exactly one of them?
In the sum
, a number in exactly two sets is counted twice and the number in all three is counted three times. In the pairwise sum , a number in exactly two sets is counted once and the triple point three times. SoCheck directly: 15 multiples of 2, minus those also divisible by 3 or 5 (
) leaves 8; for 3 it is ; for 5 it is . Total .
Check your understanding
- Only
That assumes and don't overlap. Drag the discs on top of each other and watch . - Any value in
, so monotonicity forces . - Any value in
- Any value in
Inclusion–exclusion gives .
Which condition guarantees
- None; it always holds.Drag
so that it sticks out of , and compare with . and are disjoint.Then , so , not (unless ).
On the subsets of a finite set, define
- Yes: it is never negative.Non-negativity is only half of the definition. Check additivity on two disjoint one-point sets.
- 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.
- No: additivity fails.
Practice
Proving inclusion–exclusionFrom additivity alone
Using only additivity on disjoint sets, prove
Hint
Split
Solution
Write
A lower bound for an intersectionBonferroni's inequality
Show that
Solution
From inclusion–exclusion,
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
Hint
Write
Solution
(b)
(a) Symmetry is clear from either formula.
Exercise 3.10Inclusion–exclusion for three sets
For any measure
Hint
Apply the two-set formula
Solution
Exercise 3.16The law of total probability
Let
Hint
Check the two defining properties of a partition: disjoint, and union is everything.
Solution
For
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
The idea
For a diagnostic test,
Explore
Worked example
30% of the email reaching an inbox is spam. A filter flags 95% of spam, and also flags 2% of genuine email.
What fraction of all email gets flagged?
By total probability,
.A message is flagged. What is the probability it is spam?
About 1 flagged message in 21 is genuine.
A message is not flagged. What is the probability it is spam?
Are "spam" and "flagged" independent? What would independence mean for the filter?
No:
. 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 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
- 0.99That is
. The question asks for the reverse conditional probability. - 0.5Count the positives in 1000 people: about 1 true positive and about 10 false ones.
- About 0.09
- 0.001That is the prior. A positive result should raise it.
- Yes: they have nothing to do with each other.Disjoint does not mean unrelated: if
happens, you know for certain that did not. - No
- Only if
.Check the definition: would have to equal .
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?
- Use the posterior after the first test as the prior and apply Bayes again.
- Multiply the first posterior by the sensitivity.That gives
, not . You still have to divide by the probability of the second positive. - 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.
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
Pairwise is not enoughIndependence of three events
Toss two fair coins. Let
Solution
Each event has probability
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:
Solution
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
Hint
Each event has probability
Solution
Exercise 4.29A positive test for a rare disease
A test has
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
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.
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
Three laws that come up again and again:
- Binomial
: the number of successes in independent trials, ; mean , variance . - Poisson
: for ; mean and variance both . It is the limit of as : many trials, each rarely a success. - Geometric: the number of the trial on which the first success happens,
for ; mean , variance .
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
, the chance that the variable is at most . 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
Worked example
A batch contains 200 chips, each defective with probability 0.01 independently of the others. Let
What is the law of
? Find . , so .Approximate the same probability with a Poisson law. Which
?Match the means:
. Then , within about 1% of the exact value.Estimate
both ways.Use the complement. Exactly:
. Poisson: . They agree to four decimal places.Compare the variances. Why is the Poisson variance a little larger?
The binomial variance is
; the Poisson variance is . The factor is the only difference, and it tends to 1 as with fixed. That is the regime in which the Poisson approximation is good.
Check your understanding
Adding the two counts adds the numbers of trials, not the success probabilities. can be as large as 20.- It is not binomial.Think of
and as counting successes in two separate runs of independent trials.
In the simulator, the running mean wanders around
- 4That would be true of the variance of
, not its standard deviation. - 2
- 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.
- They are independent, because they are uncorrelated.Uncorrelated only says
. Compare with . - They are uncorrelated but not independent.
- They are correlated, since
is a function of .Compute .
Practice
Mean of the geometric lawDifferentiating a series
Show that if
Hint
Differentiate
Solution
Differentiating gives
Thinning a Poisson countTotal probability with random variables
The number of emails arriving in an hour is
Hint
Given
Solution
where
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
Hint
Compute
Solution
The joint law puts mass
But
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
Solution
(a)
(b)
(c) More than 11 good means at most 3 defective:
(d)
(e)
Exercise 5.36Poisson plus Poisson
If
Hint
Convolve, and recognise the binomial theorem.
Solution
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
The idea
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
away is at most the variance divided by . - 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
Worked example
A fair die is rolled 100 times. Estimate the probability that the total is at least 380.
Find the mean and variance of a single roll.
, and , so .Find the mean and standard deviation of the total
. and , so the standard deviation is about .Standardise and use the normal approximation.
takes whole-number values, so " " is the same as " " (a continuity correction). ThenThe exact value, from convolving the die's law 100 times, is 0.0420.
What does Chebyshev's inequality give? Why is it so much weaker?
, 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 is a sum of many independent pieces.
Check your understanding
- It is approximately
. - It is approximately
.Those are the mean and variance of one term. For a sum of independent terms, means add and variances add. - It is approximately uniform on
.Run the simulator with the uniform law and : the sum is already a triangle, not flat.
Can a probability density function take values bigger than 1?
- Yes
- No, because
is a probability. is a probability per unit length. Only its integrals are probabilities. - Only at finitely many points.The uniform density on
is 2 on the whole interval.
What is the entropy
bit- It can't be negative, so 0.That is true for discrete entropy, where each
. A density can exceed 1, which makes negative. - 1 bitCheck the sign:
and .
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
From uniform to exponentialThe distribution-function method
Let
Hint
Compute
Solution
For
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
Hint
Without more information, Chebyshev is the tool.
Solution
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
Solution
With the continuity correction,
Exercise 8.37Entropy of the exponential distribution
Find the entropy of
Hint
Solution
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
The general version. To sample a density
Why the budget is not optional. In a sampler the start
Explore
Worked example
A point with local conductance
How many trials does it take on average without a budget?
.What is the chance of failure with the budget?
, about one in six. The bound is close.How many trials are used on average with the budget?
: a little below 4, because the long runs are cut off at 6.How large must
be for failure probability at most ?Need
, i.e. , so . The bound asks for , a little more.
Check your understanding
Rejection sampling with a budget fails with probability
- Yes: given that some trial among the first
succeeds, the first successful trial is still a fresh proposal conditioned on landing in . - 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.
The start
- 2.That is
. The expected cost is , which is larger. - Infinite:
. .The integral diverges at 0.
In the figure, drag
is near 1 inside and tiny far outside. A larger spread helps a point just outside reach , but it also sends proposals from a point inside out of . is always about near the set.That holds only right at a flat piece of boundary; corners and thin parts change it.
Practice
The truncated meanCompute E min(G, N)
Show that
Outline
- For a nonnegative integer variable,
.Why?
; take expectations. for , and for .Why?
means the first trials all failed.- Sum the geometric series
.Why?
It equals
.
Exactness of the general methodAccept with probability p/(Mg)
Let
Outline
.Why?
Condition on the proposal
, then integrate over it.- Take
to get , then divide.Why?
.
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.
Random vectors and conditional densities
Two random quantities measured together have a joint density. Slicing it at
The idea
Explore
Worked example
A point
What is the joint density? Find
.The disc has area
, so inside it. For , the vertical line at meets the disc in an interval of length , so .Find the conditional density of
given . for : uniform on the chord. Its spread depends on .Compute
.The disc is symmetric under
, so and . Hence : uncorrelated.Are
and independent?No. At
, outside the disc, , but . Equivalently, the conditional law of changes with . (For the bivariate normal, by contrast, does give independence: set above and the slice matches for every .)
Check your understanding
The conditional mean is , not . Move the slice to and read off the peak. Knowing also narrows the spread of : the conditional variance is .
- Yes, because the density lives on a rectangle.A rectangular range is needed for independence, but not enough. The density itself must factor.
- No
- Yes, by symmetry in
and .Symmetry says and have the same law, not that they are independent.
What happens to
- It tends to infinity.
- It tends to 1 bit.1 bit is the most two binary variables can share. Continuous variables can share far more.
- It tends to 0.The variables become more strongly dependent, not less. Slide ρ toward 0.95.
Practice
A waiting-time pairMarginals and conditionals
Solution
Is more power worth it?The Gaussian channel
Using
Solution
At
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
Hint
Standardise to
Solution
The density of
If
Exercise 9.22Sums of independent normals
Show that if
Hint
Moment generating functions multiply for independent sums.
Solution
Exercise 9.27Entropy of the bivariate normal
Using
Hint
Solution
As
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
the average, under
Explore
Worked example
A particle moves on the states
Starting from 0, what is the law of
?It is the first row of
: .Find the invariant distribution.
Solve
. The first column gives , so ; by symmetry . With : . has all entries positive, so this is the limit from any start.Compute the entropy rate.
The rows have entropies 1, 1.5 and 1 bits. So
bits per step.Compare with
and interpret. 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
A large means the chain leaves 0 quickly, so it should spend less time there, not more. , by symmetryThe two states are only symmetric when .
Take
- Yes, to
Starting from 0, the chain is at 0 at every even time and at 1 at every odd time. Set both sliders to 1. - No, it alternates between 1 and 0, although
is invariant. - No, and there is no invariant distribution.Check
.
For a stationary Markov chain with invariant law
, and conditioning cannot increase entropy on average. Only when is independent of . Try .
Practice
A walk around a cycleDoubly stochastic matrices
A particle on the cycle
Solution
Every column of
A sticky chainEntropy rate of two states
Compute
Solution
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)
Hint
Solve
Solution
(a)
(b) Each column sums to
(c) The equations give
Exercise 10.23Entropy rates
Compute the entropy rates
Hint
Weight the entropy of each row by the invariant probability of that state.
Solution
(a)
(b) Row entropies
(c) Row entropies
Exercise 10.24Bounds on the entropy rate
For a stationary Markov chain on
Hint
Solution
Each