PaC Exercise 1.10
Posted on February 18, 2021
import numpy as np
Exercise 1.10
I have a fair coin and a two-headed coin. I choose one of the two coins randomly with equal probability and flip it. Given that the flip was heads, what is the probability that I flipped the two-headed coin?
Solution: Let F denote picking the fair coin and T picking the two-headed coin, respectively. Furthermore, let H denote the event that the chosen coin shows head.
Then we have
$$
P(T | H) =
\frac{P(H \cap T)}{P(H)} =
\frac{P(H | T) \cdot P(H)}{P(T \cap H) + P(F \cap H)} =
\frac{P(H | T) \cdot P(H)}{P(H|T) \cdot P(T) + P(H|F) \cdot P(F)} =
\frac{1 \cdot \tfrac 1 2}{1 \cdot \tfrac 1 2 + \tfrac 1 2 \tfrac 1 2} =
\frac 2 3.
$$
We can check this by simulation.
= 100000
num_samples
= np.random.randint(low=0, high=2, size=num_samples) # 0 = fair, 1 = two-headed
chosen_coin = np.random.randint(low=0, high=2, size=num_samples) + chosen_coin > 0
heads
* heads).sum() / heads.sum() (chosen_coin
0.669433509041169