Automatic Differentiation
 
Loading...
Searching...
No Matches

◆ integrate_gk()

template<typename F >
double stan::math::integrate_gk ( const F &  f,
double  a,
double  b,
double  relative_tolerance,
double  absolute_tolerance,
int  max_depth 
)
inline

Integrate a single variable function f from a to b using Boost's adaptive Gauss-Kronrod (G21,K21) quadrature, with QUADPACK-style mixed convergence criterion.

The integration succeeds (returns the Boost estimate Q) whenever error <= max(relative_tolerance * L1, absolute_tolerance) where error and L1 are Boost's quadrature-error and L1-norm estimates. A larger error throws std::domain_error.

Setting absolute_tolerance to a small positive value lets callers escape the pathological regime where the relative-tolerance test on its own is checking accumulated floating-point round-off against itself (this happens routinely in nested integrate_1d_gauss_kronrod calls when the outer integration probes the deep tail of the integrand and every inner evaluation sees an essentially-zero integrand). Setting it to zero (the default) reproduces the strict pure-relative-tolerance behaviour of integrate_1d.

The signature for f should be: double f(double x, double xc)

Unlike integrate_1d (which uses tanh_sinh/exp_sinh/sinh_sinh and computes a meaningful distance-to-boundary xc), Gauss-Kronrod does not produce xc, so this routine always passes xc == NaN to the user functor. User functors written for integrate_1d that rely on xc must be rewritten without it before being used here.

Boost's gauss_kronrod handles infinite limits internally via the usual change of variable; no special handling for integrals crossing zero is required.

Template Parameters
FType of f
Parameters
fthe function to be integrated
alower limit of integration (may be -infinity)
bupper limit of integration (may be +infinity)
relative_tolerancetarget relative tolerance passed to Boost quadrature
absolute_toleranceabsolute-error floor on the convergence test
max_depthmaximum recursive bisection depth passed to Boost quadrature
Returns
numeric integral of function f

Definition at line 73 of file integrate_1d_gauss_kronrod.hpp.