Closed Fangwq closed 5 years ago
These sort of questions are better suited for our discourse channel.
You can't change the number of mixture components dynamically (which is what you are trying to do when you set K = x.get_value().shape
). When you later change x
with x.set_value(X_complete)
, the previous number of mixture components don't match, and thus mu = alpha + beta*x
wont work.
Thanks for your reply. You mention that I can't change the number of components. But when I set K = const initially, this problem still exits. Why does it happen ? @lucianopaz
K = 5
with pm.Model() as model:
# K = x.get_value().shape
# K = K[0]
phi = pm.Dirichlet('phi', np.array([1.0]*K), testval=np.ones(K)/K)
# Priors for unknown model parameters
alpha = pm.Normal('alpha', mu=0.5, sd=10, shape=K) #Intercept
beta = pm.Normal('beta', mu=0.5, sd=10, shape=K)
sigma = pm.HalfCauchy('sigma', 1.0, shape=K) #Noise
mu = alpha + beta*x
x_obs = pm.NormalMixture('obs', phi, mu, sd = sigma, observed=y)
I try to do regression with gaussian mixture model refer to https://docs.pymc.io/notebooks/dependent_density_regression.html and https://discourse.pymc.io/t/gaussian-mixture-of-regression/537. However, when I do prediction, it always give me the error below. It is definitely the problem that array size doesn't match when I draw the figure. Does anybody knows why? Thank you very much.
The code I use here:
The error here: