示例#1
0
 def test_log_probability_FiniteWithBVArgs(self):
     # import the grammar
     from Grammars import FiniteWithBVArgs
     self.G = FiniteWithBVArgs.g
     # sample from G 100 times
     for i in range(100):
         t = self.G.generate('START')
         # count probability manually
         prob = FiniteWithBVArgs.log_probability(t)
         # print t, prob, t.log_probability(), prob - t.log_probability()
         # check that it's equal to .log_probability()
         self.assertTrue(math.fabs(prob - t.log_probability()) < 0.00000001)
示例#2
0
 def test_log_probability_proposals_FiniteWithBVArgs(self):
     # import the grammar
     from Grammars import FiniteWithBVArgs
     self.G = FiniteWithBVArgs.g
     # the RegenerationProposal class
     rp = RegenerationProposal(self.G)
     # sample from G 100 times
     for i in range(100):
         X = self.G.generate('START')
         # propose to a new tree
         Y = rp.propose_tree(X)[0]
         # count probability manually
         prob = FiniteWithBVArgs.log_probability(Y)
         # print "iteration", i, X, Y, prob, Y.log_probability(), prob - Y.log_probability()
         # check that it's equal to .log_probability()
         self.assertTrue(math.fabs(prob - Y.log_probability()) < 0.00000001)