# Logcdf for T distribution throws an error

It was a quiet Thursday night so I decided to work on a simple problem with a censored T distribution and one hour later I found myself in the bowels of dist_math.py As far as I can tell, I’ve found a bug - everything here works until the last line:

n = pm.Normal.dist(mu=0, sigma=1)
n.logp(np.random.normal(size=2000)).eval()
n.logcdf(np.random.normal(size=2000)).eval()
t = pm.StudentT.dist(mu=0, sigma=1, nu=5)
t.logp(np.random.normal(size=2000)).eval()
t.logcdf(np.random.normal(size=2000)).eval()  # throws an error

which throws this error:

2040         sqrt_t2_nu = tt.sqrt(t**2 + nu)
2041         x = (t + sqrt_t2_nu)/(2.0 * sqrt_t2_nu)
-> 2042         return tt.log(incomplete_beta(nu/2., nu/2., x))
2043
2044

~/.virtualenvs/leftfoot/lib/python3.6/site-packages/pymc3/distributions/dist_math.py in incomplete_beta(a, b, value)
499     w = one - value
500
--> 501     ps = incomplete_beta_ps(a, b, value)
502
503     flip = tt.gt(value, (a / (a + b)))

~/.virtualenvs/leftfoot/lib/python3.6/site-packages/pymc3/distributions/dist_math.py in incomplete_beta_ps(a, b, value)
476             e for e in
477             tt.cast((t, s),
--> 478                     'float64')
479         ]
480     )

~/.virtualenvs/leftfoot/lib/python3.6/site-packages/theano/tensor/basic.py in cast(x, dtype)
1257         dtype = config.floatX
1258
-> 1259     _x = as_tensor_variable(x)
1260     if _x.type.dtype == dtype:
1261         return _x

~/.virtualenvs/leftfoot/lib/python3.6/site-packages/theano/tensor/basic.py in as_tensor_variable(x, name, ndim)
198         except Exception:
199             str_x = repr(x)
--> 200         raise AsTensorError("Cannot convert %s to TensorType" % str_x, type(x))
201
202 # this has a different name, because _as_tensor_variable is the

AsTensorError: ('Cannot convert (Elemwise{mul,no_inplace}.0, TensorConstant{0.0}) to TensorType', <class 'tuple'>)

Is there an easy way to fix this, or a way to define a censored T likelihood without using logcdf?
Thanks,
Dan

I am having a similar issue. It seems that only scalar is not accepted by logcdf(). I am using 3.11.4.

TypeError: StudentT.logcdf expects a scalar value but received a 1-dimensional object.

Any help would be highly appreciated!

That’s a known limitation of the logcdf beta of the StudentT. In the next major release of PyMC (v4.0) we have replaced it by a new method that can handle vectors (and performs better overall).

1 Like