Exemplo n.º 1
0
    def test_pdf(self):
        # Calculate standard normal pdf for x=1
        a = pdf(1)
        self.assertAlmostEqual(a, 0.24197072451914337)

        # Calculate standard normal pdf for x=(-1)
        a = pdf(-1)
        self.assertAlmostEqual(a, 0.24197072451914337)

        # Calculate standard normal pdf for x=13, mean=10, std_dev=1
        a = pdf(x=13, mean=10, std_dev=1)
        self.assertAlmostEqual(a, 0.004431848411938008)
Exemplo n.º 2
0
    def test_pdf(self):
        # Calculate standard normal pdf for x=1
        a = pdf(1)
        self.assertAlmostEqual(a, 0.24197072451914337)

        # Calculate standard normal pdf for x=(-1)
        a = pdf(-1)
        self.assertAlmostEqual(a, 0.24197072451914337)

        # Calculate standard normal pdf for x=13, mean=10, std_dev=1
        a = pdf(x=13, mean=10, std_dev=1)
        self.assertAlmostEqual(a, 0.004431848411938008)
Exemplo n.º 3
0
def cdf(x, iterations=300):

    product = 1.0
    taylor_exp = [x]
    for i in range(3, iterations, 2):
        product *= i
        taylor_exp.append(float(x**i) / product)
    taylor_fact = sum(taylor_exp)

    return (0.5 + (taylor_fact * std_normal_pdf.pdf(x, mean=0, std_dev=1)))
Exemplo n.º 4
0
def cdf(x, iterations=300):

    product = 1.0
    taylor_exp = [x]
    for i in range(3, iterations, 2):
        product *= i
        taylor_exp.append(float(x**i)/product)
    taylor_fact = sum(taylor_exp)

    return (0.5 + (taylor_fact * std_normal_pdf.pdf(x, mean=0, std_dev=1)))
Exemplo n.º 5
0
def mth_operations_1_input(f_code, v):
    if f_code == 1:
        res = approx_cdf.cdf(v)
        return res
    elif f_code == 4:
        res = primality_test.is_prime(v)
        return res
    elif f_code == 5:
        res = sieve_atkin.atkin(v)
        return res
    elif f_code == 6:
        res = sieve_eratosthenes.eratosthenes(v)
        return res
    elif f_code == 7:
        res = std_normal_pdf.pdf(v)
        return res
Exemplo n.º 6
0
def cdf(x, iterations=300):
    """
    Calculates the cumulative distribution function of the normal distribution.
    Uses a taylor exponent to calculate this.

    :param x: An integer that represents the taylor exponent.
    :param iterations: An integer representing the number of iterations.
    :rtype: The normal distribution
    """
    product = 1.0
    taylor_exp = [x]
    for i in range(3, iterations, 2):
        product *= i
        taylor_exp.append(float(x**i)/product)
    taylor_fact = sum(taylor_exp)

    return 0.5 + (taylor_fact * std_normal_pdf.pdf(x, mean=0, std_dev=1))
Exemplo n.º 7
0
def cdf(x, iterations=300):
    """
    Calculates the cumulative distribution function of the normal distribution.
    Uses a taylor exponent to calculate this.

    :param x: An integer that represents the taylor exponent.
    :param iterations: An integer representing the number of iterations.
    :rtype: The normal distribution
    """
    product = 1.0
    taylor_exp = [x]
    for i in range(3, iterations, 2):
        product *= i
        taylor_exp.append(float(x**i)/product)
    taylor_fact = sum(taylor_exp)

    return (0.5 + (taylor_fact * std_normal_pdf.pdf(x, mean=0, std_dev=1)))