Issue with DiscreteUniform distribution

Hi,

I have a weird error coming up while using DiscreteUniform distribution. My belief was that declaring a random variable with DiscreteUniform(lower=0, upper=n-1) distribution or with Categorical(p=[1/n, …, 1/n]) distribution will produce exactly the same result.

However, while model1 (specified below) has the expected behaviour, model2 (also specified below) produces errors at sampling (an index out of bound which seems to come from the declaration of mu).

model1 = pm.Model()

with model1:
   X = pm.Categorical('X', p=[1/2, 1/2])
   t = T.as_tensor_variable([1, 2])

   mu = t[X]

   Y = pm.Normal('Y', mu=mu, sd=0.01, observed=2) 

model2 = pm.Model()

with model2:
   X = pm.DiscreteUniform('X', lower=0, upper=1)
   t = T.as_tensor_variable([1, 2])

   mu = t[X]

   Y = pm.Normal('Y', mu=mu, sd=0.01, observed=2)

Have I missed something in the definition of Categorical and DiscreteUniform distributions or should I open an issue on Github ? Thanks in advance !

I use PyMC3 (v3.2) and Theano (v1.0.1) with Python 3.6.4 on Mac OS X.

I think this is a bug (I remembered seen it before but cant seems to find it in Github issue). It would be great if you can open an issue for this :slight_smile:

Thank you for answering so quickly ! I am going to open an issue right now.

Just to explain it further: the default Proposal distribution, in this case, is not good: it makes proposal outside of the supported range. Usually, in Metropoli it is not a big deal because the proposal is just get rejected. However, in this case because it propagates to the next logp evaluation in Normal, where it is trying to index to t, which cause the error.

1 Like