Ejemplo n.º 1
0
    def test_simple_iqr_scenario(self):
        # Make some descriptors;
        # Pick some from created set that are close to each other and use as
        #   positive query, picking some other random descriptors as negative
        #   examples.
        # Rank index based on chosen pos/neg
        # Check that positive choices are at the top of the ranking (closest to
        #   0) and negative choices are closest to the bottom.
        iqr_index = LibSvmHikRelevancyIndex()
        iqr_index.build_index(self.index_descriptors)

        rank = iqr_index.rank([self.q_pos], [self.q_neg])
        rank_ordered = sorted(rank.items(), key=lambda e: e[1], reverse=True)

        # Check expected ordering
        # 0-5-1-2-6-3-4
        # - 2 should end up coming before 6, because 6 has more intersection
        #   with the negative example.
        ntools.assert_equal(rank_ordered[0][0], self.d0)
        ntools.assert_equal(rank_ordered[1][0], self.d5)
        ntools.assert_equal(rank_ordered[2][0], self.d1)
        ntools.assert_equal(rank_ordered[3][0], self.d2)
        ntools.assert_equal(rank_ordered[4][0], self.d6)
        ntools.assert_equal(rank_ordered[5][0], self.d3)
        ntools.assert_equal(rank_ordered[6][0], self.d4)
Ejemplo n.º 2
0
        def test_simple_iqr_scenario(self):
            # Make some descriptors;
            # Pick some from created set that are close to each other and use as
            #   positive query, picking some other random descriptors as
            #   negative examples.
            # Rank index based on chosen pos/neg
            # Check that positive choices are at the top of the ranking (closest
            #   to 0) and negative choices are closest to the bottom.
            iqr_index = LibSvmHikRelevancyIndex()
            iqr_index.build_index(self.index_descriptors)

            rank = iqr_index.rank([self.q_pos], [self.q_neg])
            rank_ordered = sorted(rank.items(),
                                  key=lambda e: e[1],
                                  reverse=True)

            print("rank_ordered:")
            for i, r in enumerate(rank_ordered):
                print("..{}: {}".format(i, r))

            # Check expected ordering
            # 0-5-1-2-6-3-4
            # - 2 should end up coming before 6, because 6 has more intersection
            #   with the negative example.
            assert rank_ordered[0][0] == self.d0
            assert rank_ordered[1][0] == self.d5
            assert rank_ordered[2][0] == self.d1
            # Results show that d2 and d6 have the same rank, so their position
            # in interchangeable.
            assert rank_ordered[3][0] in (self.d2, self.d6)
            assert rank_ordered[4][0] in (self.d2, self.d6)
            assert rank_ordered[3][0] != rank_ordered[4][0]
            # d3 and d4 evaluate to the same rank based on query (no
            # intersection with positive, equal intersection with negative).
            assert rank_ordered[5][0] in (self.d3, self.d4)
            assert rank_ordered[6][0] in (self.d3, self.d4)
            assert rank_ordered[5][0] != rank_ordered[6][0]
Ejemplo n.º 3
0
 def test_count(self):
     iqr_index = LibSvmHikRelevancyIndex()
     ntools.assert_equal(iqr_index.count(), 0)
     iqr_index.build_index(self.index_descriptors)
     ntools.assert_equal(iqr_index.count(), 7)
Ejemplo n.º 4
0
 def test_rank_no_input(self):
     iqr_index = LibSvmHikRelevancyIndex()
     iqr_index.build_index(self.index_descriptors)
     ntools.assert_raises(ValueError, iqr_index.rank, [], [])
Ejemplo n.º 5
0
 def test_rank_no_neg(self):
     iqr_index = LibSvmHikRelevancyIndex()
     iqr_index.build_index(self.index_descriptors)
     # index should auto-select some negative examples, thus not raising an
     # exception.
     iqr_index.rank([self.q_pos], [])
Ejemplo n.º 6
0
 def test_rank_no_pos(self):
     iqr_index = LibSvmHikRelevancyIndex()
     iqr_index.build_index(self.index_descriptors)
     self.assertRaises(ValueError, iqr_index.rank, [], [self.q_neg])