示例#1
0
 def test_bayes(self):
     mu = Dirichlet(concentration=np.ones(3))
     model = Categorical(prob=mu)
     self.assertEqual(
         repr(model),
         "Categorical(prob=\nDirichlet(concentration=[ 1.  1.  1.])\n)")
     model.bayes(np.array([[1., 0., 0.], [1., 0., 0.], [0., 1., 0.]]))
     self.assertEqual(
         repr(model),
         "Categorical(prob=\nDirichlet(concentration=[ 3.  2.  1.])\n)")
示例#2
0
 def test_init(self):
     c = Categorical()
     self.assertTrue(c.prob is None)
     c = Categorical(np.ones(3) / 3)
     self.assertEqual(c.n_classes, 3)
     self.assertTrue(np.allclose(c.prob, np.ones(3) / 3))
示例#3
0
 def test_draw(self):
     c = Categorical(np.ones(4) / 4)
     self.assertTrue(
         np.allclose(np.mean(c.draw(1000), axis=0), [0.25] * 4, 1e-1, 1e-1))
示例#4
0
 def test_pdf(self):
     c = Categorical(prob=np.ones(4) / 4)
     self.assertTrue((c.pdf(np.eye(4)) == 0.25).all())
示例#5
0
 def test_ml(self):
     c = Categorical()
     c.ml(np.array([[0, 1], [1, 0], [1, 0], [1, 0]]))
     self.assertEqual(c.n_classes, 2)
     self.assertTrue((c.prob == np.array([0.75, 0.25])).all())
示例#6
0
 def test_mean(self):
     c = Categorical(prob=np.ones(4) / 4)
     self.assertTrue((c.mean == c.prob).all())
示例#7
0
 def test_repr(self):
     c = Categorical(prob=np.ones(2) / 2)
     self.assertEqual(repr(c), "Categorical(prob=[ 0.5  0.5])")