Adaptive quadrature (or similar) numerical integration within Stan

122 views
Skip to first unread message

Björn Holzhauer

unread,
Nov 3, 2016, 4:24:16 AM11/3/16
to Stan users mailing list

Dear all,

I am using a model with a likelihood that involves transformed parameters that are obtained via an integral, for which I do not have an analytic expression (the integral is of the form integral from 0 to t of exp(-(ax)^b-(cx)^d) * x^(b-1) dx, where a, b, c and d are all >0). I can e.g. numerically integrate this using a composite Simpson’s rule with a fixed number of terms and for my one particular integral it is pretty easy to remove any singularities and to turn this into a very nice straightforward problem. However, I cannot easily get any certainty about the quality of the numerical integral, because it is one of those cases where I have trouble to find the maximum of the fourth derivative over the plausible parameter values. Thus, even if I pick some large number of terms (e.g. 50), I am not entirely sure whether the integral approximation is all that good. Normally, one might just use an adaptive Simpson’s rule, but if I understand correctly how Stan works, a choice of the number of integral terms that is conditional on the values in successive iterations would lead to a problem with the automatic differentiation (which some suitably chosen fixed number of terms would not).

Is there some standard trick to deal with this (or a totally different approach that should work)?

Many thanks,
Björn

Sebastian Weber

unread,
Nov 3, 2016, 10:40:05 AM11/3/16
to Stan users mailing list
Hi!

Two solutions come to my mind:

1. Represent your integral as the solution to an ODE problem and you get a probably slow, but very good answer

2. Run your Stan model with 25 approximation terms for, let's say, 5 chains and run it for 5 more chains with 50 approximation terms. Then you ensure that Rhat across the 10 chains is OK for your quantities. If the answer is yes, then this answer should be fine.

Sebastian

Bob Carpenter

unread,
Nov 3, 2016, 4:17:11 PM11/3/16
to stan-...@googlegroups.com
Not yet. You can try to write your own quadrature algorithm,
which has sometimes worked. Basing termination of an algorithm
on parameter values isn't always a disaster.

We're going to be adding some numerical intergrators with
built-in derivatives soon (maybe next year?).

- Bob
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> To post to this group, send email to stan-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages