Error for default params of NoneType in pm.distributions.distribution._draw_value()

I came across the following error when using pm.distributions.continuous.TruncatedNormal.dist().random().

ValueError: Unexpected type in draw_value: <class 'NoneType'>

The error seems to be caused by the default values of None for the upper and lower parameters of the BoundedContinuous distribution object. That is,

>>> dist = pm.TruncatedNormal.dist()
>>> type(dist.mu), dist.mu
(<class 'theano.tensor.var.TensorConstant'>, TensorConstant{0})
>>> type(dist.sd), dist.sd
(<class 'theano.tensor.var.TensorConstant'>, TensorConstant{1.0})
>>> type(dist.upper), dist.upper
(<class 'NoneType'>, None)
>>> type(dist.lower), dist.lower
(<class 'NoneType'>, None)
>>> dist.random()
ValueError: ...

If I give a value to just one of ‘upper’ or ‘lower’, the error persists. If I give values to both upper and lower, the error is avoided.

>>> dist.lower, dist.upper = 0, np.inf
>>> dist.random()
array(1.15514827)

Am I using the random() method in an unintended way? Perhaps it’s just required that the user supply upper and lower bounds to the respective kwargs in TruncatedNormal– in that case, it may be desirable to make those into positional arguments (matching scipy.stats.truncnorm).

(I’m using an Anaconda env with Python 3.6.6 and pymc3 3.5 py36_0)

Thanks for the detail post! This is likely a bug - could you please raise an issue on Github?

Thanks for your reply. I’ve raised issue #3248.

1 Like