![]() |
Stan Math Library
5.3.0
Automatic Differentiation
|
|
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.
| F | Type of f |
| f | the function to be integrated |
| a | lower limit of integration (may be -infinity) |
| b | upper limit of integration (may be +infinity) |
| relative_tolerance | target relative tolerance passed to Boost quadrature |
| absolute_tolerance | absolute-error floor on the convergence test |
| max_depth | maximum recursive bisection depth passed to Boost quadrature |
Definition at line 73 of file integrate_1d_gauss_kronrod.hpp.