PyMC3高斯混合模型

时间:2016-03-09 09:29:32

标签: python bayesian mcmc pymc3

我一直在关注PyMC3的高斯混合模型示例:https://github.com/pymc-devs/pymc3/blob/master/pymc3/examples/gaussian_mixture_model.ipynb 并且它使用人工数据集很好地工作。 enter image description here

我已经尝试过一个真实的数据集,并且我努力让它得到明智的结果: enter image description here

为了更好地适应,我应该考虑缩小/扩大/改变哪些参数?痕迹似乎很稳定。这是我的模型片段,我已经从示例中进行了调整:

model = pm.Model()
with model:
    # cluster sizes
    a = pm.constant(np.array([1., 1., 1.]))
    p = pm.Dirichlet('p', a=a, shape=k)
    # ensure all clusters have some points
    p_min_potential = pm.Potential('p_min_potential', tt.switch(tt.min(p) < .1, -np.inf, 0))


    # cluster centers
    means = pm.Normal('means', mu=[0, 1.5, 3], sd=1, shape=k)
    # break symmetry
    order_means_potential = pm.Potential('order_means_potential',
                                     tt.switch(means[1]-means[0] < 0, -np.inf, 0)
                                     + tt.switch(means[2]-means[1] < 0, -np.inf, 0))

    # measurement error
    sd = pm.Uniform('sd', lower=0, upper=2, shape=k)

    # latent cluster of each observation
    category = pm.Categorical('category', p=p, shape=ndata)

    # likelihood for each observed value
    points = pm.Normal('obs', mu=means[category], sd=sd[category], observed=data)

1 个答案:

答案 0 :(得分:2)

事实证明,这里有一篇关于这个主题的优秀博客文章: http://austinrochford.com/posts/2016-02-25-density-estimation-dpm.html