Strange error with Categorical distribution

I’m getting a very strange error with a simple model with two categorical distributions, where one is conditioned to the other:

import pymc3 as pm
import theano

probs_X = theano.shared(np.array([0.5, 0.5]))
probs_Y = theano.shared(np.array([[0.33, 0.33,0.34], [0.25, 0.25, 0.5]]))

values_X = np.array([0,1])
with pm.Model() as model:
    X = pm.Categorical("X", p=probs_X, observed=values_X) 
    Y = pm.Categorical("Y", p=probs_Y[X])
    print(model.check_test_point())

which leads to an infinite log-probability:

Y        -inf
X   -1.390000
Name: Log-probability of test_point, dtype: float64

Any idea where the problem could come from? I’m using the latest version of the PyMC3 code on the github repository.

Hmmm I think there is some weird error in the default value, could you raise an issue on Github?
For now, you can make it work by specifying the shape and give it a test value:

In [17]: values_X = np.array([0,1,1])
    ...: with pm.Model() as model:
    ...:     X = pm.Categorical("X", p=probs_X, observed=values_X) 
    ...:     Y = pm.Categorical("Y", p=probs_Y[X], shape=3,testval=np.asarray([0
    ...: ,1,2]))
    ...:     print(model.check_test_point())
    ...:     
Y   -3.19
X   -2.08

OK, done! You are right that the problem disappears is the test value is changed. But I really don’t get why the default value of the Y variable turns out to be 5 in this case. I checked the code, and it seems to come from the tag.test_value attribute of the mode tensor variable from Theano. How is that computed?

Don’t remember exactly, but definitely a bug there.