I’m interested in using the CDF of the student t distribution as a function inside a model. I noticed that pm.StudentT
has a logcdf
method, so I grabbed the code and put it in a minimal example script:
import arviz as az
import numpy as np
import matplotlib.pyplot as plt
import pymc3 as pm
from pymc3.distributions.dist_math import incomplete_beta
from scipy.stats import t
import theano.tensor as tt
if __name__ == '__main__':
with pm.Model():
x = np.linspace(-8, 8)
p = t.cdf(x, 1.1)
y = np.random.binomial(40, p)
_x = tt.as_tensor_variable(x)
nu = pm.Exponential(name="nu", lam=1)
sqrt_t2_nu = tt.sqrt(_x ** 2 + nu)
__x = (_x + sqrt_t2_nu) / (2.0 * sqrt_t2_nu)
_p = incomplete_beta(nu / 2., nu / 2., __x) # <-- this line gives the error
pm.Binomial(name="yhat", n=40, p=_p, observed=y)
trace = pm.sample()
az.plot_trace(trace)
plt.show()
I get the following error:
Traceback (most recent call last):
File "/Users/samuelrobertmathias/miniconda3/envs/psychoacoustics/lib/python3.8/site-packages/theano/tensor/type.py", line 254, in dtype_specs
return {
KeyError: 'object'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/samuelrobertmathias/miniconda3/envs/psychoacoustics/lib/python3.8/site-packages/theano/tensor/basic.py", line 246, in constant
ttype = TensorType(dtype=x_.dtype, broadcastable=bcastable)
File "/Users/samuelrobertmathias/miniconda3/envs/psychoacoustics/lib/python3.8/site-packages/theano/tensor/type.py", line 51, in __init__
self.dtype_specs() # error checking is done there
File "/Users/samuelrobertmathias/miniconda3/envs/psychoacoustics/lib/python3.8/site-packages/theano/tensor/type.py", line 271, in dtype_specs
raise TypeError("Unsupported dtype for %s: %s"
TypeError: Unsupported dtype for TensorType: object
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/samuelrobertmathias/miniconda3/envs/psychoacoustics/lib/python3.8/site-packages/theano/tensor/basic.py", line 194, in as_tensor_variable
return constant(x, name=name, ndim=ndim)
File "/Users/samuelrobertmathias/miniconda3/envs/psychoacoustics/lib/python3.8/site-packages/theano/tensor/basic.py", line 266, in constant
raise TypeError("Could not convert %s to TensorType" % x, type(x))
TypeError: not all arguments converted during string formatting
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/samuelrobertmathias/PycharmProjects/TrialEffects/_test.py", line 23, in <module>
p = incomplete_beta(nu / 2., nu / 2., __x)
File "/Users/samuelrobertmathias/miniconda3/envs/psychoacoustics/lib/python3.8/site-packages/pymc3/distributions/dist_math.py", line 527, in incomplete_beta
ps = incomplete_beta_ps(a, b, value)
File "/Users/samuelrobertmathias/miniconda3/envs/psychoacoustics/lib/python3.8/site-packages/pymc3/distributions/dist_math.py", line 503, in incomplete_beta_ps
tt.cast((t, s),
File "/Users/samuelrobertmathias/miniconda3/envs/psychoacoustics/lib/python3.8/site-packages/theano/tensor/basic.py", line 1259, in cast
_x = as_tensor_variable(x)
File "/Users/samuelrobertmathias/miniconda3/envs/psychoacoustics/lib/python3.8/site-packages/theano/tensor/basic.py", line 200, in as_tensor_variable
raise AsTensorError("Cannot convert %s to TensorType" % str_x, type(x))
theano.tensor.var.AsTensorError: ('Cannot convert (Elemwise{mul,no_inplace}.0, TensorConstant{0.0}) to TensorType', <class 'tuple'>)
I’m failing to understand this error. Can anyone give me any pointers?