Exemplo n.º 1
0
    def testExploitativeProbabilisticInterleaveInterleave(self):
        r1 = ProbabilisticRankingFunction(1, self.weights_1)
        r2 = ProbabilisticRankingFunction(1, self.weights_2)
        epi = ExploitativeProbabilisticInterleave("--exploration_rate=0.5")
        r1.init_ranking(self.query)
        r2.init_ranking(self.query)
        (l, (r1_ret, r2_ret)) = epi.interleave(r1, r2, self.query, 4)
        self.assertEqual(r1, r1_ret, "r1 is just passed through.")
        self.assertEqual(r2, r2_ret, "r2 is just passed through.")
        self.assertEqual(len(l), 4, "interleave produces a list of length 4.")
        self.assertTrue(0 in l, "document 0 is in l.")
        self.assertTrue(1 in l, "document 0 is in l.")
        self.assertTrue(2 in l, "document 0 is in l.")
        self.assertTrue(3 in l, "document 0 is in l.")

        observed_l = {}
        for _ in range(0, 100):
            (l, (r1_ret, r2_ret)) = epi.interleave(r1, r2, self.query, 4)
            l_str = " ".join([str(docid) for docid in l])
            if not l_str in observed_l:
                observed_l[l_str] = 1
            else:
                observed_l[l_str] += 1
        self.assertIn("0 1 2 3", observed_l, "List was observed: 0 1 2 3.")
        self.assertIn("1 0 3 2", observed_l, "List was observed: 0 1 2 3.")
        self.assertIn("3 1 2 0", observed_l, "List was observed: 0 1 2 3.")
        self.assertIn("2 1 0 3", observed_l, "List was observed: 0 1 2 3.")
Exemplo n.º 2
0
    def testExploitativeProbabilisticInterleaveInterleave(self):
        r1 = ProbabilisticRankingFunction(1, self.weights_1)
        r2 = ProbabilisticRankingFunction(1, self.weights_2)
        epi = ExploitativeProbabilisticInterleave("--exploration_rate=0.5")
        r1.init_ranking(self.query)
        r2.init_ranking(self.query)
        (l, (r1_ret, r2_ret)) = epi.interleave(r1, r2, self.query, 4)
        self.assertEqual(r1, r1_ret, "r1 is just passed through.")
        self.assertEqual(r2, r2_ret, "r2 is just passed through.")
        self.assertEqual(len(l), 4, "interleave produces a list of length 4.")
        self.assertTrue(0 in l, "document 0 is in l.")
        self.assertTrue(1 in l, "document 0 is in l.")
        self.assertTrue(2 in l, "document 0 is in l.")
        self.assertTrue(3 in l, "document 0 is in l.")

        observed_l = {}
        for _ in range(0, 100):
            (l, (r1_ret, r2_ret)) = epi.interleave(r1, r2, self.query, 4)
            l_str = " ".join([str(docid) for docid in l])
            if not l_str in observed_l:
                observed_l[l_str] = 1
            else:
                observed_l[l_str] += 1
        self.assertIn("0 1 2 3", observed_l, "List was observed: 0 1 2 3.")
        self.assertIn("1 0 3 2", observed_l, "List was observed: 0 1 2 3.")
        self.assertIn("3 1 2 0", observed_l, "List was observed: 0 1 2 3.")
        self.assertIn("2 1 0 3", observed_l, "List was observed: 0 1 2 3.")
Exemplo n.º 3
0
 def testExploitativeProbabilisticInterleave(self):
     r1 = ProbabilisticRankingFunction(1, self.weights_1)
     r2 = ProbabilisticRankingFunction(1, self.weights_2)
     r1.init_ranking(self.query)
     r2.init_ranking(self.query)
     epi = ExploitativeProbabilisticInterleave("--exploration_rate=0.5")
     (docids, probs) = epi._get_document_distribution(r1, r2)
     exp_docids = [1, 0, 3, 2]
     exp_probs = [0.36, 0.3, 0.2, 0.14]
     self._prob_doc_test_helper(docids, exp_docids, probs, exp_probs)
Exemplo n.º 4
0
 def testExploitativeProbabilisticInterleave(self):
     r1 = ProbabilisticRankingFunction(1, self.weights_1)
     r2 = ProbabilisticRankingFunction(1, self.weights_2)
     r1.init_ranking(self.query)
     r2.init_ranking(self.query)
     epi = ExploitativeProbabilisticInterleave("--exploration_rate=0.5")
     (docids, probs) = epi._get_document_distribution(r1, r2)
     exp_docids = [1, 0, 3, 2]
     exp_probs = [0.36, 0.3, 0.2, 0.14]
     self._prob_doc_test_helper(docids, exp_docids, probs, exp_probs)
Exemplo n.º 5
0
 def testExploitativeProbabilisticInterleaveTwoDocs(self):
     # prepare rankers
     r1 = ProbabilisticRankingFunction(1, self.weights_1)
     r2 = ProbabilisticRankingFunction(1, self.weights_2)
     r1.init_ranking(self.query)
     r2.init_ranking(self.query)
     r1.rm_document(1)
     r2.rm_document(1)
     r1.rm_document(3)
     r2.rm_document(3)
     # test after 1 and 3 were removed
     epi = ExploitativeProbabilisticInterleave("--exploration_rate=0.5")
     (docids, probs) = epi._get_document_distribution(r1, r2)
     exp_docids = [0, 2]
     exp_probs = [0.61428571, 0.38571429]
     self._prob_doc_test_helper(docids, exp_docids, probs, exp_probs)
Exemplo n.º 6
0
 def testExploitativeProbabilisticInterleaveTwoDocs(self):
     # prepare rankers
     r1 = ProbabilisticRankingFunction(1, self.weights_1)
     r2 = ProbabilisticRankingFunction(1, self.weights_2)
     r1.init_ranking(self.query)
     r2.init_ranking(self.query)
     r1.rm_document(1)
     r2.rm_document(1)
     r1.rm_document(3)
     r2.rm_document(3)
     # test after 1 and 3 were removed
     epi = ExploitativeProbabilisticInterleave("--exploration_rate=0.5")
     (docids, probs) = epi._get_document_distribution(r1, r2)
     exp_docids = [0, 2]
     exp_probs = [0.61428571, 0.38571429]
     self._prob_doc_test_helper(docids, exp_docids, probs, exp_probs)
Exemplo n.º 7
0
 def testExploitativeProbabilisticInterleaveExploit(self):
     r1 = ProbabilisticRankingFunction(1, self.weights_1)
     r2 = ProbabilisticRankingFunction(1, self.weights_2)
     # exploration rate = 0.1
     epi = ExploitativeProbabilisticInterleave("--exploration_rate=0.1")
     r1.init_ranking(self.query)
     r2.init_ranking(self.query)
     (docids, probs) = epi._get_document_distribution(r1, r2)
     exp_docids = [1, 3, 2, 0]
     exp_probs = [0.456, 0.232, 0.156, 0.156]
     self._prob_doc_test_helper(docids, exp_docids, probs, exp_probs)
     # exploration rate = 0.0
     epi = ExploitativeProbabilisticInterleave("--exploration_rate=0.0")
     r1.init_ranking(self.query)
     r2.init_ranking(self.query)
     (docids, probs) = epi._get_document_distribution(r1, r2)
     exp_docids = [1, 3, 2, 0]
     exp_probs = [0.48, 0.24, 0.16, 0.12]
     self._prob_doc_test_helper(docids, exp_docids, probs, exp_probs)
Exemplo n.º 8
0
 def testExploitativeProbabilisticInterleaveExploit(self):
     r1 = ProbabilisticRankingFunction(1, self.weights_1)
     r2 = ProbabilisticRankingFunction(1, self.weights_2)
     # exploration rate = 0.1
     epi = ExploitativeProbabilisticInterleave("--exploration_rate=0.1")
     r1.init_ranking(self.query)
     r2.init_ranking(self.query)
     (docids, probs) = epi._get_document_distribution(r1, r2)
     exp_docids = [1, 3, 2, 0]
     exp_probs = [0.456, 0.232, 0.156, 0.156]
     self._prob_doc_test_helper(docids, exp_docids, probs, exp_probs)
     # exploration rate = 0.0
     epi = ExploitativeProbabilisticInterleave("--exploration_rate=0.0")
     r1.init_ranking(self.query)
     r2.init_ranking(self.query)
     (docids, probs) = epi._get_document_distribution(r1, r2)
     exp_docids = [1, 3, 2, 0]
     exp_probs = [0.48, 0.24, 0.16, 0.12]
     self._prob_doc_test_helper(docids, exp_docids, probs, exp_probs)
Exemplo n.º 9
0
 def testExploitativeProbabilisticInterleaveThreeDocs(self):
     epi = ExploitativeProbabilisticInterleave("--exploration_rate=0.5")
     # prepare rankers
     r1 = ProbabilisticRankingFunction(1, self.weights_1)
     r2 = ProbabilisticRankingFunction(1, self.weights_2)
     r1.init_ranking(self.query)
     r2.init_ranking(self.query)
     r1.rm_document(0)
     r2.rm_document(0)
     # test after document 0 was removed
     (docids, probs) = epi._get_document_distribution(r1, r2)
     exp_docids = [1, 3, 2]
     exp_probs = [0.5034965, 0.29020979, 0.20629371]
     self._prob_doc_test_helper(docids, exp_docids, probs, exp_probs)
     # prepare rankers
     r1.init_ranking(self.query)
     r2.init_ranking(self.query)
     r1.rm_document(3)
     r2.rm_document(3)
     # test after document 3 was removed
     (docids, probs) = epi._get_document_distribution(r1, r2)
     exp_docids = [1, 0, 2]
     exp_probs = [0.45864662, 0.36466165, 0.17669173]
     self._prob_doc_test_helper(docids, exp_docids, probs, exp_probs)
Exemplo n.º 10
0
 def testExploitativeProbabilisticInterleaveThreeDocs(self):
     epi = ExploitativeProbabilisticInterleave("--exploration_rate=0.5")
     # prepare rankers
     r1 = ProbabilisticRankingFunction(1, self.weights_1)
     r2 = ProbabilisticRankingFunction(1, self.weights_2)
     r1.init_ranking(self.query)
     r2.init_ranking(self.query)
     r1.rm_document(0)
     r2.rm_document(0)
     # test after document 0 was removed
     (docids, probs) = epi._get_document_distribution(r1, r2)
     exp_docids = [1, 3, 2]
     exp_probs = [0.5034965, 0.29020979, 0.20629371]
     self._prob_doc_test_helper(docids, exp_docids, probs, exp_probs)
     # prepare rankers
     r1.init_ranking(self.query)
     r2.init_ranking(self.query)
     r1.rm_document(3)
     r2.rm_document(3)
     # test after document 3 was removed
     (docids, probs) = epi._get_document_distribution(r1, r2)
     exp_docids = [1, 0, 2]
     exp_probs = [0.45864662, 0.36466165, 0.17669173]
     self._prob_doc_test_helper(docids, exp_docids, probs, exp_probs)