PyMC3 Gaussian Mixing Model
<p>I've been following the Gaussian mixture model example for PyMC3 here: <a href="https://github.com/pymc-devs/pymc3/blob/master/pymc3/examples/gaussian_mixture_model.ipynb" rel="noreferrer">https://github.com/pymc-devs/pymc3/blob/master/pymc3/examples/gaussian_mixture_model.ipynb</a>
and have got it working nicely with an artificial dataset.
<a href="https://i.stack.imgur.com/xBWUE.png" rel="noreferrer"><img src="https://i.stack.imgur.com/xBWUE.png" alt="enter image description here"></a></p>

<p>I've tried it with a real dataset, and the i'm struggling to get it to give sensible results :
<a href="https://i.stack.imgur.com/Yh5jf.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Yh5jf.png" alt="enter image description here"></a></p>

<p>Any ideas of which parameters I should be looking to narrow/widen/change in order to get a better fit? The traces seem to be stable. Here's a snippet of my model which I've adjusted from the example:</p>

<pre><code>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) &lt; .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] &lt; 0, -np.inf, 0)
                                     + tt.switch(means[2]-means[1] &lt; 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)
</code></pre>