Maybe you can try using this integral directly? eg: Custom theano Op to do numerical integration - #6 by aseyboldt