def test_erfinv_extreme_values(): x_near_n1 = np.nextafter(-1, np.inf) assert_allclose( sc.erfinv(x_near_n1), float(mpmath.erfinv(x_near_n1)), atol=0, rtol=1e-14, ) x_near_1 = np.nextafter(1, -np.inf) assert_allclose( sc.erfinv(x_near_1), float(mpmath.erfinv(x_near_1)), atol=0, rtol=1e-14, )
def _invert_Gaussian_CDF(self, z): if z < 0.5: sign = -1 else: sign = 1 x = sign*np.sqrt(2)*mpmath.erfinv(sign*(2*z-1)) return(float(x))
def t2z_convert(t, nu): t = mpf(t) nu = mpf(nu) z = sqrt(mpf("2")) * erfinv( # inverse normal cdf mpf("2") * t * gamma((mpf("1") / mpf("2")) * nu + mpf("1") / mpf("2")) * hyper( (mpf("1") / mpf("2"), (mpf("1") / mpf("2")) * nu + mpf("1") / mpf("2")), (mpf("3") / mpf("2"), ), -power(t, mpf("2")) / nu, ) / (sqrt(pi) * sqrt(nu) * gamma((mpf("1") / mpf("2")) * nu))) return z
def invsf(p, mu=0, sigma=1): """ Inverse of the survivial function of the Lévy distribution. """ if p < 0 or p > 1: raise ValueError('p must be in the interval [0, 1]') if sigma <= 0: raise ValueError('sigma must be positive.') with mpmath.extradps(5): p = mpmath.mpf(p) mu = mpmath.mpf(mu) sigma = mpmath.mpf(sigma) return mu + sigma / (2 * mpmath.erfinv(p)**2)
def f2z_convert(x, d1, d2): x = mpf(x) d1 = mpf(d1) d2 = mpf(d2) if x < mpf("0") or d1 < mpf("0") or d2 < mpf("0"): return mpf("0") z = sqrt(mpf("2")) * erfinv( # inverse normal cdf -mpf("1") + mpf("2") * betainc( # F distribution cdf d1 / mpf("2"), d2 / mpf("2"), x2=d1 * x / (d1 * x + d2), regularized=True)) return z
def ZPL_bayesiana(Non, Noff, vol): alpha = (1 - vol) / (vol) def B_01(Non, Noff, alpha): Ntot = Non + Noff gam = (1 + 2 * Noff) * power(alpha, (0.5 + Ntot)) * gamma(0.5 + Ntot) delta = ((2 * power((1 + alpha), Ntot)) * gamma(1 + Ntot) * hyp2f1(0.5 + Noff, 1 + Ntot, 1.5 + Noff, (-1 / alpha))) c1_c2 = sqrt(pi) / (2 * atan(1 / sqrt(alpha))) return gam / (c1_c2 * delta) buf = 1 - B_01(Non, Noff, alpha) if buf < -1.0: buf = -1.0 # print(buf) return sqrt("2") * erfinv(buf)
def invcdf(p, mu=0, sigma=1): """ Normal distribution inverse CDF. This function is also known as the quantile function or the percent point function. """ if p < 0 or p > 1: return mpmath.nan p = mpmath.mpf(p) mu = mpmath.mpf(mu) sigma = mpmath.mpf(sigma) a = mpmath.erfinv(2 * p - 1) x = mpmath.sqrt(2) * sigma * a + mu return x
def invcdf(p, mu=0, sigma=1): """ Log-normal distribution inverse CDF. This function is also known as the quantile function or the percent point function. """ _validate_sigma(sigma) if p < 0 or p > 1: return mpmath.nan with mpmath.extradps(5): p = mpmath.mpf(p) mu = mpmath.mpf(mu) sigma = mpmath.mpf(sigma) a = mpmath.erfinv(2 * p - 1) x = mpmath.exp(mpmath.sqrt(2) * sigma * a + mu) return x
def _comp_beta(self, eps_exp): eps = mpm.power(2, eps_exp) beta = mpm.erfinv(1 - eps) * mpm.sqrt(2) return beta
def mpmath_erfcinv(x): return mpmath.erfinv(mpmath.mpf(1) - x)
def pvalue2sigma(self, pvalue): return mpmath.sqrt(2) * mpmath.erfinv(1 - 2 * pvalue)
def inverseNormalCDF(area): return mpmath.erfinv(area) * mpmath.sqrt(2.0)
def _erfcinv(y): with mpmath.extradps(5): return mpmath.erfinv(1 - y)