Last active
June 28, 2019 09:39
-
-
Save aliakbars/bbb745016cc77c2ff928ddbcd5728711 to your computer and use it in GitHub Desktop.
PyMC3 approach to solve Bayesian coin flip example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pymc3 as pm | |
with pm.Model() as coinflip: | |
which_coin = pm.Bernoulli('which_coin', 0.5) | |
theta_biased = pm.Uniform('theta_biased', 0, 1) | |
p = pm.math.switch(which_coin > 0.5, 0.5, theta_biased) | |
heads = pm.Binomial('heads', n=2, p=p, observed=2) | |
coin_trace = pm.sample(5000, tune=2500) | |
pm.traceplot(coin_trace); | |
print('p(coin=fair|HH)={}'.format( | |
coin_trace['which_coin'].mean() | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment