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

◆ integrate_1d_gauss_kronrod() [1/2]

template<typename F , typename T_a , typename T_b , typename... Args, require_any_st_fvar< T_a, T_b, Args... > * = nullptr>
return_type_t< T_a, T_b, Args... > stan::math::integrate_1d_gauss_kronrod ( const F &  f,
const T_a &  a,
const T_b &  b,
std::ostream *  msgs,
const Args &...  args 
)
inline

Return the integral of f from a to b using adaptive Gauss-Kronrod (G21,K21) quadrature, with tangents computed via finite differences over the integrand parameters.

Compute the integral of the single variable function f from a to b using adaptive Gauss-Kronrod (G21,K21) quadrature.

Template Parameters
FType of f
T_atype of first limit
T_btype of second limit
Argstypes of parameter pack arguments
Parameters
fthe functor to integrate
alower limit of integration
bupper limit of integration
[in,out]msgsthe print stream for warning messages
argsadditional arguments to pass to f
Returns
numeric integral of function f

a and b can be finite or infinite.

f should be compatible with reverse mode autodiff and have the signature: var f(double x, double xc, std::ostream* msgs, Args... args...);

It should return the value of the function evaluated at x. Any errors should be printed to the msgs stream. xc is unused (always NaN) here.

The integration algorithm terminates when the Boost estimate of the quadrature error satisfies error <= max(relative_tolerance * L1, absolute_tolerance) where L1 is the Boost estimate of the L1 norm of the integral.

Gradients of f that evaluate to NaN when the function evaluates to zero are set to zero themselves. This is due to the autodiff easily overflowing to NaN when evaluating gradients near the maximum and minimum floating point values (where the function should be zero anyway for the integral to exist).

Template Parameters
FType of f
T_atype of first limit
T_btype of second limit
Argstypes of parameter pack arguments
Parameters
fthe functor to integrate
alower limit of integration
bupper limit of integration
[in,out]msgsthe print stream for warning messages
argsadditional arguments to pass to f
Returns
numeric integral of function f

Definition at line 85 of file integrate_1d_gauss_kronrod.hpp.