Template Function utils::integrateScaled
Defined in File PDFIntegrator.hpp
Function Documentation
-
template<class F, GKOrder Order = GKOrder::GK15>
auto utils::integrateScaled(const pdfs::PDF &p, const F &f, const std::size_t nInt, const double a, const double b, const std::vector<double> &scalePoints, const std::size_t maxIter, const double absTol, const double relTol, const bool logTransform = false) -> std::vector<double> Integrate p(x) f(x) over [a, b], with f made dimensionless first.
For a vector-valued integrand whose elements span many orders of magnitude, and may include exact zeros, neither tolerance works alone: an element that integrates to (nearly) zero can never meet the relative tolerance, while an absolute tolerance in f’s own units is either meaningless for the small elements or (when the integral itself is much smaller than 1, e.g. over a narrow sub-range of p’s support) met by the first, unresolved estimate. So f is divided by integrandScale(f, scalePoints), its smallest nonzero element at those points, and integrated with absolute tolerance absTol times p’s own integral over [a, b] – the size of the integral of a unit-scale integrand – and the result is scaled back. With logTransform, that same tolerance still applies unchanged: PDFIntegrator includes the Jacobian x in its own integrand, so the integral it computes, and hence the size of a unit-scale integrand’s integral, is the same either way.
- Template Parameters:
F – A callable taking a double and returning a std::vector<double> of nInt values
Order – Gauss-Kronrod order, as for PDFIntegrator
- Parameters:
p – The PDF p(x) weighting the integrand
f – The integrand f(x)
nInt – The number of values f returns
a – Lower limit of integration
b – Upper limit of integration
scalePoints – Points at which to evaluate f to find its scale (see integrandScale())
maxIter – Maximum number of bisection iterations, as for PDFIntegrator
absTol – Absolute tolerance on the integral of the dimensionless integrand, per unit integral of p over [a, b] – typically SimControls::intAbsTol()
relTol – Relative tolerance, as for PDFIntegrator
logTransform – Whether to integrate in ln(x) rather than x, as for PDFIntegrator (which then requires a and b to be strictly positive); defaults to false
- Returns:
The integral of p(x) f(x) over [a, b], in f’s own units