Stan Math Library
4.9.0
Automatic Differentiation
|
|
inline |
Compute the integral of the single variable function f from a to b to within a specified relative tolerance.
a and b can be finite or infinite.
T_a | type of first limit |
T_b | type of second limit |
T_theta | type of parameters |
T | Type of f |
f | the functor to integrate | |
a | lower limit of integration | |
b | upper limit of integration | |
theta | additional parameters to be passed to f | |
x_r | additional data to be passed to f | |
x_i | additional integer data to be passed to f | |
[in,out] | msgs | the print stream for warning messages |
relative_tolerance | relative tolerance passed to Boost quadrature |
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, const std::vector<var>& theta, const std::vector<double>& x_r, const std::vector<int> &x_i, std::ostream* msgs)
It should return the value of the function evaluated at x. Any errors should be printed to the msgs stream.
Integrals that cross zero are broken into two, and the separate integrals are each integrated to the given relative tolerance.
For integrals with finite limits, the xc argument is the distance to the nearest boundary. So for a > 0, b > 0, it will be a - x for x closer to a, and b - x for x closer to b. xc is computed in a way that avoids the precision loss of computing a - x or b - x manually. For integrals that cross zero, xc can take values a - x, -x, or b - x depending on which integration limit it is nearest.
If either limit is infinite, xc is set to NaN
The integration algorithm terminates when
\[ \frac{{|I_{n + 1} - I_n|}}{{|I|_{n + 1}}} < \text{relative tolerance} \]
where \(I_{n}\) is the nth estimate of the integral and \(|I|_{n}\) is the nth estimate of the norm of the integral.
Integrals that cross zero are split into two. In this case, each integral is separately integrated to the given relative_tolerance.
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)
T_a | type of first limit |
T_b | type of second limit |
T_theta | type of parameters |
T | Type of f |
f | the functor to integrate | |
a | lower limit of integration | |
b | upper limit of integration | |
theta | additional parameters to be passed to f | |
x_r | additional data to be passed to f | |
x_i | additional integer data to be passed to f | |
[in,out] | msgs | the print stream for warning messages |
relative_tolerance | relative tolerance passed to Boost quadrature |
Definition at line 91 of file integrate_1d.hpp.