def testHistProbabilisticInterleave(self): r1 = ProbabilisticRankingFunction(3, self.weights_1) r2 = ProbabilisticRankingFunction(3, self.weights_2) hpi = HistProbabilisticInterleave(None) a = ([0, 1, 1, 0], r1, r2) self.assertEqual(hpi.infer_outcome([0, 1, 2, 3], a, [0, 0, 0, 0], r1, r2, self.query), 0, "No clicks, outcome should be 0.") o = hpi.infer_outcome([1, 0, 3, 2], a, [1, 0, 0, 0], r1, r2, self.query) self.assertAlmostEquals(o, -0.0486, 4, "Same target as original " "rankers. Ranker 1 should win (o = %.4f)." % o) o = hpi.infer_outcome([1, 0, 3, 2], a, [1, 0, 0, 0], r2, r1, self.query) self.assertAlmostEquals(o, 0.0486, 4, "Target rankers switched. " "Ranker 2 should win (o = %.4f)." % o) test_r1 = ProbabilisticRankingFunction(3, self.weights_1) a = ([0, 1, 1, 0], r1, test_r1) o = hpi.infer_outcome([1, 0, 3, 2], a, [1, 0, 0, 0], r2, r1, self.query) self.assertAlmostEquals(o, 0.1542, 4, "Same original ranker. " "Ranker 2 should win (o = %.4f)." % o)
def testHistProbabilisticInterleaveWithoutMarginalization(self): r1 = ProbabilisticRankingFunction(3, self.weights_1) r2 = ProbabilisticRankingFunction(3, self.weights_2) hpiIs = HistProbabilisticInterleave("--biased False " "--marginalize False") # test get_probability_of_list_and_assignment p = hpiIs._get_probability_of_list_and_assignment([1, 3, 2, 0], [0, 0, 0, 0], r1, r2, self.query) self.assertAlmostEqual(p, 0.026261, 6, "Most likely list for ranker 1." " p = %e" % p) # test overall outcomes a = ([0, 1, 1, 0], r1, r2) self.assertEqual( hpiIs.infer_outcome([0, 1, 2, 3], a, [0, 0, 0, 0], r1, r2, self.query), 0, "No clicks, outcome should be 0.") o = hpiIs.infer_outcome([1, 0, 3, 2], a, [1, 0, 0, 0], r1, r2, self.query) self.assertEquals( o, -1, "Same original and target pair. " "Ranker 1 should win (o = %d)." % o) test_r1 = ProbabilisticRankingFunction(3, self.weights_1) a = ([0, 1, 1, 0], r1, test_r1) o = hpiIs.infer_outcome([1, 0, 3, 2], a, [1, 0, 0, 0], r2, r1, self.query) self.assertAlmostEquals( o, -0.1250, 4, "Different original pair. " "Ranker 1 should win (o = %.4f)." % o)
def testHistProbabilisticInterleave(self): r1 = ProbabilisticRankingFunction(3, self.weights_1) r2 = ProbabilisticRankingFunction(3, self.weights_2) hpi = HistProbabilisticInterleave(None) a = ([0, 1, 1, 0], r1, r2) self.assertEqual( hpi.infer_outcome([0, 1, 2, 3], a, [0, 0, 0, 0], r1, r2, self.query), 0, "No clicks, outcome should be 0.") o = hpi.infer_outcome([1, 0, 3, 2], a, [1, 0, 0, 0], r1, r2, self.query) self.assertAlmostEquals( o, -0.0486, 4, "Same target as original " "rankers. Ranker 1 should win (o = %.4f)." % o) o = hpi.infer_outcome([1, 0, 3, 2], a, [1, 0, 0, 0], r2, r1, self.query) self.assertAlmostEquals( o, 0.0486, 4, "Target rankers switched. " "Ranker 2 should win (o = %.4f)." % o) test_r1 = ProbabilisticRankingFunction(3, self.weights_1) a = ([0, 1, 1, 0], r1, test_r1) o = hpi.infer_outcome([1, 0, 3, 2], a, [1, 0, 0, 0], r2, r1, self.query) self.assertAlmostEquals( o, 0.1542, 4, "Same original ranker. " "Ranker 2 should win (o = %.4f)." % o)
def testHistProbabilisticInterleaveWithoutMarginalization(self): r1 = ProbabilisticRankingFunction(3, self.weights_1) r2 = ProbabilisticRankingFunction(3, self.weights_2) hpiIs = HistProbabilisticInterleave("--biased False " "--marginalize False") # test get_probability_of_list_and_assignment p = hpiIs._get_probability_of_list_and_assignment([1, 3, 2, 0], [0, 0, 0, 0], r1, r2, self.query) self.assertAlmostEqual(p, 0.026261, 6, "Most likely list for ranker 1." " p = %e" % p) # test overall outcomes a = ([0, 1, 1, 0], r1, r2) self.assertEqual(hpiIs.infer_outcome([0, 1, 2, 3], a, [0, 0, 0, 0], r1, r2, self.query), 0, "No clicks, outcome should be 0.") o = hpiIs.infer_outcome([1, 0, 3, 2], a, [1, 0, 0, 0], r1, r2, self.query) self.assertEquals(o, -1, "Same original and target pair. " "Ranker 1 should win (o = %d)." % o) test_r1 = ProbabilisticRankingFunction(3, self.weights_1) a = ([0, 1, 1, 0], r1, test_r1) o = hpiIs.infer_outcome([1, 0, 3, 2], a, [1, 0, 0, 0], r2, r1, self.query) self.assertAlmostEquals(o, -0.1250, 4, "Different original pair. " "Ranker 1 should win (o = %.4f)." % o)