Loading...
Searching...
No Matches
math::DistributionFunctions Class Reference

Auxiliary functions for CDF calculation. More...

#include <backend/DistributionFunctions.h>

Public Member Functions

 DistributionFunctions ()
 ~DistributionFunctions ()
double normalCDF (const double x, double const mu, const double sigma)
 Normal cumulative distribution function.
double normalCDFInverse (const double p, double const mu, const double sigma)
 Inverse complementary error function.
double erfinv (double x)
 Inverse error function NOTE: Abramowitz & Stegun rational approximation, taken from http://libit.sourceforge.net/math_8c-source.html Sufficient accuracy for the current GPR use case (~7 digits).

Detailed Description

Auxiliary functions for CDF calculation.

Definition at line 17 of file DistributionFunctions.h.

Constructor & Destructor Documentation

◆ DistributionFunctions()

math::DistributionFunctions::DistributionFunctions ( )
inline

Definition at line 19 of file DistributionFunctions.h.

19{ }

◆ ~DistributionFunctions()

math::DistributionFunctions::~DistributionFunctions ( )
inline

Definition at line 20 of file DistributionFunctions.h.

20{ }

Member Function Documentation

◆ erfinv()

double math::DistributionFunctions::erfinv ( double x)

Inverse error function NOTE: Abramowitz & Stegun rational approximation, taken from http://libit.sourceforge.net/math_8c-source.html Sufficient accuracy for the current GPR use case (~7 digits).

Parameters
xValue for evaluation

Definition at line 12 of file DistributionFunctions.cpp.

13{
14 const double erfinv_a3 = -0.140543331;
15 const double erfinv_a2 = 0.914624893;
16 const double erfinv_a1 = -1.645349621;
17 const double erfinv_a0 = 0.886226899;
18
19 const double erfinv_b4 = 0.012229801;
20 const double erfinv_b3 = -0.329097515;
21 const double erfinv_b2 = 1.442710462;
22 const double erfinv_b1 = -2.118377725;
23 const double erfinv_b0 = 1;
24
25 const double erfinv_c3 = 1.641345311;
26 const double erfinv_c2 = 3.429567803;
27 const double erfinv_c1 = -1.62490649;
28 const double erfinv_c0 = -1.970840454;
29
30 const double erfinv_d2 = 1.637067800;
31 const double erfinv_d1 = 3.543889200;
32 const double erfinv_d0 = 1;
33
34 double x2, r, y;
35 int sign_x;
36
37 if (x < -1 || x > 1) return NAN;
38
39 if (x == 0) return 0;
40
41 if (x > 0)
42 sign_x = 1;
43 else {
44 sign_x = -1;
45 x = -x;
46 }
47
48 if (x <= 0.7) {
49 x2 = x * x;
50 r = x *
51 (((erfinv_a3 * x2 + erfinv_a2) * x2 + erfinv_a1) * x2 + erfinv_a0);
52 r /=
53 (((erfinv_b4 * x2 + erfinv_b3) * x2 + erfinv_b2) * x2 + erfinv_b1) *
54 x2 +
55 erfinv_b0;
56 } else {
57 y = sqrt(-log((1 - x) / 2));
58 r = (((erfinv_c3 * y + erfinv_c2) * y + erfinv_c1) * y + erfinv_c0);
59 r /= ((erfinv_d2 * y + erfinv_d1) * y + erfinv_d0);
60 }
61
62 r = r * sign_x;
63 x = x * sign_x;
64
65 r -= (erf(r) - x) / (2 / sqrt(M_PI) * exp(-r * r));
66 r -= (erf(r) - x) / (2 / sqrt(M_PI) * exp(-r * r));
67
68 return r;
69}
@ x
Definition Enums.h:28
@ y
Definition Enums.h:28
DoubleDouble sqrt(DoubleDouble a)
double erf(double x) noexcept
double log(double x) noexcept
double exp(double x) noexcept

◆ normalCDF()

double math::DistributionFunctions::normalCDF ( const double x,
double const mu,
const double sigma )
inline

Normal cumulative distribution function.

Parameters
xValue for evaluation
muMean
sigmaStandard deviation
Returns
Cumulative distribution function of the normal distribution

Definition at line 30 of file DistributionFunctions.h.

31 {
32 double x_loc = (x - mu) / sigma;
33 return 0.5 * erfc(-x_loc * M_SQRT1_2);
34 }
double erfc(double x) noexcept

◆ normalCDFInverse()

double math::DistributionFunctions::normalCDFInverse ( const double p,
double const mu,
const double sigma )
inline

Inverse complementary error function.

Parameters
pProbability value for evaluation
muMean
sigmaStandard deviation
Returns
Inverse of the normal vumulative distribution function

Definition at line 44 of file DistributionFunctions.h.

46 {
47 return mu + sigma * M_SQRT2 * erfinv(2. * p - 1.);
48 }
double erfinv(double x)
Inverse error function NOTE: Abramowitz & Stegun rational approximation, taken from http://libit....

The documentation for this class was generated from the following files: