Esempio n. 1
0
def cdf(x, a, b, c, loc=0, scale=1):
    """
    CDF of the generalized exponential distribution.
    """
    with mpmath.extradps(5):
        x, a, b, c, loc, scale = _validate_x_params(x, a, b, c, loc, scale)
        z = (x - loc) / scale
        s = a + b
        r = b / c
        result = -mpmath.expm1(-s*z + r*(-mpmath.expm1(-c*z)))
    return result
Esempio n. 2
0
def pdf(x, a, b, c, loc=0, scale=1):
    """
    PDF of the generalized exponential distribution.
    """
    with mpmath.extradps(5):
        x, a, b, c, loc, scale = _validate_x_params(x, a, b, c, loc, scale)
        z = (x - loc) / scale
        s = a + b
        r = b / c
        p = ((a + b*(-mpmath.expm1(-c*z))) *
             mpmath.exp(-s*z + r*(-mpmath.expm1(-c*z))))/scale
    return p
Esempio n. 3
0
def logpdf(x, a, b, c, loc=0, scale=1):
    """
    Natural logarithm of the PDF of the generalized exponential distribution.
    """
    with mpmath.extradps(5):
        x, a, b, c, loc, scale = _validate_x_params(x, a, b, c, loc, scale)
        z = (x - loc) / scale
        s = a + b
        r = b / c
        logp = (mpmath.log(a + b*(-mpmath.expm1(-c*z))) +
                (-s*z + r*(-mpmath.expm1(-c*z))))
    return logp
Esempio n. 4
0
def skewness(mu=0, sigma=1):
    """
    Skewness of the lognormal distribution.
    """
    _validate_sigma(sigma)
    sigma2 = sigma**2
    return (mpmath.exp(sigma2) + 2) * mpmath.sqrt(mpmath.expm1(sigma2))
Esempio n. 5
0
def var(mu=0, sigma=1):
    """
    Variance of the lognormal distribution.
    """
    _validate_sigma(sigma)
    mu = mpmath.mpf(mu)
    sigma = mpmath.mpf(sigma)
    sigma2 = sigma**2
    return mpmath.expm1(sigma2) * mpmath.exp(2 * mu + sigma2)
Esempio n. 6
0
def yeo_johnson(x, lmbda):
    r"""
    Yeo-Johnson transformation of x.

    See https://en.wikipedia.org/wiki/Power_transform#Yeo%E2%80%93Johnson_transformation
    """
    with mpmath.extradps(5):
        x = mpmath.mpf(x)
        lmbda = mpmath.mpf(lmbda)
        if x >= 0:
            if lmbda == 0:
                return mpmath.log1p(x)
            else:
                return mpmath.expm1(lmbda * mpmath.log1p(x)) / lmbda
        else:
            if lmbda == 2:
                return -mpmath.log1p(-x)
            else:
                lmb2 = 2 - lmbda
                return -mpmath.expm1(lmb2 * mpmath.log1p(-x)) / lmb2
Esempio n. 7
0
def inv_yeo_johnson(x, lmbda):
    """
    Inverse Yeo-Johnson transformation.

    See https://en.wikipedia.org/wiki/Power_transform#Yeo%E2%80%93Johnson_transformation
    """
    with mpmath.extradps(5):
        x = mpmath.mpf(x)
        lmbda = mpmath.mpf(lmbda)
        if x >= 0:
            if lmbda == 0:
                return mpmath.expm1(x)
            else:
                return mpmath.expm1(mpmath.log1p(lmbda * x) / lmbda)
        else:
            if lmbda == 2:
                return -mpmath.expm1(-x)
            else:
                lmb2 = 2 - lmbda
                return -mpmath.expm1(mpmath.log1p(-lmb2 * x) / lmb2)
Esempio n. 8
0
def mode(mu, loc=0, scale=1):
    """
    Mode of the inverse Gaussian distribution.
    """
    with mpmath.extradps(5):
        mu, loc, scale = _validate_params(mu, loc, scale)
        s = 3 * mu / 2
        # t is equivalent to sqrt(1 + 1/s**2) - 1.
        t = mpmath.expm1(mpmath.log1p(1 / s**2) / 2)
        # m = mu*(sqrt(1 + s**2) - s) = mu*s*(sqrt(1 + 1/s**2) - 1) = mu*s*t
        m = mu * s * t
        return scale * m + loc
Esempio n. 9
0
def sf(x, loc, scale):
    """
    Survival function for the Gumbel distribution.
    """
    if scale <= 0:
        raise ValueError('scale must be positive.')

    with mpmath.extradps(5):
        x = mpmath.mpf(x)
        loc = mpmath.mpf(loc)
        scale = mpmath.mpf(scale)
        z = (x - loc) / scale
        return -mpmath.expm1(-mpmath.exp(-z))
Esempio n. 10
0
def sf(x, k, loc, scale):
    """
    Survival function for the Weibull distribution (for maxima).

    This is a three-parameter version of the distribution.  The more typical
    two-parameter version has just the parameters k and scale.
    """
    with mpmath.extradps(5):
        x = mpmath.mpf(x)
        k, loc, scale = _validate_params(k, loc, scale)
        if x >= loc:
            return mpmath.mp.zero
        z = (x - loc) / scale
        return -mpmath.expm1(-(-z)**k)
Esempio n. 11
0
def sf(x, xi, mu=0, sigma=1):
    """
    Generalized extreme value distribution survival function.
    """
    _validate_sigma(sigma)
    xi = mpmath.mpf(xi)
    mu = mpmath.mpf(mu)
    sigma = mpmath.mpf(sigma)

    # Formula from wikipedia, which has a sign convention for xi that
    # is the opposite of scipy's shape parameter.
    if xi != 0:
        t = mpmath.power(1 + ((x - mu) / sigma) * xi, -1 / xi)
    else:
        t = mpmath.exp(-(x - mu) / sigma)
    return -mpmath.expm1(-t)
Esempio n. 12
0
def pdf(x, a, c, scale=1):
    """
    PDF for the exponentiated Weibull distribution.

    All the distribution parameters are assumed to be positive.
    """
    x = mpmath.mpf(x)
    a = mpmath.mpf(a)
    c = mpmath.mpf(c)
    scale = mpmath.mpf(scale)

    if x < 0:
        return mpmath.mp.zero

    z = x / scale
    p = (a * c / scale * z**(c-1) * (-mpmath.expm1(-z**c))**(a - 1) *
         mpmath.exp(-z**c))
    return p
Esempio n. 13
0
def cdf(x, a, c, scale=1):
    """
    CDF for the exponentiated Weibull distribution.

    This is the cumulative distribution function for the exponentiated
    Weibull distribution.

    All the distribution parameters are assumed to be positive.
    """
    x = mpmath.mpf(x)
    a = mpmath.mpf(a)
    c = mpmath.mpf(c)
    scale = mpmath.mpf(scale)

    if x < 0:
        return mpmath.mp.zero

    z = x / scale
    return mpmath.power(-mpmath.expm1(-z**c), a)
Esempio n. 14
0
def cdf(x, xi, mu=0, sigma=1):
    """
    Generalized Pareto distribution cumulative density function.
    """
    with mpmath.extradps(5):
        xi = mpmath.mpf(xi)
        mu = mpmath.mpf(mu)
        sigma = mpmath.mpf(sigma)

        z = (x - mu) / sigma
        if (xi >= 0 and z < 0) or (xi < 0 and z < 0):
            t = mpmath.mp.zero
        elif xi < 0 and z > -1 / xi:
            t = mpmath.mp.one
        else:
            if xi != 0:
                t = -mpmath.powm1(1 + xi * z, -1 / xi)
            else:
                t = -mpmath.expm1(-z)
    return t
Esempio n. 15
0
def cmarcumq(m, a, b):
    """
    The "complementary" Marcum Q function.

    This is 1 - marcumq(m, a, b).

    The function uses numerical integration, so it can be very slow.

    The computed integral tends to be very inaccurate for m < 1/2.

    *See also:* `mpsci.fun.marcumq`
    """
    if a == 0:
        if m == 1:
            q = -mpmath.expm1(-b**2/2)
        else:
            q = mpmath.gammainc(m, 0, b**2/2, regularized=True)
    elif b == 0 and m > 0:
        q = mpmath.mpf(0)
    else:
        q = mpmath.quad(lambda x: _integrand(x, m, a), [0, b])
    return q
Esempio n. 16
0
def logpdf(x, a, c, scale=1):
    """
    Logarithm of the PDF for the exponentiated Weibull distribution.

    All the distribution parameters are assumed to be positive.
    """
    x = mpmath.mpf(x)
    a = mpmath.mpf(a)
    c = mpmath.mpf(c)
    scale = mpmath.mpf(scale)

    if x < 0:
        return -mpmath.mp.inf

    z = x / scale
    logp = (mpmath.log(a)
            + mpmath.log(c)
            - mpmath.log(scale)
            + (c - 1)*mpmath.log(z)
            + (a - 1)*mpmath.log(-mpmath.expm1(-z**c))
            - z**c)
    return logp
Esempio n. 17
0
def _mle_scale_with_fixed_loc(scale, x, loc):
    z = [(xi - loc) / scale for xi in x]
    ez = [mpmath.expm1(-zi)*zi for zi in z]
    return stats.mean(ez) + 1
Esempio n. 18
0
def f53(x):
    # exprel_2
    x = mpmath.mpf(x)
    y = 2 * (mpmath.expm1(x) - x) / (x * x)
    return y
Esempio n. 19
0
def f52(x):
    # exprel
    x = mpmath.mpf(x)
    return mpmath.expm1(x) / x
Esempio n. 20
0
def f51(x):
    # expm1
    return mpmath.expm1(x)
Esempio n. 21
0
def fz(z):
    e = 1 / (mpmath.expm1(z * C / (1 - z)))
    a = (z**3) / ((1 - z)**5)
    return mpmath.mpf(e * a)
Esempio n. 22
0
 'atan': ['primitive', [lambda x, y: mp.atan(x), None]],
 'atan2': ['primitive', [lambda x, y: mp.atan2(y[0], x), None]],
 'asec': ['primitive', [lambda x, y: mp.asec(x), None]],
 'acsc': ['primitive', [lambda x, y: mp.acsc(x), None]],
 'acot': ['primitive', [lambda x, y: mp.acot(x), None]],
 'sinc': ['primitive', [lambda x, y: mp.sinc(x), None]],
 'sincpi': ['primitive', [lambda x, y: mp.sincpi(x), None]],
 'degrees': ['primitive', [lambda x, y: mp.degrees(x),
                           None]],  #radian - >degree 
 'radians': ['primitive', [lambda x, y: mp.radians(x),
                           None]],  #degree - >radian 
 #
 'exp': ['primitive', [lambda x, y: mp.exp(x), None]],
 'expj': ['primitive', [lambda x, y: mp.expj(x), None]],  #exp(x*i) 
 'expjpi': ['primitive', [lambda x, y: mp.expjpi(x), None]],  #exp(x*i*pi)
 'expm1': ['primitive', [lambda x, y: mp.expm1(x), None]],  #exp(x)-1
 'power': ['primitive', [lambda x, y: mp.power(x, y[0]), None]],
 'powm1': ['primitive', [lambda x, y: mp.powm1(x, y[0]),
                         None]],  #pow(x, y) - 1 
 'log': [
     'primitive',
     [lambda x, y: mp.log(x) if y is None else mp.log(x, y[0]), None]
 ],
 'ln': ['primitive', [lambda x, y: mp.ln(x), None]],
 'log10': ['primitive', [lambda x, y: mp.log10(x), None]],
 #
 'lambertw': [
     'primitive',
     [
         lambda x, y: mp.lambertw(x)
         if y is None else mp.lambertw(x, y[0]), None
Esempio n. 23
0
 def _genexpon_invcdf_rootfunc(z):
     return s*z + r*mpmath.expm1(-c*z) - y
Esempio n. 24
0
def I(v, T):
    k = ((2 * sc.h / (sc.c**2))) * (v**3)
    d = (1 / (mpmath.expm1((sc.h * v / (sc.k * T)))))
    return mpmath.mpf(k * d)