Loading...
Searching...
No Matches
DistributionFunctions.cpp
Go to the documentation of this file.
1//
2// DistributionFunctions.cpp
3// gpr_dimer
4//
5// Created by Maxim Masterov on 03/12/2020.
6//
7
9
10namespace math {
11
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}
70} // namespace math
@ x
Definition Enums.h:28
@ y
Definition Enums.h:28
double erfinv(double x)
Inverse error function NOTE: Abramowitz & Stegun rational approximation, taken from http://libit....