Ejemplo n.º 1
0
 def test_log_pdf_array_dimension(self):
     d = 3
     n = 2
     ps = asarray(rand(d))
     b = Bernoulli(ps)
     X = randint(0, 2, (n, d)).astype(numpy.bool8)
     self.assertEqual(b.log_pdf(X).shape, (n, ))
Ejemplo n.º 2
0
    def test_log_pdf_success_multiple(self):
        d = 4
        n = 3
        num_runs = 100

        for _ in range(num_runs):
            ps = rand(d)
            b = Bernoulli(ps)
            X = randint(0, 2, (n, d)).astype(numpy.bool8)

            # naive computation of log pdf
            expected = zeros((n, d))
            for i in range(n):
                for j in range(d):
                    expected[i,
                             j] = log(ps[j]) if X[i,
                                                  j] == 1 else log(1 - ps[j])

            self.assertTrue(all(sum(expected, 1) == b.log_pdf(X)))
Ejemplo n.º 3
0
 def test_log_pdf_failure_single(self):
     d = 1
     ps = asarray(rand(d))
     b = Bernoulli(ps)
     X = asarray([[0]], dtype=numpy.bool8)
     self.assertEqual(b.log_pdf(X), log(1 - ps[0]))
Ejemplo n.º 4
0
 def test_log_pdf_type(self):
     p = asarray([0.3])
     b = Bernoulli(p)
     self.assertEqual(type(b.log_pdf(asarray([[1]], dtype=numpy.bool8))),
                      numpy.ndarray)