Пример #1
0
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))
Пример #3
0
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
Пример #4
0
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)
Пример #5
0
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
Пример #6
0
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)
Пример #7
0
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
Пример #8
0
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
Пример #9
0
 def _comp_beta(self, eps_exp):
     eps = mpm.power(2, eps_exp)
     beta = mpm.erfinv(1 - eps) * mpm.sqrt(2)
     return beta
Пример #10
0
def mpmath_erfcinv(x):
    return mpmath.erfinv(mpmath.mpf(1) - x)
Пример #11
0
 def pvalue2sigma(self, pvalue):
     return mpmath.sqrt(2) * mpmath.erfinv(1 - 2 * pvalue)
Пример #12
0
def inverseNormalCDF(area):
    return mpmath.erfinv(area) * mpmath.sqrt(2.0)
Пример #13
0
def _erfcinv(y):
    with mpmath.extradps(5):
        return mpmath.erfinv(1 - y)