Multi-Modal normal distribution


I have a bimodal normal distribution that samples from the following distribution:

G = p * g1(x)  + (1 - p) g2(x)
g1(x) ~ Normal(mu1, sd=1)
g2(x) ~ Normal(mu2, sd=1)
p ~ Bernoulli(p=pp)
pp ~ beta(alpha=1, beta=1)

I am observing the G and I would like to find the g1, g2, and pp distributions.

I am using the following code but it doesn’t let me (obviously) to use the observed in Deterministic function:

with pm.Model() as rev_mmn:
    pp = pm.Beta('pp', alpha=1, beta=1)
    p = pm.Bernoulli('cc', p=pp)
    g_mus = pm.Uniform('g_mu', lower=-1, upper=10, shape=2)
    g1 = pm.Normal('g1', mu=g_mus[0], sd=1)
    g2 = pm.Normal('g2', mu=g_mus[1], sd=1)
    g_mu = pm.Deterministic('g', g1 * cc + g2 * (1 - cc), observed=G_)

I wonder if you guys have any suggestion.



The best way is to reformulate it as a mixture model. Have a look at the Gaussian mixture model example in the doc, you might find some inspiration.

1 Like