예제 #1
0
    def test_add(self):
        binomial_one = Binomial(.4, 20)
        binomial_two = Binomial(.4, 60)
        binomial_sum = binomial_one + binomial_two

        self.assertEqual(binomial_sum.p, .4)
        self.assertEqual(binomial_sum.n, 80)
예제 #2
0
    def __add__(self, other):
        """Function to add together two Binomial distributions with equal p

        Args:
            other (Binomial): Binomial instance

        Returns:
            Binomial: Binomial distribution

        """

        try:
            assert self.p == other.p, 'p values are not equal'
        except AssertionError as error:
            raise ValueError('p values must be equal')

        # TODO: Define addition for two binomial distributions. Assume that the
        # p values of the two distributions are the same. The formula for
        # summing two binomial distributions with different p values is more complicated,
        # so you are only expected to implement the case for two distributions with equal p.

        # the try, except statement above will raise an exception if the p values are not equal

        # Hint: You need to instantiate a new binomial object with the correct n, p,
        #   mean and standard deviation values. The __add__ method should return this
        #   new binomial object.

        #   When adding two binomial distributions, the p value remains the same
        #   The new n value is the sum of the n values of the two distributions.

        size_new = self.n + other.n
        return Binomial(size=size_new, prob=self.p)
예제 #3
0
    def test_init_with_errors(self):
        params = ((None, None, None), (1.2, None, None), (-1, None, None),
                  (-1.2, None, None), (3, None, None), (3, 1.2, None),
                  (3, -1, None), (3, 5, None), (3, 5, -2), (3, 5, -1.2),
                  ('some', 5, 0.85), (5, 'string', 0.85), (5, 10,
                                                           'some'), (3, 5, 2))

        for param in params:
            with self.assertRaises(ValueError):
                Binomial(*param)
예제 #4
0
 def setUp(self):
     self.binomial = Binomial(0.4, 20)
     self.binomial.read_data_file('numbers_binomial.txt')
예제 #5
0
 def setUp(self):
     self.binomial = Binomial('numbers_binomial.txt')
예제 #6
0
 def setUp(self):
     self.distribution = Binomial(3, 5, 0.85)
예제 #7
0
from distributions import Binomial

binomial_one = Binomial()
binomial_one.read_data_file('numbers_binomial.txt')
binomial_one.replace_stats_with_data()
binomial_one.plot_bar()
binomial_one.plot_bar_pdf()