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

◆ integrate_1d_adjoint()

template<typename F , typename T_a , typename T_b , typename Integrator , typename... Args>
return_type_t< T_a, T_b, Args... > stan::math::internal::integrate_1d_adjoint ( const char *  function,
const F &  f,
const T_a &  a,
const T_b &  b,
Integrator &&  integrator,
std::ostream *  msgs,
const Args &...  args 
)
inline

Build the reverse-mode result of a one-dimensional adaptive quadrature.

The quadrature routine is supplied as a callable integrator so the three integrate_1d* variants (plain, double-exponential, Gauss-Kronrod) can share this body, differing only in which Boost routine and tolerances they bind. integrator is invoked as integrator(g) where g is an integrand with signature g(x, xc); it returns the scalar integral of g over [a, b].

The integral value is computed with an all-double integrand. Adjoints are then accumulated into the original var inputs:

  • endpoints contribute -f(a) and f(b) (skipped when infinite),
  • each var argument component contributes the integral of d f / d arg, obtained with nested reverse-mode autodiff.

Gradients of f that come back NaN at a point where f == 0 are set to zero. Any other NaN propagates into the component integral and is reported as a domain_error naming the (flattened) parameter index.

Template Parameters
FType of f
T_atype of first limit
T_btype of second limit
Integratorcallable (integrand) -> double
Argstypes of parameter pack arguments
Parameters
functionname of the calling function, used in error messages
fthe functor to integrate
alower limit of integration
bupper limit of integration
integratorbinds the quadrature routine and its tolerances
[in,out]msgsthe print stream for warning messages
argsadditional arguments to pass to f
Returns
numeric integral of function f

Definition at line 57 of file integrate_1d_adjoint.hpp.