Ejemplo n.º 1
0
    def poisson_pmf(k, the_lambda):
        """
           Gives the value of the Poisson probability mass function
           for the given k (k can be a whole, nonnrgative nuber)
           and the specified parameter of the Poisson distribution-
           the_lambda must be > 0.
        """
        if the_lambda <= 0:
            raise IncorrectInputError()

        A = math.pow(the_lambda, k)
        B = math.exp(-the_lambda)
        C = functions.factorial(k)
        return A*B/C
Ejemplo n.º 2
0
    def poisson_cdf(k, the_lambda):
        """
           Gives the value of the Poisson cumulative density function
           for the given k (k can be a whole, nonnrgative nuber)
           and the specified parameter of the Poisson distribution-
           the_lambda must be > 0.
        """
        if the_lambda <= 0:
            raise IncorrectInputError()

        A = math.exp(-the_lambda)
        index = functions.floor_function(k)
        summation = 0
        for i in range(index+1):
            summation += math.pow(the_lambda, i)/functions.factorial(i)
        return A*summation
Ejemplo n.º 3
0
    def test_input(self):
        string = "asd"
        invalid_float = 7.15
        invalid_int = -5

        with self.assertRaises(functions.IncorrectInputError):
            functions.factorial(string)
        with self.assertRaises(functions.IncorrectInputError):
            functions.factorial(invalid_float)
        with self.assertRaises(functions.IncorrectInputError):
            functions.factorial(invalid_int)
Ejemplo n.º 4
0
    def test_results(self):
        valid_float = 7.0
        valid_int = 4

        self.assertEqual(5040, functions.factorial(valid_float))
        self.assertEqual(24, functions.factorial(valid_int))
Ejemplo n.º 5
0
    def test_zero(self):
        zero = 0

        self.assertEqual(1, functions.factorial(zero))