高斯混合物未聚合在pyMC3中

时间:2014-01-20 17:03:52

标签: python probability bayesian pymc

我有三位高斯的混合物,但无论我多大程度地调整先验,我都无法通过后面的方法摆脱先前的价值观。

k = 3

n1 = 1000
n2 = 1000
n3 = 1000

n = n1+n2+n3

mean1 = 17.3
mean2 = 42.0
mean3 = 31.0

precision = 0.1

sigma = np.sqrt(1 / precision)

print "Standard deviation: %s" % sigma

data1 = np.random.normal(mean1,sigma,n1)
data2 = np.random.normal(mean2,sigma,n2)
data3 = np.random.normal(mean3,sigma,n3)

data = np.concatenate([data1 , data2, data3])

hist(data, bins=200,  color="k", histtype="stepfilled", alpha=0.8)
plt.title("Histogram of the dataset")
plt.ylim([0, None])

with pm.Model() as model:
    dd = pm.Dirichlet('dd', a=np.array([float(n/k) for i in range(k)]), shape=k)
    sd = pm.Uniform('precs', lower=1, upper=5, shape=k)
    means = pm.Normal('means', [25, 30, 35], 0.01, shape=k)
    category = pm.Categorical('category', p=dd, shape=n)

    points = pm.Normal('obs',
                     means[category],
                     sd=sd[category],
                     observed=data)
    tr = pm.sample(100000, step=pm.Metropolis())
    pm.traceplot(tr, vars=['means', 'precs', 'dd'])

输出:

Standard deviation: 3.16227766017
 [-----------------100%-----------------] 100000 of 100000 complete in 157.2 sec

正如您所看到的那样,没有收敛,并且手段不会从其初始值移动 histogram of data traceplots not converging

1 个答案:

答案 0 :(得分:4)

不幸的是,这是一个已知问题:我们正在研究https://github.com/pymc-devs/pymc/issues/452https://github.com/pymc-devs/pymc/issues/443

请注意,您可以使用其他步骤方法作为问题中的示例模型中的分类。但即使这样也不会导致收敛。