|
RandLib 2.0.0
Probability distributions, fitting, and heavy-tail tools for C++20
|
Beta-related functions. More...
Namespaces | |
| namespace | detail |
| namespace | portable |
Classes | |
| struct | IncompleteGamma |
| struct | MinimizeResult |
| The MinimizeResult struct Outcome of a multivariate minimization. More... | |
Functions | |
| template<std::floating_point Real> | |
| Real | logBeta (Real a, std::type_identity_t< Real > b) |
| Calculate logarithm of beta function. | |
| template<typename Left , typename Right > requires (std::is_arithmetic_v<Left> && std::is_arithmetic_v<Right> && (std::integral<Left> || std::integral<Right> || !std::same_as<Left, Right>)) | |
| auto | logBeta (Left a, Right b) -> std::common_type_t< double, Left, Right > |
| template<std::floating_point Real> | |
| Real | ibeta (Real x, std::type_identity_t< Real > a, std::type_identity_t< Real > b, std::type_identity_t< Real > logBetaFun, std::type_identity_t< Real > logX, std::type_identity_t< Real > log1mX) |
| Fast calculation of regularized beta function, using precalculated values. | |
| template<std::floating_point Real> | |
| Real | ibeta (Real x, std::type_identity_t< Real > a, std::type_identity_t< Real > b) |
| Calculate regularized beta function. | |
| template<std::floating_point Real> | |
| Real | ibetaPowerSeries1 (Real x, Real a, Real b, Real logBetaFun, Real logX, Real log1mX) |
| template<std::floating_point Real> | |
| Real | ibetacontinuedFraction1 (Real x, Real a, Real b, int number, Real logBetaFun, Real logX, Real log1mX) |
| template<std::floating_point Real> | |
| Real | ibetaPowerSeries2 (Real x, Real a, Real b, Real logBetaFun, Real logX, Real log1mX) |
| template<std::floating_point Real> | |
| Real | ibetaContinuedFraction2 (Real x, Real a, Real b, int number, Real logBetaFun, Real logX, Real log1mX) |
| template<std::floating_point Real> | |
| Real | ibetaContinuedFractionLentz (Real x, Real a, Real b, Real logBetaFun, Real logX, Real log1mX) |
| Continued fraction of I(x, a, b) (DiDonato and Morris, also Numerical Recipes betacf) by the modified Lentz method; it converges for x below (a + 1) / (a + b + 2) in far fewer terms than b for large shapes. | |
| template<std::floating_point Real> | |
| Real | ibetaLowerTail (Real x, Real a, Real b, Real logBetaFun, Real logX, Real log1mX) |
| I(x, a, b) for x not above the mean a / (a + b) and shapes up to IBETA_LARGEST_FINITE_SHAPE. | |
| template<int TABLE_SIZE> | |
| constexpr std::array< LongDoublePair, TABLE_SIZE > | createZiggurat (const std::function< LongDoublePair(const LongDoublePair &)> &funPtr, LongDoublePair first, LongDoublePair second) |
| template<std::floating_point Real> | |
| int | sign (Real x) |
| template<std::floating_point Real> | |
| Real | atan (Real x) |
| template<std::floating_point Real> | |
| Real | softplus (Real x) |
| template<std::floating_point Real> | |
| Real | log1mexp (Real x) |
| template<std::floating_point Real> | |
| Real | logexpm1l (Real x) |
| template<std::floating_point Real> | |
| Real | log2mexp (Real x) |
| template<std::floating_point Real> | |
| Real | erfinv (Real p) |
| template<std::floating_point Real> | |
| Real | erfcinv (Real p) |
| template<std::floating_point Real> | |
| Real | erfcx (Real x) |
| template<std::floating_point Real> | |
| Real | xexpxsqerfc (Real x) |
| xexpxsqerfc | |
| template<std::floating_point Real> | |
| Real | harmonicNumber (Real exponent, int number) |
| template<std::floating_point Real> | |
| Real | logBesselI (std::type_identity_t< Real > nu, Real x) |
| Calculates logarithm of modified Bessel function of the 1st kind. | |
| template<std::floating_point Real> | |
| Real | logBesselK (std::type_identity_t< Real > nu, Real x) |
| Calculates logarithm of modified Bessel function of the 2nd kind. | |
| template<std::floating_point Real> | |
| Real | W0Lambert (Real x, std::type_identity_t< Real > epsilon=Real{1e-11}) |
| template<std::floating_point Real> | |
| std::complex< Real > | W0Lambert (std::complex< Real > z) |
| template<std::floating_point Real> | |
| Real | Wm1Lambert (Real x, std::type_identity_t< Real > epsilon=Real{1e-11}) |
| template<std::floating_point Real> | |
| Real | MarcumP (std::type_identity_t< Real > mu, Real x, std::type_identity_t< Real > y, std::type_identity_t< Real > sqrtX, std::type_identity_t< Real > sqrtY, std::type_identity_t< Real > logX, std::type_identity_t< Real > logY) |
| template<std::floating_point Real> | |
| Real | MarcumP (std::type_identity_t< Real > mu, Real x, std::type_identity_t< Real > y) |
| template<std::floating_point Real> | |
| Real | MarcumQ (std::type_identity_t< Real > mu, Real x, std::type_identity_t< Real > y, std::type_identity_t< Real > sqrtX, std::type_identity_t< Real > sqrtY, std::type_identity_t< Real > logX, std::type_identity_t< Real > logY) |
| template<std::floating_point Real> | |
| Real | MarcumQ (std::type_identity_t< Real > mu, Real x, std::type_identity_t< Real > y) |
| template<std::floating_point Real> | |
| Real | factorial (Real n) |
| Calculate n! using table values for small n <= 255 and built-in gamma function for large n > 255. | |
| template<std::integral Integer> | |
| long double | factorial (Integer n) |
| template<std::floating_point Real = long double> | |
| Real | doubleFactorial (int n) |
| Calculate n!! | |
| template<std::floating_point Real = long double> | |
| Real | lfact (size_t n) |
| Calculate log(n!) using table values for small n <= 255 and built-in lgamma function for large n > 255. | |
| template<std::floating_point Real = long double> | |
| Real | ldfact (size_t n) |
| ldoublefact | |
| template<std::floating_point Real = long double> | |
| Real | binom (size_t n, size_t k) |
| Calculate binomial coefficient. | |
| template<std::floating_point Real = double> | |
| Real | stirlingError (size_t n) |
| template<std::floating_point Real = double> | |
| Real | logFactorialRatio (size_t x, size_t y) |
| template<std::floating_point Real> | |
| Real | bd0 (std::type_identity_t< Real > x, Real m) |
| Deviance term of the saddle-point expansions of Poisson and binomial probabilities (C. | |
| template<std::floating_point Real> | |
| Real | digamma (Real x) |
| template<std::floating_point Real> | |
| Real | digammamLog (Real x) |
| template<std::floating_point Real> | |
| Real | trigamma (Real x) |
| template<std::floating_point Real> | |
| Real | lpgamma (std::type_identity_t< Real > a, Real x, std::type_identity_t< Real > logA, std::type_identity_t< Real > lgammaA) |
| Calculate logarithm of lower incomplete gamma function, accelerated by using precalculated value of log(a) and log(Γ(a)) | |
| template<std::floating_point Real> | |
| Real | lpgamma (std::type_identity_t< Real > a, Real x, std::type_identity_t< Real > logX) |
| Calculate logarithm of lower incomplete gamma function, accelerated by using precalculated value of log(x) | |
| template<std::floating_point Real> | |
| Real | lpgamma (std::type_identity_t< Real > a, Real x) |
| Calculate logarithm of lower incomplete gamma function. | |
| template<std::floating_point Real> | |
| Real | pgamma (std::type_identity_t< Real > a, Real x, std::type_identity_t< Real > logA, std::type_identity_t< Real > lgammaA) |
| Calculate lower regularized incomplete gamma function, accelerated by using precalculated value of log(a) and log(Γ(a)) | |
| template<std::floating_point Real> | |
| Real | pgamma (std::type_identity_t< Real > a, Real x, std::type_identity_t< Real > logX) |
| Calculate lower regularized incomplete gamma function, accelerated by using precalculated value of log(x) | |
| template<std::floating_point Real> | |
| Real | pgamma (std::type_identity_t< Real > a, Real x) |
| Calculate lower regularized incomplete gamma function. | |
| template<std::floating_point Real> | |
| Real | lqgamma (std::type_identity_t< Real > a, Real x, std::type_identity_t< Real > logA, std::type_identity_t< Real > lgammaA) |
| Calculate logarithm of upper incomplete gamma function, accelerated by using precalculated values of log(a) and log(Γ(a)) | |
| template<std::floating_point Real> | |
| Real | lqgamma (std::type_identity_t< Real > a, Real x, std::type_identity_t< Real > logX) |
| Calculate logarithm of upper incomplete gamma function, accelerated by using precalculated value of log(x) | |
| template<std::floating_point Real> | |
| Real | lqgamma (std::type_identity_t< Real > a, Real x) |
| Calculate logarithm of upper incomplete gamma function. | |
| template<std::floating_point Real> | |
| Real | qgamma (std::type_identity_t< Real > a, Real x, std::type_identity_t< Real > logA, std::type_identity_t< Real > lgammaA) |
| Calculate upper regularized incomplete gamma function, accelerated by using precalculated values of log(a) and log(Γ(a)) | |
| template<std::floating_point Real> | |
| Real | qgamma (std::type_identity_t< Real > a, Real x, std::type_identity_t< Real > logX) |
| Calculate upper regularized incomplete gamma function, accelerated by using precalculated value of log(x) | |
| template<std::floating_point Real> | |
| Real | qgamma (std::type_identity_t< Real > a, Real x) |
| Calculate upper regularized incomplete gamma function. | |
| template<std::floating_point Real> | |
| Real | factorialForSmallValue (int n) |
| Get n! using product method with table. | |
| template<std::floating_point Real> | |
| Real | digammamLogForLargeX (Real x) |
| template<std::floating_point Real> | |
| Real | log1pmx (Real t) |
| template<std::floating_point Real> | |
| Real | logPrefactor (Real a, Real x, Real logX) |
| template<std::floating_point Real> | |
| Real | lowerSeries (Real a, Real x) |
| template<std::floating_point Real> | |
| Real | upperContinuedFraction (Real a, Real x) |
| Modified Lentz evaluation of the continued fraction for Q(a, x), x ≥ a + 1. | |
| template<std::floating_point Real> | |
| IncompleteGamma< Real > | incompleteGamma (Real a, Real x, Real logX) |
| Regularized incomplete gamma ratios P(a, x) and Q(a, x) = 1 - P(a, x) and their logarithms. | |
| template<std::floating_point Real> | |
| void | parametersVerification (Real a, Real x) |
| template<typename RealType > | |
| double | parabolicMinimum (RealType a, RealType b, RealType c, double fa, double fb, double fc) |
| template<typename RealType > | |
| bool | findMin (const std::function< double(RealType)> &funPtr, const Triplet< RealType > &abc, double &fx, RealType &root, double epsilon) |
| Combined Brent's method. | |
| template<typename RealType > | |
| bool | findMin (const std::function< double(RealType)> &funPtr, RealType closePoint, RealType &root, long double epsilon=1e-8) |
| Combined Brent's method. | |
| template<std::floating_point Real = double, class F > | |
| MinimizeResult< Real > | nelderMead (const F &f, std::vector< Real > start, Real tolerance=1e-10, int maxIterations=20000) |
| Downhill simplex method of Nelder and Mead with the dimension-dependent coefficients of Gao and Han (2012). | |
| template<std::floating_point Real = double, class F > | |
| std::vector< Real > | numericalGradient (const F &f, const std::vector< Real > &x) |
| template<std::floating_point Real = double, class F > | |
| std::vector< std::vector< Real > > | numericalHessian (const F &f, const std::vector< Real > &x) |
| template<std::floating_point Real = double, class F > | |
| MinimizeResult< Real > | bfgs (const F &f, std::vector< Real > start, Real tolerance=1e-8, int maxIterations=1000) |
| Quasi-Newton minimization of Broyden, Fletcher, Goldfarb and Shanno with central-difference gradients and a backtracking line search under the Armijo condition. | |
| template<std::floating_point Real = double, class F > | |
| Real | integrate (const F &f, std::type_identity_t< Real > a, std::type_identity_t< Real > b, std::type_identity_t< Real > tolerance=1e-11, int maxSubdivisions=512) |
| Global adaptive Gauss-Kronrod quadrature (QUADPACK QAG). | |
| template<std::floating_point Real = double, class F > | |
| Real | integrateTanhSinh (const F &f, std::type_identity_t< Real > a, std::type_identity_t< Real > b, std::type_identity_t< Real > tolerance=1e-11, int maxRefinements=12) |
| Double-exponential tanh-sinh quadrature on a finite interval. | |
| template<std::floating_point Real = double, class F > | |
| std::complex< Real > | integrateOscillatory (const F &litude, std::type_identity_t< Real > frequency, std::type_identity_t< Real > lower=0, std::type_identity_t< Real > tolerance=1e-10, int maxCycles=512) |
| QAWF-style Fourier integral on a semi-infinite interval. | |
| template<std::floating_point Real = double, class F , class TailMass > requires std::invocable<const TailMass &, Real> | |
| std::complex< Real > | integrateOscillatory (const F &litude, std::type_identity_t< Real > frequency, std::type_identity_t< Real > lower, const TailMass &tailMass, std::type_identity_t< Real > tolerance=1e-10, int maxCycles=512) |
| QAWF-style Fourier integral of an amplitude with a known tail bound: the half-period walk stops once the remaining mass is below the tolerance, and is accelerated only beyond half of the mass. | |
| template<std::floating_point Real, class F > | |
| std::pair< Real, Real > | toms748 (const F &f, Real a, Real b, Real fa, Real fb, int maxIterations=200) |
| Bracketing root finder of Alefeld, Potra and Shi (ACM TOMS algorithm 748): inverse cubic and Newton-quadratic interpolation steps, a double-length secant step and bisection whenever the bracket does not shrink by half; it converges like Brent's method at worst and faster on smooth functions. | |
| template<std::floating_point Real = double, class F > | |
| Real | findRoot (const F &f, std::type_identity_t< Real > a, std::type_identity_t< Real > b, int maxIterations=200) |
| template<typename RealType > | |
| bool | findRootNewtonFirstOrder (const std::function< DoublePair(RealType)> &funPtr, RealType &root, long double funTol=1e-10, long double stepTol=1e-6) |
| Newton's root-finding procedure, using first derivative. | |
| template<typename RealType > | |
| bool | findRootNewtonSecondOrder (const std::function< DoubleTriplet(RealType)> &funPtr, RealType &root, long double funTol=1e-10, long double stepTol=1e-6) |
| Newton's root-finding procedure, using first and second derivatives. | |
| bool | findRootNewtonFirstOrder2d (const std::function< DoublePair(DoublePair)> &funPtr, const std::function< std::tuple< DoublePair, DoublePair >(DoublePair)> &gradPtr, DoublePair &root, long double funTol=1e-10, long double stepTol=1e-6) |
| Newton's root-finding procedure for 2 functions of 2 parameters, using Jacobian matrix. | |
| template<std::floating_point Real> | |
| Real | besselI (std::type_identity_t< Real > nu, Real x) |
| template<std::floating_point Real> | |
| Real | besselK (std::type_identity_t< Real > nu, Real x) |
| template<std::floating_point Real> | |
| Real | riemannZeta (Real s) |
| template<std::floating_point Real> | |
| Real | lgammaCorrection (Real x) |
Variables | |
| constexpr int | FACTORIAL_TABLESIZE = 175 |
| constexpr long double | FACTORIAL_TABLE [] |
| constexpr long double | LOGFACTORIAL_TABLE [] |
| constexpr size_t | LOGFACTORIAL_TABLESIZE = 255 |
Beta-related functions.
Special functions that the C++17 standard library provides only optionally.
Gamma-related functions.
libstdc++ and MSVC implement the C++17 mathematical special functions, libc++ does not. These wrappers forward to std:: when it is available and fall back to RandLib's own implementations otherwise (or always, with RANDLIB_PORTABLE_SPECIAL_FUNCTIONS defined).
|
inline |
| x |
For small absolute values we use standard technique Otherwise we use relation atan(x) = +/-π/2 - atan(1/x) to avoid numeric problems
For small absolute values we use standard technique Otherwise we use relation atan(x) = +/-π/2 - atan(1/x) to avoid numeric problems
|
inline |
Deviance term of the saddle-point expansions of Poisson and binomial probabilities (C.
Loader, "Fast and accurate computation of binomial probabilities", 2000)
| x | non-negative number |
| m | positive number |
|
inline |
| nu | order, ν ≥ 0 |
| x | argument, x ≥ 0 |
|
inline |
| nu | order, ν ≥ 0 |
| x | argument, x > 0 |
| MinimizeResult< Real > randlib::math::bfgs | ( | const F & | f, |
| std::vector< Real > | start, | ||
| Real | tolerance = 1e-8, |
||
| int | maxIterations = 1000 |
||
| ) |
Quasi-Newton minimization of Broyden, Fletcher, Goldfarb and Shanno with central-difference gradients and a backtracking line search under the Armijo condition.
| f | smooth function of a std::span<const Real> |
| start | starting point |
| tolerance | the iteration stops when the largest gradient component is below this tolerance times max(1, |f|), or when a step no longer changes f |
| maxIterations | iteration limit |
H <- (I - ρ s yᵀ) H (I - ρ y sᵀ) + ρ s sᵀ
|
inline |
Calculate binomial coefficient.
| n | non-negative integer |
| k | non-negative integer, k < n |
first check trivial cases
next run general procedure
first check trivial cases
next run general procedure
|
constexpr |
|
inline |
| x | input parameter |
Negative argument
shift to minimum value, for which series expansion is applicable
Negative argument
shift to minimum value, for which series expansion is applicable
|
inline |
| x | input parameter |
|
inline |
| x |
set up tables
choose the amount of terms in series
apply
|
inline |
Calculate n!!
| n | non-negative integer number |
|
inline |
| p |
Consider special cases
Consider special cases
|
inline |
| x |
|
inline |
| p |
Consider special cases
Handle tails
Consider special cases
Handle tails
|
inline |
|
inline |
Calculate n! using table values for small n <= 255 and built-in gamma function for large n > 255.
| n | non-negative integer number |
|
inline |
Get n! using product method with table.
| n | non-negative integer number |
go up
go down
| bool randlib::math::findMin | ( | const std::function< double(RealType)> & | funPtr, |
| const Triplet< RealType > & | abc, | ||
| double & | fx, | ||
| RealType & | root, | ||
| double | epsilon | ||
| ) |
Combined Brent's method.
| funPtr | |
| abc | lower boundary / middle / upper boundary |
| fx | funPtr(b) |
| root | such x that funPtr(x) is min |
| epsilon | tolerance |
The tolerance is relative beyond |x| = 1: an absolute one cannot be met once it is below the spacing of doubles near the minimum, and the iteration would never end
accept u
use golden ratio instead of parabolic approximation
golden ratio [x, c]
golden ratio [a, x]
setting the closest distance between u and x
| bool randlib::math::findMin | ( | const std::function< double(RealType)> & | funPtr, |
| RealType | closePoint, | ||
| RealType & | root, | ||
| long double | epsilon = 1e-8 |
||
| ) |
Combined Brent's method.
| funPtr | |
| closePoint | point that is nearby minimum |
| root | such x that funPtr(x) is min |
| epsilon | tolerance |
we go to the right
parabolic interpolation
go to the left
parabolic interpolation
| Real randlib::math::findRoot | ( | const F & | f, |
| std::type_identity_t< Real > | a, | ||
| std::type_identity_t< Real > | b, | ||
| int | maxIterations = 200 |
||
| ) |
| f | continuous function with f(a) and f(b) of opposite signs |
| a | lower end of the bracket |
| b | upper end of the bracket |
| maxIterations | maximum number of refinement steps |
| bool randlib::math::findRootNewtonFirstOrder | ( | const std::function< DoublePair(RealType)> & | funPtr, |
| RealType & | root, | ||
| long double | funTol = 1e-10, |
||
| long double | stepTol = 1e-6 |
||
| ) |
Newton's root-finding procedure, using first derivative.
| funPtr | mapping x |-> (f(x), f'(x)) |
| root | starting point in input and such x that f(x) = 0 in output |
| funTol | function tolerance |
| stepTol | step tolerance |
Sanity check
Check convergence criteria
|
inline |
Newton's root-finding procedure for 2 functions of 2 parameters, using Jacobian matrix.
| funPtr | mapping x, y |-> (f(x, y), g(x, y)) |
| gradPtr | x, y |-> (f_x(x, y), f_y(x, y), g_x(x, y)), g_y(x, y)) |
| root | starting point in input and such x that f(x) = 0 in output |
| funTol | function tolerance |
| stepTol | step tolerance |
Sanity check
Check convergence criteria
Sanity check
Check convergence criteria
| bool randlib::math::findRootNewtonSecondOrder | ( | const std::function< DoubleTriplet(RealType)> & | funPtr, |
| RealType & | root, | ||
| long double | funTol = 1e-10, |
||
| long double | stepTol = 1e-6 |
||
| ) |
Newton's root-finding procedure, using first and second derivatives.
| funPtr | mapping x |-> (f(x), f'(x), f''(x)) |
| root | starting point in input and such x that f(x) = 0 in output |
| funTol | function tolerance |
| stepTol | step tolerance |
Sanity check
Check convergence criteria
|
inline |
| exponent | |
| number |
|
inline |
Calculate regularized beta function.
| x | |
| a | |
| b |
Check special and incorrect values of parameters
Check special and incorrect values of parameters
|
inline |
Fast calculation of regularized beta function, using precalculated values.
| x | |
| a | |
| b | |
| logBetaFun | log(B(a, b)) |
| logX | log(x) |
| log1mX | log(1-x) |
Check special and incorrect values of parameters
x may be a rounded complement such as 1 - t for tiny t, so 1 - x is recovered from log(1 - x)
For large shapes the continued fraction converges below c = (a + 1) / (a + b + 2). For a tiny x the complementary fraction at 1 - x would lose its digits, and the direct one still converges up to about four standard deviations above c, so the side whose argument is tiny is preferred there
If x is greater than mean of Beta distribution, convergence of complementary distribution function is faster. Close to 1 the series below converge only at the rate x, so the argument is never moved there: a tiny argument beyond a tinier mean is evaluated directly, and one within this distance of 1 under the mean (for a tiny second shape) through the complement, losing at most ε / I(x, a, b)
Check special and incorrect values of parameters
x may be a rounded complement such as 1 - t for tiny t, so 1 - x is recovered from log(1 - x)
For large shapes the continued fraction converges below c = (a + 1) / (a + b + 2). For a tiny x the complementary fraction at 1 - x would lose its digits, and the direct one still converges up to about four standard deviations above c, so the side whose argument is tiny is preferred there
If x is greater than mean of Beta distribution, convergence of complementary distribution function is faster. Close to 1 the series below converge only at the rate x, so the argument is never moved there: a tiny argument beyond a tinier mean is evaluated directly, and one within this distance of 1 under the mean (for a tiny second shape) through the complement, losing at most ε / I(x, a, b)
|
inline |
avoid underflow
|
inline |
|
inline |
Continued fraction of I(x, a, b) (DiDonato and Morris, also Numerical Recipes betacf) by the modified Lentz method; it converges for x below (a + 1) / (a + b + 2) in far fewer terms than b for large shapes.
|
inline |
I(x, a, b) for x not above the mean a / (a + b) and shapes up to IBETA_LARGEST_FINITE_SHAPE.
We truncate after 0.45 instead of 0.5 here in order to avoid x being too close to 0.5
equivalent continued fraction #1
equivalent continued fraction #2
|
inline |
avoid underflow
|
inline |
|
inline |
Regularized incomplete gamma ratios P(a, x) and Q(a, x) = 1 - P(a, x) and their logarithms.
The smaller ratio is always computed directly (series for x < a + 1, continued fraction otherwise), never by subtraction, so both tails keep their relative accuracy.
| Real randlib::math::integrate | ( | const F & | f, |
| std::type_identity_t< Real > | a, | ||
| std::type_identity_t< Real > | b, | ||
| std::type_identity_t< Real > | tolerance = 1e-11, |
||
| int | maxSubdivisions = 512 |
||
| ) |
Global adaptive Gauss-Kronrod quadrature (QUADPACK QAG).
Infinite limits are mapped onto (0, 1] by x = a + (1 - t) / t, as in QUADPACK QAGI; the rule never evaluates the endpoints.
| f | integrand |
| a | lower limit, possibly -∞ |
| b | upper limit, possibly +∞ |
| tolerance | relative error tolerance |
| maxSubdivisions | maximal number of bisections |
| std::complex< Real > randlib::math::integrateOscillatory | ( | const F & | amplitude, |
| std::type_identity_t< Real > | frequency, | ||
| std::type_identity_t< Real > | lower, | ||
| const TailMass & | tailMass, | ||
| std::type_identity_t< Real > | tolerance = 1e-10, |
||
| int | maxCycles = 512 |
||
| ) |
QAWF-style Fourier integral of an amplitude with a known tail bound: the half-period walk stops once the remaining mass is below the tolerance, and is accelerated only beyond half of the mass.
| amplitude | non-oscillatory real amplitude |
| frequency | positive angular frequency |
| lower | finite lower limit |
| tailMass | bound on the integral of |amplitude| from its argument to infinity |
| tolerance | absolute convergence tolerance |
| maxCycles | maximum number of half-periods |
| std::complex< Real > randlib::math::integrateOscillatory | ( | const F & | amplitude, |
| std::type_identity_t< Real > | frequency, | ||
| std::type_identity_t< Real > | lower = 0, |
||
| std::type_identity_t< Real > | tolerance = 1e-10, |
||
| int | maxCycles = 512 |
||
| ) |
QAWF-style Fourier integral on a semi-infinite interval.
The interval is divided into half-periods and the resulting alternating sequence is accelerated with Wynn's epsilon algorithm.
| amplitude | non-oscillatory real amplitude |
| frequency | positive angular frequency |
| lower | finite lower limit |
| tolerance | absolute convergence tolerance |
| maxCycles | maximum number of half-periods |
| Real randlib::math::integrateTanhSinh | ( | const F & | f, |
| std::type_identity_t< Real > | a, | ||
| std::type_identity_t< Real > | b, | ||
| std::type_identity_t< Real > | tolerance = 1e-11, |
||
| int | maxRefinements = 12 |
||
| ) |
Double-exponential tanh-sinh quadrature on a finite interval.
This rule is intended for integrable endpoint singularities. A callable that accepts (x, endpointDistance) receives a negative distance a - x near the left endpoint and a positive distance b - x near the right endpoint, allowing cancellation-free evaluation when x rounds to an endpoint.
| f | integrand accepting either f(x) or f(x, endpointDistance) |
| a | finite lower limit |
| b | finite upper limit |
| tolerance | error tolerance relative to the estimated integral of |f| |
| maxRefinements | maximum number of step halvings |
|
inline |
ldoublefact
| n |
|
inline |
Calculate log(n!) using table values for small n <= 255 and built-in lgamma function for large n > 255.
| n | non-negative integer number |
|
inline |
| x | argument, x ≥ 10 |
|
inline |
| x |
|
inline |
| t |
|
inline |
| x |
|
inline |
Calculates logarithm of modified Bessel function of the 1st kind.
| nu | |
| x |
log(sinh(x)) or log(cosh(x))
I(ν, x) = I(-ν, x) - 2 / π sin(πν) K(-ν, x), and sin(πν) = -sin(π|ν|) for ν < 0
Large order: I_ν(x) = (x/2)^ν / Γ(ν + 1) Σ_j (x²/4)^j / (j! (ν + 1)_j) underflows, its logarithm does not
log(sinh(x)) or log(cosh(x))
I(ν, x) = I(-ν, x) - 2 / π sin(πν) K(-ν, x), and sin(πν) = -sin(π|ν|) for ν < 0
Large order: I_ν(x) = (x/2)^ν / Γ(ν + 1) Σ_j (x²/4)^j / (j! (ν + 1)_j) underflows, its logarithm does not
|
inline |
Calculates logarithm of modified Bessel function of the 2nd kind.
| nu | |
| x |
K(-ν, x) = K(ν, x)
K(-ν, x) = K(ν, x)
|
inline |
|
inline |
Calculate logarithm of beta function.
| a | positive parameter |
| b | positive parameter |
Stirling corrections avoid both overflow of Γ and cancellation between large log Γ values
Stirling corrections avoid both overflow of Γ and cancellation between large log Γ values
|
inline |
| x |
|
inline |
| x | non-negative integer number |
| y | non-negative integer number |
log(x!) = (x + 1/2) log(x + 1) - (x + 1) + log(2π) / 2 + stirlingError(x + 1)
log(x!) = (x + 1/2) log(x + 1) - (x + 1) + log(2π) / 2 + stirlingError(x + 1)
|
inline |
|
inline |
|
inline |
Calculate logarithm of lower incomplete gamma function.
| a | non-negative parameter |
| x | non-negative parameter |
|
inline |
Calculate logarithm of lower incomplete gamma function, accelerated by using precalculated value of log(a) and log(Γ(a))
| a | non-negative parameter |
| x | non-negative parameter |
| logA | log(a) |
| lgammaA | log(Γ(a)) |
|
inline |
Calculate logarithm of lower incomplete gamma function, accelerated by using precalculated value of log(x)
| a | non-negative parameter |
| x | non-negative parameter |
| logX | log(x) |
|
inline |
Calculate logarithm of upper incomplete gamma function.
| a | non-negative parameter |
| x | non-negative parameter |
|
inline |
Calculate logarithm of upper incomplete gamma function, accelerated by using precalculated values of log(a) and log(Γ(a))
| a | non-negative parameter |
| x | non-negative parameter |
| logA | log(a) |
| lgammaA | log(Γ(a)) |
|
inline |
Calculate logarithm of upper incomplete gamma function, accelerated by using precalculated value of log(x)
| a | non-negative parameter |
| x | non-negative parameter |
| logX | log(x) |
|
inline |
| mu | |
| x | |
| y |
|
inline |
| mu | |
| x | |
| y | |
| sqrtX | √x |
| sqrtY | √y |
| logX | log(x) |
| logY | log(y) |
Saddle-centred Poisson mixtures: the lower tail directly below the mean μ + x, the complement above it
Saddle-centred Poisson mixtures: the lower tail directly below the mean μ + x, the complement above it
|
inline |
| mu | |
| x | |
| y |
|
inline |
| mu | |
| x | |
| y | |
| sqrtX | √x |
| sqrtY | √y |
| logX | log(x) |
| logY | log(y) |
Below the mean μ + x the complement of the lower-tail mixture is accurate where Q is close to 1, and it agrees with MarcumP there
Below the mean μ + x the complement of the lower-tail mixture is accurate where Q is close to 1, and it agrees with MarcumP there
| MinimizeResult< Real > randlib::math::nelderMead | ( | const F & | f, |
| std::vector< Real > | start, | ||
| Real | tolerance = 1e-10, |
||
| int | maxIterations = 20000 |
||
| ) |
Downhill simplex method of Nelder and Mead with the dimension-dependent coefficients of Gao and Han (2012).
The initial simplex steps 5% along each coordinate (0.00025 for zero coordinates), as in MATLAB's fminsearch.
| f | function of a std::span<const Real> |
| start | starting point |
| tolerance | the iteration stops when the function values and the coordinates of the simplex agree to this relative tolerance |
| maxIterations | iteration limit |
| std::vector< Real > randlib::math::numericalGradient | ( | const F & | f, |
| const std::vector< Real > & | x | ||
| ) |
| f | function of a std::span<const Real> |
| x | point |
| std::vector< std::vector< Real > > randlib::math::numericalHessian | ( | const F & | f, |
| const std::vector< Real > & | x | ||
| ) |
| f | function of a std::span<const Real> |
| x | point |
| double randlib::math::parabolicMinimum | ( | RealType | a, |
| RealType | b, | ||
| RealType | c, | ||
| double | fa, | ||
| double | fb, | ||
| double | fc | ||
| ) |
| a | point to the left of b |
| b | middle point |
| c | point to the right of b |
| fa | f(a) |
| fb | f(b) |
| fc | f(c) |
|
inline |
|
inline |
Calculate lower regularized incomplete gamma function.
| a | non-negative parameter |
| x | non-negative parameter |
|
inline |
Calculate lower regularized incomplete gamma function, accelerated by using precalculated value of log(a) and log(Γ(a))
| a | non-negative parameter |
| x | non-negative parameter |
| logA | log(a) |
| lgammaA | log(Γ(a)) |
|
inline |
Calculate lower regularized incomplete gamma function, accelerated by using precalculated value of log(x)
| a | non-negative parameter |
| x | non-negative parameter |
| logX | log(x) |
|
inline |
Calculate upper regularized incomplete gamma function.
| a | non-negative parameter |
| x | non-negative parameter |
|
inline |
Calculate upper regularized incomplete gamma function, accelerated by using precalculated values of log(a) and log(Γ(a))
| a | non-negative parameter |
| x | non-negative parameter |
| logA | log(a) |
| lgammaA | log(Γ(a)) |
|
inline |
Calculate upper regularized incomplete gamma function, accelerated by using precalculated value of log(x)
| a | non-negative parameter |
| x | non-negative parameter |
| logX | log(x) |
|
inline |
| s | argument, s > 1 |
|
inline |
| x |
|
inline |
| x |
|
inline |
| n | positive integer number |
| std::pair< Real, Real > randlib::math::toms748 | ( | const F & | f, |
| Real | a, | ||
| Real | b, | ||
| Real | fa, | ||
| Real | fb, | ||
| int | maxIterations = 200 |
||
| ) |
Bracketing root finder of Alefeld, Potra and Shi (ACM TOMS algorithm 748): inverse cubic and Newton-quadratic interpolation steps, a double-length secant step and bisection whenever the bracket does not shrink by half; it converges like Brent's method at worst and faster on smooth functions.
| f | continuous function with f(a) and f(b) of opposite signs |
| a | lower end of the bracket |
| b | upper end of the bracket |
| fa | f(a) |
| fb | f(b) |
| maxIterations | maximal number of evaluations of f |
replaces [a, b] by the sub-bracket around c and keeps the dropped end in (d, fd)
double-length secant step from the end with the smaller residual
bisect when the bracket did not shrink by half
|
inline |
| x | input parameter |
Negative argument
set up tables
shift to minimum value, for which series expansion is applicable
choose the amount of terms in series
apply
Negative argument
set up tables
shift to minimum value, for which series expansion is applicable
choose the amount of terms in series
apply
|
inline |
Modified Lentz evaluation of the continued fraction for Q(a, x), x ≥ a + 1.
|
inline |
| x | |
| epsilon |
|
inline |
| z | complex argument off the branch cut (-∞, -1/e] |
Winitzki's approximation, refined by Halley's iteration
Winitzki's approximation, refined by Halley's iteration
|
inline |
| x | |
| epsilon |
|
inline |
xexpxsqerfc
| x |
|
constexpr |
|
constexpr |
|
constexpr |
|
constexpr |