def test_log_probability_FiniteWithoutBVs(self): # import the grammar from Grammars import FiniteWithoutBVs self.G = FiniteWithoutBVs.g # sample from G 100 times for i in range(100): t = self.G.generate('START') # count probability manually prob = FiniteWithoutBVs.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)
def test_log_probability_proposals_FiniteWithoutBVs(self): # import the grammar from Grammars import FiniteWithoutBVs self.G = FiniteWithoutBVs.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 = FiniteWithoutBVs.log_probability(Y) # print 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)