コード例 #1
0
 def test_01_02(self):
     r = np.random.RandomState()
     r.seed(11)
     for reductions in [0, 2]:
         for _ in range(100):
             c = r.randint(1, 10, (5, 5))
             i, j = np.mgrid[0:5, 0:5]
             i = i.flatten()
             j = j.flatten()
             x, y, u, v = LAPJV.lapjv(i, j, c.flatten(), True, reductions)
             min_cost = np.sum(c)
             best = None
             for permutation in permutations([0, 1, 2, 3, 4]):
                 cost = sum([c[i, permutation[i]] for i in range(5)])
                 if cost < min_cost:
                     best = list(permutation)
                     min_cost = cost
             result_cost = sum([c[i, x[i]] for i in range(5)])
             self.assertAlmostEqual(min_cost, result_cost)
コード例 #2
0
ファイル: test_lapjv.py プロジェクト: JDWarner/CellProfiler
 def test_01_02(self):
     r = np.random.RandomState()
     r.seed(11)
     for reductions in [0,2]:
         for _ in range(100):
             c = r.randint(1,10,(5,5))
             i,j = np.mgrid[0:5,0:5]
             i = i.flatten()
             j = j.flatten()
             x,y,u,v = LAPJV.lapjv(i, j, c.flatten(), True, reductions)
             min_cost = np.sum(c)
             best = None
             for permutation in permutations([0,1,2,3,4]):
                 cost = sum([c[i,permutation[i]] for i in range(5)])
                 if cost < min_cost:
                     best = list(permutation)
                     min_cost = cost
             result_cost = sum([c[i,x[i]] for i in range(5)])
             self.assertAlmostEqual(min_cost, result_cost)