Skip to content
BIASED
Back to topic

Optional

Bayes: coin from two urns

Update P(urn|data) after a heads/tails sequence; match the table.

Version
v1
Minutes
~20
Evidence
Self-check in the notebook

Until platform auto-check exists, compare cell output with the expected numbers in the notebook. This is not a debt and does not affect mastery.

Download .ipynb

Download the notebook and run it locally. Its environment requirements are listed inside.

Notebook contents

Readable on your phone. The code below has not been executed in the browser; download the notebook to run it.

Prob · Байес: две урны / Bayes: two urns

Activity version: 1 · Seed: n/a · Данные: две монеты с P(H)=0.5P(H)=0.5 и P(H)=0.9P(H)=0.9, prior 1/21/2, данные HHH.

Ожидаемые числа
Quantity Value Tolerance
P(fair∣HHH)P(fair\mid HHH) 0.125/(0.125+0.729)≈0.14630.125/(0.125+0.729)\approx 0.1463 abs ≤ 1e-4
P(biased∣HHH)P(biased\mid HHH) ≈0.8537\approx 0.8537 abs ≤ 1e-4
Самопроверка в ноутбуке

Не влияет на mastery.

import numpy as np
 
prior = np.array([0.5, 0.5])  # fair, biased
lik = np.array([0.5**3, 0.9**3])
post = prior * lik
post /= post.sum()
print("post", post)
assert abs(post[0] - 0.125 / (0.125 + 0.729)) < 1e-4
assert abs(post[1] - 0.729 / (0.125 + 0.729)) < 1e-4
print("OK: Bayes coin update")
Самопроверка в ноутбуке
  • P(fair∣HHH)≈0.146P(fair\mid HHH)\approx 0.146
  • P(biased∣HHH)≈0.854P(biased\mid HHH)\approx 0.854