def test_bayes(self): self.assertTrue(math.isnan(smooth.bayes(0, 0, 0, 0, 0))) self.assertAlmostEquals(smooth.bayes(10, 100, 20, 500, 0.1), .0999, 4) self.assertAlmostEquals(smooth.bayes(10, 100, 20, 500, 0.5), .0997, 4) self.assertEquals(smooth.bayes(1, 1, 1, 1, 1), 1) self.assertAlmostEquals(smooth.bayes(0, 100, 20, 500, 0.1), 0.000999000999 * (20/500))
def test_bayes(self): self.__init_test(test.SMALL_DEL_FILE) smooth_func = 'Bayes' lamb = 0.3 p = SmoothEstimator(smooth_func, lamb, self.annots, 1) prob_i0_t0 = bayes(2, 5, 3, 10, lamb) prob_i0_t1 = bayes(1, 5, 3, 10, lamb) prob_i0_t2 = bayes(0, 5, 1, 10, lamb) prob_i0_t3 = bayes(1, 5, 1, 10, lamb) prob_i0_t4 = bayes(1, 5, 1, 10, lamb) prob_i0_t5 = bayes(0, 5, 1, 10, lamb) self.assertAlmostEquals(p.prob_tag_given_item(0, 0), prob_i0_t0) self.assertAlmostEquals(p.prob_tag_given_item(0, 1), prob_i0_t1) self.assertAlmostEquals(p.prob_tag_given_item(0, 2), prob_i0_t2) self.assertAlmostEquals(p.prob_tag_given_item(0, 3), prob_i0_t3) self.assertAlmostEquals(p.prob_tag_given_item(0, 4), prob_i0_t4) self.assertAlmostEquals(p.prob_tag_given_item(0, 5), prob_i0_t5)