Numerical Integrals

Inspired by the tanh-sinh stuff pointed out from Ben, I figured a way to abuse our ODE integrator to do indefinite integration. Essentially by transforming from -Inf - +Inf to 0 - 1 with the inv_logit function. Probably there are smarter transforms.

I also added a R version of the sinh-tanh integration scheme. This R version can be directly translated to Stan (vanilla Stan functions code). Performance won’t be great, but at least it runs…no idea if the integrator is faster or this scheme. The speed will depend on how clever one can take advantage of vectorization to avoid a large AD stack. The only drawback is no adaptive error control, so one would have to sample from the prior and fix m and beforehand, but that is doable I think.

Cheers,
Sebastian

integrate_ode.stan (481 Bytes)
integration.R (1.8 KB)