Пример #1
0
 def test_basic_behaviour(self):
     below_threshold = om.optimal_matching(['a'], ['b'], lambda x, y: 10,
                                           lambda x: 15, 11)
     self.assertEqual({
         'lhs': {
             'a': 'b'
         },
         'rhs': {
             'b': 'a'
         }
     }, below_threshold)
     above_threshold = om.optimal_matching(['a'], ['b'], lambda x, y: 10,
                                           lambda x: 15, 9)
     self.assertEqual({
         'lhs': {
             'a': None
         },
         'rhs': {
             'b': None
         }
     }, above_threshold)
     without_threshold = om.optimal_matching(['a'], ['b'], lambda x, y: 10,
                                             lambda x: 15, None)
     self.assertEqual({
         'lhs': {
             'a': 'b'
         },
         'rhs': {
             'b': 'a'
         }
     }, below_threshold)
 def test_basic_behaviour( self ):
     below_threshold = om.optimal_matching(['a'], ['b'], lambda x,y: 10, lambda x: 15, 11)
     self.assertEqual({'lhs': {'a': 'b'}, 'rhs': {'b': 'a'}}, below_threshold)
     above_threshold = om.optimal_matching(['a'], ['b'], lambda x,y: 10, lambda x: 15, 9)
     self.assertEqual({'lhs': {'a': None}, 'rhs': {'b': None}}, above_threshold)
     without_threshold = om.optimal_matching(['a'], ['b'], lambda x,y: 10, lambda x: 15, None)
     self.assertEqual({'lhs': {'a': 'b'}, 'rhs': {'b': 'a'}}, below_threshold)
 def runTest( self ):
     def cost_fct(x, y):
         table = {'a': {}, 'b': {}}
         table['a']['d'] = 3
         table['a']['c'] = 1
         table['b']['c'] = 2
         table['b']['d'] = 5
         return table[x][y]
     assoc = om.optimal_matching(['a','b'], ['c', 'd'], cost_fct, lambda x: 10)
     expected = {'lhs': {'a': 'd', 'b': 'c'}, 'rhs': {'d': 'a', 'c': 'b'}}
     self.assertEqual(assoc, expected)
Пример #4
0
    def runTest(self):
        def cost_fct(x, y):
            table = {'a': {}, 'b': {}}
            table['a']['d'] = 3
            table['a']['c'] = 1
            table['b']['c'] = 2
            table['b']['d'] = 5
            return table[x][y]

        assoc = om.optimal_matching(['a', 'b'], ['c', 'd'], cost_fct,
                                    lambda x: 10)
        expected = {'lhs': {'a': 'd', 'b': 'c'}, 'rhs': {'d': 'a', 'c': 'b'}}
        self.assertEqual(assoc, expected)
Пример #5
0
def optimal_matching( lhs, rhs, nonmatch_threshold=30):
    '''Associate two sets of tracklets using globally optimal nearest neighbor matching.

    Returns a dictionary of associations of the form:
    {'lhs': {lhs_instance: rhs_instance}, 'rhs': {rhs_instance: lhs_instance}}

    In case of a nonmatch, the instance is associated with None.

    lhs, rhs -- iterable of unique Tracklet instances 
    nonmatch_threshold -- distance threshold; below are potential matching partners

    '''
    # In case of euclidean distance based nearest neighbor matching, the nonmatch_cost is equivalent
    # with a hard distance cutoff; therefore we set the cutoff to almost the nonmatch_cost. We shouldn't
    # set it exactly to the cost, because there may be problems if some match cost has exactly the value of
    # the nonmatch cost. We better give the optimization scheme some room to breathe.
    match =  _om.optimal_matching( lhs, rhs, Tracklet.distance, lambda x: nonmatch_threshold, nonmatch_threshold + 1)
    return match
Пример #6
0
def optimal_matching( lhs, rhs, nonmatch_threshold=30):
    '''Associate two sets of tracklets using globally optimal nearest neighbor matching.

    Returns a dictionary of associations of the form:
    {'lhs': {lhs_instance: rhs_instance}, 'rhs': {rhs_instance: lhs_instance}}

    In case of a nonmatch, the instance is associated with None.

    lhs, rhs -- iterable of unique Tracklet instances 
    nonmatch_threshold -- distance threshold; below are potential matching partners

    '''
    # In case of euclidean distance based nearest neighbor matching, the nonmatch_cost is equivalent
    # with a hard distance cutoff; therefore we set the cutoff to almost the nonmatch_cost. We shouldn't
    # set it exactly to the cost, because there may be problems if some match cost has exactly the value of
    # the nonmatch cost. We better give the optimization scheme some room to breathe.
    match =  _om.optimal_matching( lhs, rhs, Tracklet.distance, lambda x: nonmatch_threshold, nonmatch_threshold + 1)
    return match
Пример #7
0
 def test_vertices_without_edges(self):
     no_edges = om.optimal_matching(['a'], ['b'], lambda x, y: 20,
                                    lambda x: 15, 10)
     self.assertEqual({'lhs': {'a': None}, 'rhs': {'b': None}}, no_edges)
Пример #8
0
 def test_both_empty(self):
     assoc = om.optimal_matching([], [], lambda x, y: 0, lambda x: 0)
     self.assertEqual(assoc, {'lhs': {}, 'rhs': {}})
Пример #9
0
 def test_empty_rhs(self):
     assoc = om.optimal_matching([1, 2], [], lambda x, y: 0, lambda x: 0)
     expected = {'lhs': {1: None, 2: None}, 'rhs': {}}
     self.assertEqual(assoc, expected)
 def test_vertices_without_edges( self ):
     no_edges = om.optimal_matching(['a'], ['b'], lambda x,y: 20, lambda x: 15, 10)
     self.assertEqual({'lhs': {'a': None}, 'rhs': {'b': None}}, no_edges)
 def test_both_empty(self):
     assoc = om.optimal_matching([], [], lambda x,y: 0, lambda x: 0)
     self.assertEqual(assoc, {'lhs': {}, 'rhs': {}})
 def test_empty_rhs(self):
     assoc = om.optimal_matching([1,2], [], lambda x,y: 0, lambda x: 0)
     expected = {'lhs': {1: None, 2: None}, 'rhs': {}}
     self.assertEqual(assoc, expected)