MultiNomial init error

I have some data r and want to run this Multinomial model, I get an initialisation error, although the prior predictive works.

T = 12, g = 3, I = 50

with pm.Model() as model:
  alpha = pm.Gamma('alpha', 1, 1, shape=g)
  M = pm.Gamma('M', 1, 1)
  K = pm.Gamma('K', 1, 1)
  mu = pm.Gamma('mu', M * T, K, shape=I)
  n = pm.Poisson('n', mu, shape=I)
  p = pm.Dirichlet('p', alpha, shape=(I, g))
  pred = pm.Multinomial('pred', n, p, shape=(I, g), observed=r)
  pp = pm.sample_prior_predictive()
  trace = pm.sample()

SamplingError: Initial evaluation of model at starting point failed!

When the sampling throws that error, it usually prints the test point. If not, you can print model.check_test_point(). If I had to guess, I would suspect that M and thus mu and thus n is too small relative to your data.

I think the problem is likely:

n = pm.Poisson('n', mu, shape=I)

Since you observed the multinomial, n is known n = r.sum(axis=-1). I guess you are assigning it as random variable so you can infer the parameter mu and its hyper priors. So suggestion here is to do
n = pm.Poisson('n', mu, observed=r.sum(axis=-1))

1 Like

Junpeng, you are right, it dawned on me later, n was actually given.