Hello PyMC3 community.
I’m trying to build a model based on a multimodal disribution.
I have the following code, but am not sure that it’s correct:
- The way I’m specifying priors is using the .dist syntax, which makes me think it’s not stochastic.
- If I plot the prior predictive and posterior predictive samples, they are not very different from each other.
import numpy as np
import pymc3 as pm
import matplotlib.pyplot as plt
W = np.array([0.5, 0.5, 0.5])
data = np.array([1.73, 1.59, 1.64, 1.58])
with pm.Model() as model_mix:
# Mixing variable
w = pm.Dirichlet('w', np.ones_like(W))
dist1 = pm.Normal.dist(mu = 1.72, sigma = 0.01)
dist2 = pm.Normal.dist(mu = 1.78, sigma = 0.01)
dist3 = pm.StudentT.dist(mu = 1.88, sigma = 0.01, nu = 5)
like = pm.Mixture('like', w=w, comp_dists=[dist1, dist2, dist3], observed=data)
trace = pm.sample(2000, tune = 8000, cores=1)
params_prior_mix = pm.sample_prior_predictive(model = model_mix, samples = 2000)
params_pred_mix = pm.sample_posterior_predictive(trace, 1000, model_mix)
predictions_vec_mix = params_pred_mix['like'].reshape(4000)
plt.hist(np.random.choice(predictions_vec_mix, 1000), label='Posterior', color='r')
plt.hist(params_prior_mix['like'][:,0], label='Prior')
plt.hist(data, color='pink', label='Measured Distribution')
plt.legend()
Do I need to model the distributions of the parameters of dist1, dist2, dist3 in order to correctly specify the priors?