End matter
Problems & solutions
Four problems from each lesson. Open a solution only after you have a number, a set, or a proof of your own. Drill, think, and prove are labelled.
I. Sample Spaces
1.1A fair die, twicedrillTwo fair distinguishable dice are rolled. Let A be the event that at least one six appears, and B the event that the sum is even. Compute |Ω|, |A|, |B|, and |A ∩ B|. Hence find P(A), P(B), and P(A ∩ B).
Reveal solution
Solution
Ω has 36 outcomes. A is the first-six row, the second-six column, minus the double-six: 6+6−1=11, so |A|=11. Sums are even when both even or both odd: 3×3+3×3=18, so |B|=18. A ∩ B: among the 11 outcomes with a six, those with even sum are those whose other face is even (the six is even). If the first is 6, second ∈ {2,4,6}; if the second is 6 and the first is not (to avoid double-counting 6,6), first ∈ {2,4}. That is 3+2=5. Thus P(A)=11/36, P(B)=1/2, P(A∩B)=5/36.
1.2Two aces in fivedrillA five-card hand is dealt from a 52-card deck. Write P(exactly two aces) as a ratio of binomial coefficients, and evaluate it to three decimal places.
Reveal solution
Solution
P = C(4,2)C(48,3)/C(52,5). C(4,2)=6, C(48,3)=17,296, C(52,5)=2,598,960, so 6×17296/2598960 = 103776/2598960 ≈ 0.040.
1.3The boy-girl sample spacethinkFamilies with two children are modelled as {BB, BG, GB, GG}, equally likely. (a) Given at least one boy, what is P(two boys)? (b) Given that the older child is a boy, what is P(two boys)? (c) Why did the answers differ?
Reveal solution
Solution
(a) Conditioning on {BB, BG, GB} leaves three equally likely outcomes, one of which is BB, so 1/3. (b) Conditioning on {BB, BG} (older-first notation) leaves two outcomes, so 1/2. (c) The information specified different subsets of Ω. “At least one” is not a named child; “the older” is. Always write the set before the ratio.
1.4A biased coin as a counter-examplethinkA coin has P(H)=2/3. Explain, in one paragraph, why the classical rule P(A)=|A|/|Ω| on Ω={H,T} is the wrong model, and write the correct P on the same Ω.
Reveal solution
Solution
The two outcomes are not interchangeable: the coin’s construction (or a long frequency) distinguishes them. Classical counting would force 1/2. The right assignment is P({H})=2/3, P({T})=1/3, P(Ω)=1, P(∅)=0. Same sample space, different weights.
II. Events and Axioms
2.1Complement of a uniondrillProve that P(A ∪ B) = 1 − P(Aᶜ ∩ Bᶜ) using only the axioms and De Morgan.
Reveal solution
Solution
De Morgan: (A ∪ B)ᶜ = Aᶜ ∩ Bᶜ. Complements: P(A ∪ B) = 1 − P((A ∪ B)ᶜ) = 1 − P(Aᶜ ∩ Bᶜ).
2.2Inclusion-exclusion numericallydrillP(A)=0.6, P(B)=0.5, P(A ∩ B)=0.3. Find P(A ∪ B), P(Aᶜ), and P(A ∩ Bᶜ).
Reveal solution
Solution
P(A ∪ B)=0.6+0.5−0.3=0.8. P(Aᶜ)=0.4. P(A ∩ Bᶜ)=P(A)−P(A ∩ B)=0.3.
2.3A boundproveShow that P(A ∪ B ∪ C) ≤ P(A)+P(B)+P(C). When does equality hold?
Reveal solution
Solution
By inclusion-exclusion, the union is the sum of singles minus pairwise intersections plus the triple. Dropping the (non-negative, once regrouped) intersection corrections yields the inequality; more elementarily, A ∪ B ∪ C is covered by A, B, C so subadditivity of P (itself from additivity plus monotonicity of the leftovers) gives the bound. Equality holds when the three events are pairwise disjoint.
2.4Disjoint versus independent, in numbersthinkGive an example of two events on a fair die with P(A),P(B)>0 that are disjoint, and compute P(A)P(B) versus P(A ∩ B). Conclude they are not independent.
Reveal solution
Solution
A={1,2}, B={3,4}. Intersection empty, so P(A ∩ B)=0, while P(A)P(B)=(1/3)(1/3)=1/9 ≠ 0. Disjoint positive-probability events are dependent: each announces that the other failed.
III. Conditional Probability
3.1Even, then greater than fourdrillA fair die is rolled. Find P(X>4 | X even) by restricting the sample space, and again from the definition.
Reveal solution
Solution
Even faces {2,4,6}; those >4: {6}; so 1/3. Definition: P({6})/P({2,4,6})=(1/6)/(1/2)=1/3.
3.2Aces without replacementdrillTwo cards from 52, no replacement. Compute P(second is an ace | first is an ace) and P(both aces).
Reveal solution
Solution
After an ace, 3 aces remain among 51 cards, so 3/51=1/17. Both aces: (4/52)(3/51)=1/221.
3.3Total probability, two urnsthinkUrn A has 2 red and 3 blue; urn B has 4 red and 1 blue. An urn is chosen by a fair coin, then a ball. Find P(red), then P(urn A | red).
Reveal solution
Solution
P(R)= (1/2)(2/5)+(1/2)(4/5)=3/5. P(A|R)=[(1/2)(2/5)]/(3/5)=1/3. The red-heavier urn B explains more of the reds.
3.4A chain of threeproveProve the chain rule P(A ∩ B ∩ C) = P(A) P(B|A) P(C|A ∩ B) when the conditionals exist.
Reveal solution
Solution
The right-hand side is P(A)·[P(A ∩ B)/P(A)]·[P(A ∩ B ∩ C)/P(A ∩ B)] = P(A ∩ B ∩ C), provided P(A)>0 and P(A ∩ B)>0.
3.5The Venn lensdrillOn a Venn diagram, P(A ∩ B)=0.12 and P(B)=0.40. What is P(A|B)? Which region of the diagram is 0.12, and why is it wrong to call that region P(A|B)?
Reveal solution
Solution
P(A|B)=0.12/0.40=0.30. The 0.12 is the lens A ∩ B, a slice of Ω. A conditional is a ratio: that lens divided by the whole of B. No single region is P(A|B).
3.6Red, then a heartthinkA well-shuffled card is drawn. Let H be ‘heart’ and R ‘red’. Compute P(H ∩ R) and P(H|R). Say, in one sentence, which number a Venn-lens guesser would report, and why it is the wrong question.
Reveal solution
Solution
Hearts are red, so H ⊂ R, H ∩ R = H, P(H ∩ R)=13/52=1/4. P(H|R)=(13/52)/(26/52)=1/2. The lens-guesser reports 1/4 (‘how often is it a heart-and-red?’). The question asked was ‘among red cards, how often a heart?’, which is 1/2. Restricting to the 26 red cards makes the 13 hearts half of the new world.
IV. Bayes' Theorem
4.1The clinic, different prevalencedrillRepeat the clinic calculation with prevalence 10%, true-positive rate 0.99, false-positive rate 0.05. Find P(D | T⁺) to two decimals.
Reveal solution
Solution
P(T⁺)=0.99·0.10+0.05·0.90=0.144. Posterior=0.099/0.144=0.6875 ≈ 0.69. Tenfold prevalence roughly fourfolds the posterior — priors matter.
4.2A tiny counting tabledrillIn a town of 1,000 people, 8 have a condition. A test is positive on all 8 who have it and on 48 who do not. A resident tests positive. Estimate P(condition | positive) by counting.
Reveal solution
Solution
Positive pile: 8+48=56. Of them 8 have the condition. 8/56=1/7 ≈ 0.14.
4.3Spamthink2% of mail is spam. The word “loan” appears in 40% of spam and 1% of ham. A message contains “loan”. Find P(spam | loan). What modelling assumption did you make about other words?
Reveal solution
Solution
P(loan)=0.40·0.02+0.01·0.98=0.0178. Posterior=0.008/0.0178≈0.45. You treated the appearance of this one word as the whole data — a one-feature naïve Bayes. Other words would multiply extra likelihood factors if assumed independent given the label.
4.4MAP with two hypothesesthinkHypotheses H0, H1 with priors 0.8 and 0.2. Data with P(x|H0)=0.1 and P(x|H1)=0.6. Which hypothesis is MAP? Which would MLE pick?
Reveal solution
Solution
Posterior scores: 0.1·0.8=0.08 versus 0.6·0.2=0.12, so MAP is H1. MLE looks only at 0.1 vs 0.6 and also picks H1. If the likelihoods were 0.1 and 0.3, MLE would still pick H1 (0.3>0.1) while MAP would pick H0 (0.08>0.06).
4.5Name the piecesdrillA friend says: “Before I opened the inbox I thought only 2% of mail was spam. This message contains the word ‘loan’, which I see in 40% of spam and 1% of ordinary mail. I’m now about 45% sure it’s spam.” Identify the hypothesis, prior, data, likelihoods, and posterior. Which number is P(data)?
Reveal solution
Solution
Hypotheses: spam vs ham. Prior of spam: 0.02. Data: the word ‘loan’ appears. Likelihoods: P(loan|spam)=0.40, P(loan|ham)=0.01. Posterior of spam: ≈0.45. The missing piece is P(loan)=0.40·0.02+0.01·0.98=0.0178, the marginal of the data (sometimes called ‘the evidence’). 0.45 is not a likelihood.
4.6Empty hookdrillKeys are in the kitchen with prior 0.7, otherwise the hallway. An empty kitchen hook has likelihood 0.10 if they are in the kitchen and 1 if they are in the hallway. The hook is empty. Compute the posterior that they are in the kitchen, and say in one sentence what each of 0.7, 0.10, and 1 is called.
Reveal solution
Solution
P(kitchen|empty)= (0.10·0.7)/(0.10·0.7+1·0.3)=0.07/0.37≈0.19. 0.7 is the prior, 0.10 is the likelihood of the data given kitchen, 1 is the likelihood of the data given hallway. The empty hook is the data, not a probability.
4.7The two meanings of evidencethinkIn one paragraph, distinguish ‘evidence’ as ordinary English (the clue) from ‘evidence’ as P(data) in Bayesian jargon. Then, in the clinic of this chapter, name one object of each kind.
Reveal solution
Solution
English evidence is the observation itself: the positive test, the witness, the dataset. Bayesian ‘evidence’ often means the marginal P(data), which is a probability that normalises the posterior. In the clinic the positive test T⁺ is evidence-in-English; P(T⁺)=0.0594 is evidence-in-jargon. Mixing the two is why people say ‘the evidence is 0.99’ when they mean the likelihood.
4.8A second lookthinkAfter the empty-hook observation the posterior that the keys are in the kitchen is 0.19. You look a second time, independently given their location, and the hook is still empty, with the same likelihoods 0.10 and 1. Update again. What was the prior for this second step?
Reveal solution
Solution
The prior for the second look is 0.19, yesterday’s posterior. P(kitchen|empty, empty)=(0.10·0.19)/(0.10·0.19+1·0.81)=0.019/0.829≈0.023. Two empty looks all but rule the kitchen out. Sequential Bayes is the same theorem; the word ‘prior’ just means ‘belief before this clue’, not ‘belief before any clue ever’.
V. Independence
5.1Two coinsdrillTwo fair coins. A = first heads, B = second heads, C = faces agree. Check independence of (A,B), (A,C), and of the triple (A,B,C).
Reveal solution
Solution
P(A∩B)=1/4=P(A)P(B). P(A∩C)=P(HH)=1/4=P(A)P(C). Pairwise A,B,C: also P(B∩C)=1/4. But P(A∩B∩C)=P(HH)=1/4 ≠ 1/8 = P(A)P(B)P(C). Pairwise independent, not mutually.
5.2ComplementsproveIf A and B are independent, prove that A and Bᶜ are independent.
Reveal solution
Solution
P(A ∩ Bᶜ)=P(A)−P(A ∩ B)=P(A)−P(A)P(B)=P(A)(1−P(B))=P(A)P(Bᶜ).
5.3Naïve Bayes for two bitsthinkLabel Y ∈ {0,1} fair. Given Y=1, features X1,X2 are i.i.d. Bernoulli(0.8); given Y=0, i.i.d. Bernoulli(0.3). Observe (1,1). Compute P(Y=1 | X=(1,1)) under the model.
Reveal solution
Solution
P(X=(1,1)|Y=1)=0.64, P(X=(1,1)|Y=0)=0.09. Posterior ∝ 0.64·0.5 versus 0.09·0.5, so 0.64/0.73 ≈ 0.877.
5.4A dependent pair with product means?thinkOn a fair die let A={1,2,3} and B={3,4,5}. Are they independent? Compute both sides of the product rule.
Reveal solution
Solution
P(A)=1/2, P(B)=1/2, P(A∩B)=P({3})=1/6 ≠ 1/4. Dependent. Overlapping the centre point correlates them.
VI. Random Variables
6.1Sum of two dice, pmfdrillLet X be the sum of two fair dice. Tabulate p_X(k) for k=2,…,12, and find F_X(4).
Reveal solution
Solution
Masses (in 36ths): 1,2,3,4,5,6,5,4,3,2,1 for k=2..12. F_X(4)=P(X≤4)=(1+2+3)/36=6/36=1/6.
6.2A function of a diedrillX is a fair die. Let Y = (X−3.5)². List the possible values of Y and their probabilities.
Reveal solution
Solution
Values: (1−3.5)²=6.25 with P=1/6 (from 1 and, wait: 1 and 6 both give 6.25, 2 and 5 give 2.25, 3 and 4 give 0.25). So 6.25 with 1/3, 2.25 with 1/3, 0.25 with 1/3.
6.3Same distribution, different experimentsthinkGive two genuinely different experiments whose random variables both have the Bernoulli(1/2) distribution.
Reveal solution
Solution
A fair coin mapped H↦1,T↦0; a fair die mapped even↦1, odd↦0. Different Ω, same push-forward on {0,1}.
6.4PreimagesproveLet X:Ω→ℝ. Show that {X ≤ a} ∪ {X > a} = Ω and that the two events are disjoint. What probability statement follows?
Reveal solution
Solution
Every real is either ≤ a or > a, never both, so the preimages partition Ω. Hence P(X≤a)+P(X>a)=1, i.e. F_X(a)+P(X>a)=1.
VII. Expectation and Variance
7.1Die mean and variancedrillFor a fair die X, compute E[X] and Var(X).
Reveal solution
Solution
E[X]=3.5. E[X²]=(1+4+9+16+25+36)/6=91/6. Var=91/6 − (7/2)² = 91/6 − 49/4 = (182−147)/12=35/12.
7.2Fixed pointsthinkUsing indicators, find the expected number of aces in a five-card hand. (Do not list hands.)
Reveal solution
Solution
Let I_j indicate that the j-th ace is in the hand, j=1..4. P(I_j=1)=C(51,4)/C(52,5)=5/52. E[sum]=4·5/52=5/13. Alternatively four indicators for positions in the hand: each card is an ace with chance 4/52, five cards, E=20/52=5/13. Same number.
7.3Linearity without independencethinkTwo cards without replacement. Let X be 1 if the first is an ace, Y if the second is an ace. Find E[X+Y]. Are X and Y independent?
Reveal solution
Solution
E[X]=4/52, E[Y]=4/52 by symmetry, so E[X+Y]=8/52=2/13. They are dependent: P(Y=1|X=1)=3/51 ≠ 4/52. Linearity did not ask.
7.4Chebyshev on a dieproveApply Chebyshev to a fair die to bound P(|X−3.5| ≥ 2.5). Compare with the exact probability.
Reveal solution
Solution
Var=35/12, so P≥2.5 ≤ (35/12)/6.25 = (35/12)/(25/4)= (35/12)·(4/25)=7/15≈0.467. Exact: |X−3.5|≥2.5 means X=1 or 6, probability 1/3≈0.333. The bound is true and slack.
7.5The die never shows 3.5drillA friend says ‘I expect the fair die to land on 3.5’. In two sentences, say what is wrong with the English, and what E[X]=3.5 actually claims. Then compute E[X] from the six equally likely faces to confirm the number.
Reveal solution
Solution
Expectation is not a prediction of a typical face; 3.5 is not on the die. E[X] is the balance point of six equal masses on {1,…,6}, equivalently the long-run average of many rolls. Sum of faces 21, divided by 6, is 3.5.
7.6A seesaw with a rare 10thinkP(X=1)=0.8, P(X=10)=0.2. Compute E[X] and the mode. Why do they differ? Using the same masses, compute E[X²] and Var(X).
Reveal solution
Solution
E[X]=1·0.8+10·0.2=2.8. The mode is 1, where most mass sits. The rare 10 has leverage: it pulls the fulcrum right of the crowd. E[X²]=1·0.8+100·0.2=20.8. Var=20.8−2.8²=20.8−7.84=12.96.
VIII. Discrete Families
8.1Binomial computationdrillX ~ Bin(5, 1/3). Compute P(X=2) as an exact fraction.
Reveal solution
Solution
C(5,2)(1/3)²(2/3)³ = 10 · 1/9 · 8/27 = 80/243.
8.2Geometric meandrillA bit succeeds with p=1/5 each independent try. Expected trials until (and including) the first success? Expected failures before it?
Reveal solution
Solution
E[trials]=1/p=5. Failures = trials−1, expectation 4. (This is the other geometric convention.)
8.3Poisson limitthinkA book of n=1000 pages has on average 2 typos per book, placed independently. Approximate the chance a given page is typo-free, two ways: binomial and Poisson.
Reveal solution
Solution
Per page p=2/1000=0.002. Binomial: (1−0.002)^1000 ≈ e^{-2} ≈ 0.1353. Poisson with λ=2: P(0)=e^{-2} same approximation. The Poisson is the limit the binomial is already hugging.
8.4Not binomialthinkCards are drawn without replacement until the first ace. Is the number of draws geometric? Why or why not?
Reveal solution
Solution
No. Geometric requires i.i.d. trials with constant p. Without replacement the chance of an ace on the next card changes (and the trials are dependent). The waiting time is a function of a hypergeometric-like process; it has a closed form P(X=k)= (48 choose k-1) ways to miss then hit, over permutations, but it is not geometric.
8.5Pick the familydrillFor each story, name the family (Bernoulli, binomial, geometric, Poisson, or hypergeometric) and the parameters if you can: (a) a fair die is ‘success’ on a six, rolled once; (b) the same die, number of sixes in 10 independent rolls; (c) rolls until the first six; (d) 5 cards from 52, number of aces; (e) typos on a page, about 0.3 per page.
Reveal solution
Solution
(a) Bernoulli p=1/6. (b) Binomial n=10, p=1/6. (c) Geometric p=1/6 on {1,2,…}. (d) Hypergeometric N=52, K=4, n=5 — without replacement. (e) Poisson λ=0.3, the rare-event counting model.
8.6Five cards, gold-ishthinkA 52-card deck, 4 aces. You are dealt 5 cards. Write P(exactly 2 aces) as a ratio of binomial coefficients, and find the expected number of aces without writing the full pmf.
Reveal solution
Solution
Hypergeometric: P(X=2)= C(4,2)C(48,3)/C(52,5). E[X]=5·4/52=5/13 by linearity (each card is an ace with chance 4/52).
IX. Continuous Chance
9.1Uniform intervaldrillX ~ Unif(0, 4). Find P(1 ≤ X ≤ 2.5) and P(X=2).
Reveal solution
Solution
Length 1.5 over length 4, so 3/8. P(X=2)=0 because a point has no length.
9.2Exponential memorydrillWaiting time X ~ Exp(λ=1/10) in minutes. Find P(X>10) and P(X>25 | X>15). Compare.
Reveal solution
Solution
P(X>t)=e^{-λt}. P(X>10)=e^{-1}≈0.368. P(X>25|X>15)=P(X>10)=e^{-1} by memorylessness. Same number.
9.3Standardising a normaldrillX ~ N(100, 15²). Express P(X ≥ 130) as a probability about a standard normal Z.
Reveal solution
Solution
P(X≥130)=P((X−100)/15 ≥ 2)=P(Z≥2)=1−Φ(2)≈1−0.977=0.023.
9.4A density checkproveLet f(x)=c x on [0,2] and 0 elsewhere. Find c so that f is a density, then E[X].
Reveal solution
Solution
∫_0^2 c x dx = c·2 =1 ⇒ c=1/2. E[X]=∫_0^2 x·(x/2) dx = (1/2)(8/3)=4/3.
9.5Height is not chancedrillX ~ Unif(0,1). The density equals 1 on [0,1]. Why is P(X=0.5) not 1? What is P(0.4 ≤ X ≤ 0.6), and which object — height or area — gave you the answer?
Reveal solution
Solution
A density’s height is not a probability. P(X=0.5)=0 because a point has no length. P(0.4≤X≤0.6)=0.2, the area (length) of the interval. Integrate, do not read off f(0.5).
9.6Which curve?thinkName the family: (a) a spinner equally likely anywhere on [0,1]; (b) the wait for the next bus, if buses have no memory; (c) the sum of many tiny independent measurement errors. For (c), write P(X>μ+2σ) as a statement about Z ~ N(0,1).
Reveal solution
Solution
(a) Uniform(0,1). (b) Exponential. (c) Normal, by the central-limit story. P(X>μ+2σ)=P(Z>2).
X. Joint Distributions
10.1A 2×2 jointdrillP(X=0,Y=0)=0.1, P(0,1)=0.3, P(1,0)=0.2, P(1,1)=0.4. Find the marginal of X and P(Y=1|X=1). Are X and Y independent?
Reveal solution
Solution
P(X=0)=0.4, P(X=1)=0.6. P(Y=1|X=1)=0.4/0.6=2/3. Independence would need 0.4=P(X=1)P(Y=1)=0.6·0.7=0.42, which is not 0.4. Dependent, slightly.
10.2Variance of a sumdrillVar(X)=4, Var(Y)=9, Cov(X,Y)=1. Find Var(X+Y) and Var(X−Y).
Reveal solution
Solution
Var(X+Y)=4+9+2=15. Var(X−Y)=4+9−2=11.
10.3Uncorrelated but dependentthinkLet X be uniform on {−1,0,1} (each 1/3) and Y=X². Show that Cov(X,Y)=0 but Y is a function of X.
Reveal solution
Solution
E[X]=0, E[XY]=E[X³]=0 because X³ is odd on a symmetric support (values −1,0,1). So Cov=0. But Y=X², so {Y=1}={X≠0}, complete dependence. Correlation saw no linear trend: Y is a U-shape in X.
10.4Ice creamthinkIn two sentences, why a large correlation between ice-cream sales and drowning does not justify banning ice cream, and what extra structure would justify a causal claim.
Reveal solution
Solution
A common cause (heat) can induce association without any mechanism from cones to casualties. A causal claim needs an intervention or a design that blocks the common cause — randomised assignment, an experiment, or a justified causal graph — not a covariance.
XI. Limit Theorems
11.1Variance of a meandrilli.i.d. Xi with Var=9. How large must n be so that Var(X̄_n) ≤ 0.01?
Reveal solution
Solution
9/n ≤ 0.01 ⇒ n ≥ 900.
11.2A CLT sketchdrillFair coins, n=100. Approximate P(S_100 ≥ 60) using the CLT with the continuity correction P(S≥59.5).
Reveal solution
Solution
E[S]=50, Var=25, sd=5. P(S≥59.5)≈P(Z≥(59.5−50)/5)=P(Z≥1.9)≈0.029.
11.3Gambler’s fallacythinkA fair coin has come up heads ten times. What does the LLN say about the 11th toss? What does it say about the average of the first n tosses as n→∞ including these ten?
Reveal solution
Solution
The 11th toss is still fair — independence. The average including the ten heads still converges to 1/2; the ten become negligible in the n-denominator. No compensatory tail is required.
11.4Empirical riskthinkA fixed classifier has error probability 0.1 on a random example. In 400 i.i.d. test points, the observed error rate is 0.13. Is this surprising under Chebyshev? (Use Var of a Bernoulli.)
Reveal solution
Solution
Bernoulli(0.1) has variance 0.09; mean of 400 has variance 0.09/400=0.000225, sd=0.015. Deviation 0.03 is 2 sd. Chebyshev: P(|dev|≥0.03)≤0.000225/0.0009=0.25. Not surprising by Chebyshev; a CLT estimate would call it about P(|Z|≥2)≈0.05, mildly unusual but not shocking.
XII. Likelihood and Models
12.1Bernoulli MLEdrilln i.i.d. Bernoulli(p) observations with k ones. Derive the MLE of p.
Reveal solution
Solution
ℓ(p)=k log p + (n−k) log(1−p). Derivative k/p − (n−k)/(1−p)=0 ⇒ k(1−p)=(n−k)p ⇒ p̂=k/n.
12.2Gaussian squared lossthinkIf Y | x ~ N(w·x, σ²) with σ known, show that maximising the likelihood in w is the same as minimising Σ (y_i − w·x_i)².
Reveal solution
Solution
Log-likelihood = const − (1/(2σ²)) Σ (y_i − w·x_i)². Maximising it is minimising the sum of squares. Least squares is Gaussian MLE.
12.3MAP as regularisationproveSuppose P(w) ∝ exp(−λ‖w‖²). Show that MAP for a likelihood L(w) is arg min[ −log L(w) + λ‖w‖² ].
Reveal solution
Solution
Posterior ∝ L(w) exp(−λ‖w‖²). Log posterior = log L − λ‖w‖² + const. Maximising is minimising −log L + λ‖w‖².
12.4A two-feature naïve BayesthinkBinary label Y with P(Y=1)=0.4. Two binary features, independent given Y, with P(Xj=1|Y=1)=0.7 and P(Xj=1|Y=0)=0.2 for j=1,2. Classify x=(1,0). Compute both posterior scores.
Reveal solution
Solution
P(x|Y=1)=0.7·0.3=0.21, times prior 0.4 → 0.084. P(x|Y=0)=0.2·0.8=0.16, times 0.6 → 0.096. Posterior odds favour Y=0. Predict 0. (Normalising: P(Y=1|x)=0.084/0.180=0.467.)
XIII. Entropy and Information
13.1Fair die entropydrillCompute H(X) in bits for a fair six-sided die.
Reveal solution
Solution
Uniform on 6 points: H=log2(6)=ln6/ln2≈2.585 bits. Equivalently −6·(1/6)log2(1/6)=log2 6.
13.2Bernoulli entropy at p=0.1drillCompute H(p) in bits for a Bernoulli(0.1) variable, to two decimals.
Reveal solution
Solution
H=−0.1 log2 0.1 − 0.9 log2 0.9. log2 0.1≈−3.322, log2 0.9≈−0.152. So 0.332+0.137=0.47 bits.
13.3KL and a wrong cointhinkTrue p=Bernoulli(0.8), model q=Bernoulli(0.5). Compute D_KL(p‖q) in bits. Interpret.
Reveal solution
Solution
D=0.8 log2(0.8/0.5)+0.2 log2(0.2/0.5)=0.8 log2(1.6)+0.2 log2(0.4)≈0.8·0.678+0.2·(−1.322)≈0.542−0.264=0.278 bits. Using a fair-coin code on a biased source wastes about 0.28 bits per toss.
13.4Cross-entropy splitsproveProve that H(p,q)=H(p)+D_KL(p‖q) from the definitions, for discrete p,q with the same support.
Reveal solution
Solution
H(p,q)=−∑ p log q. D_KL(p‖q)=∑ p log(p/q)=∑ p log p − ∑ p log q = −H(p)+H(p,q). Rearrange.
XIV. Estimation
14.1MSE of a constantdrillYou estimate a mean μ by the constant 0, ignoring the data. What are the bias, variance, and MSE?
Reveal solution
Solution
Bias=0−μ=−μ, variance=0, MSE=μ². A degenerate estimator: no variance, possibly huge bias.
14.2Unbiased sample variancethinkFor i.i.d. observations with variance σ², why does S²=∑(Xi−X̄)²/(n−1) use n−1 rather than n? Answer in terms of bias.
Reveal solution
Solution
The n-denominator version is the MLE for a Gaussian and is biased downward: E[∑(Xi−X̄)²]= (n−1)σ². Dividing by n−1 removes the bias. The cost is a slightly larger variance; for large n the two agree.
14.3Fisher information of N(μ,1)proveFor X~N(μ,1), show that I(μ)=1. What does the Cramér–Rao bound then say about unbiased estimators of μ from n i.i.d. samples?
Reveal solution
Solution
log p = −½(x−μ)² + const. Score ∂/∂μ = x−μ. I=E[(X−μ)²]=1. Bound: Var(θ̂)≥1/(nI)=1/n. The sample mean attains it.
14.4Why a test setthinkYou train 100 models and report the training accuracy of the winner. Why is this not an unbiased estimate of that winner’s true accuracy? What would be?
Reveal solution
Solution
The winner was selected by looking at the same data, so its empirical risk is biased downward (you maximised it). An unbiased estimate uses a held-out sample that did not participate in selection. Cross-validation is the same idea, recycled.
XV. Markov Chains
15.1Read the tabledrillWeather: P(sun→sun)=0.7, P(sun→rain)=0.3, P(rain→sun)=0.5, P(rain→rain)=0.5. Today is certainly rain. What is tomorrow’s distribution? The day after?
Reveal solution
Solution
Today π=(0,1). Tomorrow: (0.5, 0.5). Day after: 0.5·(0.7,0.3)+0.5·(0.5,0.5)=(0.60, 0.40).
15.2Rows sum to onedrillA proposed table has rows (0.4, 0.4) and (0.2, 0.9). Why can this not be a transition matrix? Fix the first row in the fairest way you can, keeping the second as (0.2, 0.8) after you notice it too.
Reveal solution
Solution
Rows must be conditional distributions, so they sum to 1. First row sums to 0.8; second to 1.1. A fair fix of the first is to renormalise: (0.5, 0.5). The second, already noticed, becomes (0.2, 0.8). (Any other repair is a modelling choice; the definition forbids the original table.)
15.3Stationary weatherthinkFor the weather in 15.1, solve π P = π with π_sun + π_rain = 1. Confirm that applying P to your answer returns the same row.
Reveal solution
Solution
π_sun·0.3 = π_rain·0.5 and π_rain=1−π_sun give 0.3π_sun=0.5−0.5π_sun, so 0.8π_sun=0.5, π_sun=5/8, π_rain=3/8. Check: (5/8)(0.7)+(3/8)(0.5)=7/16+3/16=10/16=5/8, and the rain slot is 3/8.
15.4The frogthinkPads A–B–C in a line. From A always to B, from C always to B, from B left or right with equal chance. Write the 3×3 table (rows from A, B, C). If the frog starts at A, where is it after one step, and after two?
Reveal solution
Solution
Rows: A: (0,1,0); B: (1/2,0,1/2); C: (0,1,0). Start (1,0,0). After one step: (0,1,0) — certainly B. After two: (1/2, 0, 1/2) — the ends, never B. The chain is periodic: even times on the ends, odd times in the middle. It still has a stationary row (1/4,1/2,1/4), but a single frog does not sit there at a fixed time.