I am working through this example in the pymc3 docs: Marginalized Gaussian Mixture Model
W = np.array([0.35, 0.4, 0.25])
MU = np.array([0., 2., 5.])
SIGMA = np.array([0.5, 0.5, 1.])
component = np.random.choice(MU.size, size=N, p=W)
x = np.random.normal(MU[component], SIGMA[component], size=N)
x_shared = theano.shared(x)
with pm.Model() as model:
w = pm.Dirichlet('w', np.ones_like(W))
mu = pm.Normal('mu', 0., 10., shape=W.size)
tau = pm.Gamma('tau', 1., 1., shape=W.size)
x_obs = pm.NormalMixture('x_obs', w, mu, tau=tau, observed=x_shared)
Then I created new/holdout/test data and exchanged it into the shared Theano tensor.
x_shared.set_value(new_obs)
However, when I try to predict the w
, mu
and tau
for the new data, I get the error below.
with model:
ppc_trace = pm.sample_ppc(trace, vars = model.free_RVs, 5000, random_seed=SEED)
AttributeError: 'TransformedDistribution' object has no attribute 'random'
My investigation below showed that w
and tau
are the “TransformedDistributions”
vars = model.basic_RVs
for var in vars:
print(var)
print(var.distribution)