|
138 | 138 | from decimal import Decimal |
139 | 139 | from itertools import count, groupby, repeat |
140 | 140 | from bisect import bisect_left, bisect_right |
141 | | -from math import hypot, sqrt, fabs, exp, erf, tau, log, fsum, sumprod |
| 141 | +from math import hypot, sqrt, fabs, exp, erfc, tau, log, fsum, sumprod |
142 | 142 | from math import isfinite, isinf, pi, cos, sin, tan, cosh, asin, atan, acos |
143 | 143 | from functools import reduce |
144 | 144 | from operator import itemgetter |
@@ -811,8 +811,9 @@ def deco(builder): |
811 | 811 | def normal_kernel(): |
812 | 812 | sqrt2pi = sqrt(2 * pi) |
813 | 813 | sqrt2 = sqrt(2) |
| 814 | + neg_sqrt2 = -sqrt2 |
814 | 815 | pdf = lambda t: exp(-1/2 * t * t) / sqrt2pi |
815 | | - cdf = lambda t: 1/2 * (1.0 + erf(t / sqrt2)) |
| 816 | + cdf = lambda t: 1/2 * erfc(t / neg_sqrt2) |
816 | 817 | invcdf = lambda t: _normal_dist_inv_cdf(t, 0.0, 1.0) |
817 | 818 | support = None |
818 | 819 | return pdf, cdf, invcdf, support |
@@ -1257,7 +1258,7 @@ def cdf(self, x): |
1257 | 1258 | "Cumulative distribution function. P(X <= x)" |
1258 | 1259 | if not self._sigma: |
1259 | 1260 | raise StatisticsError('cdf() not defined when sigma is zero') |
1260 | | - return 0.5 * (1.0 + erf((x - self._mu) / (self._sigma * _SQRT2))) |
| 1261 | + return 0.5 * erfc((self._mu - x) / (self._sigma * _SQRT2)) |
1261 | 1262 |
|
1262 | 1263 | def inv_cdf(self, p): |
1263 | 1264 | """Inverse cumulative distribution function. x : P(X <= x) = p |
@@ -1311,7 +1312,7 @@ def overlap(self, other): |
1311 | 1312 | dv = Y_var - X_var |
1312 | 1313 | dm = fabs(Y._mu - X._mu) |
1313 | 1314 | if not dv: |
1314 | | - return 1.0 - erf(dm / (2.0 * X._sigma * _SQRT2)) |
| 1315 | + return erfc(dm / (2.0 * X._sigma * _SQRT2)) |
1315 | 1316 | a = X._mu * Y_var - Y._mu * X_var |
1316 | 1317 | b = X._sigma * Y._sigma * sqrt(dm * dm + dv * log(Y_var / X_var)) |
1317 | 1318 | x1 = (a + b) / dv |
|
0 commit comments