I’m getting strange behavior with a very simple model with a categorical likelihood. I expect that the issue is my lack of experience with this particular kind of model.
Here a minimal example that illustrates the problem:
import numpy as np
import pymc3 as pm
import theano.tensor as tt
import matplotlib.pyplot as plt
with pm.Model():
y = np.random.choice(4, 1000, p=[0.1, 0.2, 0.6, 0.1])
print(y)
probs = []
for k in range(4):
_p = pm.Beta(name='p%i' % k, alpha=1, beta=1)
probs.append(_p)
p = tt.stack(probs)
pm.Categorical(name='y', p=p, observed=y)
trace = pm.sample(draws=10000, tune=2000)
pm.traceplot(trace)
plt.savefig('traceplot.png')
I think this model should converge on the correct values of p, but it doesn’t: