Exemplo n.º 1
0
def clevy(scale, x):
    """
    The cdf of the Levy distribution (stable distribution with 
    alpha = 1/2 and beta = 1, aka the Cournot distribution). 
    This is actually the right-skewed Levy!
    f = sqrt(s/2pi) * (1/x)**(3/2) * exp(-s/2x)
    F = erfc(sqrt(s/2x))
    
    s >= 0.0, x >= 0
    """

    assert scale >= 0.0, "scale must not be negative in clevy!"
    assert x >= 0.0, "variate must not be negative in clevy!"

    # The cdf of the Levy can be handled since it is an "incomplete gamma
    # function", but it seems to be more simple than that:

    try:
        cdf = erfc1(sqrt(0.5 * scale / x))
    except (OverflowError, ZeroDivisionError):
        return 0.0

    cdf = kept_within(0.0, cdf, 1.0)

    return cdf
Exemplo n.º 2
0
def clevy(scale, x):
    """
    The cdf of the Levy distribution (stable distribution with 
    alpha = 1/2 and beta = 1, aka the Cournot distribution). 
    This is actually the right-skewed Levy!
    f = sqrt(s/2pi) * (1/x)**(3/2) * exp(-s/2x)
    F = erfc(sqrt(s/2x))
    
    s >= 0.0, x >= 0
    """

    assert scale >= 0.0, "scale must not be negative in clevy!"
    assert x >= 0.0, "variate must not be negative in clevy!"

    # The cdf of the Levy can be handled since it is an "incomplete gamma
    # function", but it seems to be more simple than that:

    try:
        cdf = erfc1(sqrt(0.5 * scale / x))
    except (OverflowError, ZeroDivisionError):
        return 0.0

    cdf = kept_within(0.0, cdf, 1.0)

    return cdf


# end of clevy

# ------------------------------------------------------------------------------
Exemplo n.º 3
0
def cnormal(mu, sigma, x):
    """
    cdf for the normal (Gaussian) distribution based on the erfc1 function 
    that offers an estimated maximum fractional error < 50*machine epsilon.
    
    sigma > 0.0
    """

    assert sigma > 0.0, "sigma must be a positive float in cnormal!"

    x = (x - mu) / float(sigma)
    y = SQRT05 * abs(x)
    cdf = 0.5 * erfc1(y)
    if x > 0.0: cdf = 1.0 - cdf

    cdf = kept_within(0.0, cdf, 1.0)

    return cdf
Exemplo n.º 4
0
def cnormal(mu, sigma, x):
    """
    cdf for the normal (Gaussian) distribution based on the erfc1 function 
    that offers an estimated maximum fractional error < 50*machine epsilon.
    
    sigma > 0.0
    """

    assert sigma > 0.0, "sigma must be a positive float in cnormal!"

    x = (x - mu) / float(sigma)
    y = SQRT05 * abs(x)
    cdf = 0.5 * erfc1(y)
    if x > 0.0:
        cdf = 1.0 - cdf

    cdf = kept_within(0.0, cdf, 1.0)

    return cdf