Exemple #1
0
 def test_array_b(self):
   b = np.zeros(10, dtype=int)
   b[5:] = 20
   expected = 1 - np.eye(10, dtype=int)
   expected[:5] = 0
   G = b_matching(self.dists, b)
   assert_array_equal(G.matrix('dense').astype(int), expected)
Exemple #2
0
 def test_array_b(self):
     b = np.zeros(10, dtype=int)
     b[5:] = 20
     expected = 1 - np.eye(10, dtype=int)
     expected[:5] = 0
     G = b_matching(self.dists, b)
     assert_array_equal(G.matrix('dense').astype(int), expected)
Exemple #3
0
 def test_oscillation(self):
     # Generated with the bdmatch binary (b=2,damp=1)
     expected = np.array([[0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
                          [0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
                          [0, 0, 0, 0, 1, 0, 0, 0, 1, 0],
                          [1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
                          [0, 0, 0, 0, 0, 0, 1, 0, 0, 1],
                          [0, 0, 0, 0, 0, 0, 0, 1, 1, 0],
                          [0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
                          [1, 0, 0, 0, 0, 1, 0, 0, 0, 0],
                          [0, 0, 1, 0, 0, 1, 0, 0, 0, 0],
                          [0, 0, 0, 0, 1, 0, 1, 0, 0, 0]])
     G = b_matching(self.dists, 2, damping=1)
     assert_array_equal(G.matrix('dense').astype(int), expected)
Exemple #4
0
 def test_standard(self):
     # Generated with the bdmatch binary (b=2,damp=0.5)
     expected = np.array([[0, 1, 0, 1, 0, 0, 0, 1, 0, 0],
                          [1, 0, 0, 1, 0, 0, 0, 0, 0, 0],
                          [0, 0, 0, 0, 1, 0, 1, 0, 1, 0],
                          [1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
                          [0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
                          [0, 0, 0, 0, 0, 0, 0, 1, 1, 0],
                          [0, 0, 1, 0, 0, 0, 0, 0, 0, 1],
                          [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
                          [0, 0, 1, 0, 0, 1, 0, 0, 0, 0],
                          [0, 0, 0, 0, 1, 0, 1, 0, 0, 0]]).T
     G = b_matching(self.dists, 2, damping=0.5)
     assert_array_equal(G.matrix('dense').astype(int), expected)
Exemple #5
0
 def test_oscillation(self):
   # Generated with the bdmatch binary (b=2,damp=1)
   expected = np.array([
       [0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
       [0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
       [0, 0, 0, 0, 1, 0, 0, 0, 1, 0],
       [1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 1, 0, 0, 1],
       [0, 0, 0, 0, 0, 0, 0, 1, 1, 0],
       [0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
       [1, 0, 0, 0, 0, 1, 0, 0, 0, 0],
       [0, 0, 1, 0, 0, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 0, 1, 0, 0, 0]])
   G = b_matching(self.dists, 2, damping=1)
   assert_array_equal(G.matrix('dense').astype(int), expected)
Exemple #6
0
 def test_standard(self):
   # Generated with the bdmatch binary (b=2,damp=0.5)
   expected = np.array([
       [0, 1, 0, 1, 0, 0, 0, 1, 0, 0],
       [1, 0, 0, 1, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 0, 1, 0, 1, 0],
       [1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
       [0, 0, 0, 0, 0, 0, 0, 1, 1, 0],
       [0, 0, 1, 0, 0, 0, 0, 0, 0, 1],
       [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
       [0, 0, 1, 0, 0, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 0, 1, 0, 0, 0]]).T
   G = b_matching(self.dists, 2, damping=0.5)
   assert_array_equal(G.matrix('dense').astype(int), expected)
Exemple #7
0
 def test_warn_nonconvergence(self):
   with warnings.catch_warnings(record=True) as w:
     b_matching(self.dists, 2, max_iter=2)
     self.assertEqual(len(w), 1)
     self.assertEqual(str(w[0].message),
                      'Hit iteration limit (2) before converging')
Exemple #8
0
 def test_warn_nonconvergence(self):
     with warnings.catch_warnings(record=True) as w:
         b_matching(self.dists, 2, max_iter=2)
         self.assertEqual(len(w), 1)
         self.assertEqual(str(w[0].message),
                          'Hit iteration limit (2) before converging')