I would like to calculate the inverse CDF of a Variable in pymc. I would typically use norm.ppf
from Scipy, however within this function there are boolean operations and so I get the type error “Variables do not support boolean operations.”
I would normally get around this error by using aesara.ifelse
, however here I am dealing with boolean operations within the package norm.ppf
(which I believe is written in C or fortran).
Any ideas?
p.s., error can be replicated by simply running:
from scipy.stats import norm
import aesara
print(norm.ppf(0.5)) ## desired use of ppf (but with variable instead of float)
print(norm.ppf(aesara.tensor.as_tensor_variable(0.5))) ## fails
with error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Input In [4], in <cell line: 1>()
----> 1 norm.ppf(aesara.tensor.as_tensor_variable(0.5))
File c:\Users\spearing\AppData\Local\Continuum\anaconda3\envs\pymc4_env\lib\site-packages\scipy\stats\_distn_infrastructure.py:2156, in rv_continuous.ppf(self, q, *args, **kwds)
2154 _a, _b = self._get_support(*args)
2155 cond0 = self._argcheck(*args) & (scale > 0) & (loc == loc)
-> 2156 cond1 = (0 < q) & (q < 1)
2157 cond2 = cond0 & (q == 0)
2158 cond3 = cond0 & (q == 1)
File c:\Users\spearing\AppData\Local\Continuum\anaconda3\envs\pymc4_env\lib\site-packages\aesara\tensor\var.py:71, in _tensor_py_operators.__bool__(self)
69 return True
70 else:
---> 71 raise TypeError("Variables do not support boolean operations.")
TypeError: Variables do not support boolean operations.