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 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 · Данные: две монеты с и , prior , данные HHH.
Ожидаемые числа
| Quantity | Value | Tolerance |
|---|---|---|
| abs ≤ 1e-4 | ||
| 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")