I’m trying to write a custom random variable, in which I need to do numerical integration with pymc RVs as parameter. An example is stated as below:
#define some pymc RVs
a1=pm.Normal(‘a1’,mu=0,sd=1)
a2=pm.Nromal(‘a2’,mu=0,sd=1)
#the function to be integrated
def f(x,p):
retrun tt.power(x,p[0]*p[1])
scipy.integrate.quad(f,0,1,args=[a1,a2])
However, quad would return an error since a1,a2 are not real number, and I can’t find something like a1.value() to get the current value of the random variable.
I don’t think you can use the integration from Scipy directly. You should try to find a closed-form solution to the integration (or an approximation) and rewrite it in theano.
You can have a look at PR #2688, where @domenzain is implementing logcdf for distribution. There are quite a lot of integration involved.
I’ve tried this integrateOut op but it doesn’t really work in my case, although it seems to be helpful in many other cases.
For the example in this integrateOut op: