Пример #1
0
 def test_trivial(self):
     """Check the trivial case of matching a point set with itself."""
     n = 100
     src = self._rng.random_sample((n, 2))
     correspondences = [(j, ) * 2 for j in range(n)]
     out = bijective_matching(src, src)
     self.assertCountEqual(correspondences, out)
Пример #2
0
 def test_maximum_size(self):
     """Check that the matching has maximum size."""
     for n, m in itertools.product((100, 105), repeat=2):
         with self.subTest(n=n, m=m):
             src = self._rng.random_sample((n, 2))
             dst = self._rng.random_sample((m, 2))
             correspondences = bijective_matching(src, dst)
             self.assertEqual(min(n, m), len(list(correspondences)))
Пример #3
0
 def test_permutation(self):
     """Check that a random permutation of a point set can be recovered."""
     for n, m in itertools.product((100, 105), repeat=2):
         with self.subTest(n=n, m=m):
             k = max(n, m)
             idx = self._rng.permutation(k)
             correspondences = [(j, i) for j, i in zip(idx, range(m))
                                if j < n]
             points = self._rng.random_sample((k, 2))
             src = points[:n]
             dst = points[idx[:m]]
             out = bijective_matching(src, dst)
             self.assertCountEqual(correspondences, out)
Пример #4
0
    def test_uniqueness(self):
        """
        Check that each `src` or `dst` vertex of the matching is part of
        exactly one matching edge.

        """
        for n, m in itertools.product((100, 105), repeat=2):
            with self.subTest(n=n, m=m):
                src = self._rng.random_sample((n, 2))
                dst = self._rng.random_sample((m, 2))
                correspondences = bijective_matching(src, dst)
                for i in (0, 1):
                    vertices = list(
                        map(operator.itemgetter(i), correspondences))
                    self.assertEqual(len(vertices), len(set(vertices)))
Пример #5
0
    def test_sorted(self):
        """
        The returned list of correspondences should be sorted by distance in
        ascending order.

        """
        for n, m in itertools.product((100, 105), repeat=2):
            with self.subTest(n=n, m=m):
                src = self._rng.random_sample((n, 2))
                dst = self._rng.random_sample((m, 2))
                correspondences = bijective_matching(src, dst)
                distance = [
                    scipy.spatial.distance.euclidean(src[j], dst[i])
                    for j, i in correspondences
                ]
                self.assertTrue(
                    all(itertools.starmap(operator.le, pairwise(distance))))