结果M& M的PyMC实现中的差异

时间:2015-12-18 20:34:34

标签: python-2.7 bayesian pymc

此链接显示了M& M问题的PyMC解决方案: http://dataorigami.net/blogs/napkin-folding/29036419-bayesian-m-m-problem-in-pymc-2

为了尝试以稍微不同的方式解决问题,我使用了以下方法:

import pymc as pm


p = [
 #brown, yellow, red, green, orange, tan, blue
 [.3, .2, .2, .1, .1, .1, .0], # 1994 bag
 [.13, .14, .13, .2, .16, .0, .24]  # 1996 bag
]

theta = pm.DiscreteUniform('theta', lower=0, upper=1)

@pm.deterministic
def first_bag_selection(p=p, theta=theta):
    return p[theta]

@pm.deterministic
def second_bag_selection(p=p, theta=theta):
    return p[1-theta]

first_bag = pm.Categorical('first_bag', first_bag_selection, value=1, observed=True)
second_bag = pm.Categorical('second_bag', second_bag_selection, value=3, observed=True)

model = pm.MCMC([p, theta, first_bag_selection, second_bag_selection, first_bag, second_bag])
model.sample(10000, 1000, 10)
model.summary()
pm.Matplot.plot(model)

然而,训练后'theta'的平均值变为0.416,即 打印(model.trace( 'THETA')[:]意味着()) 0.416333333333

虽然链接的解决方案对选择旧包的后验概率提出了不同的答案。你能评论一下吗?

0 个答案:

没有答案