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)