def test_2d_3d(self) -> None: """Test the 3-D implementation using the simplest of the 2-D.""" front_3d, nadir_3d, front_2d, nadir_2d = random_2d_3d_front( 10, dominated=False) contrib_a = contributions(front_3d, nadir_3d) contrib_b = contributions(front_2d, nadir_2d) self.assertTrue(np.allclose(contrib_a, contrib_b))
def test_nondominated_points_ref_1(self): """Test input data with non-dominated points and reference.""" _, _, points, reference = random_2d_3d_front(1000) sorted_contribs = np.array(sorted(hv.contributions(points, reference))) parameters = UPMOParameters(points.shape[1], 1.0) archive = UPMOArchive(parameters, reference) for point in points: archive.insert(point, point) self.assertTrue(archive.size == len(points), "Size") output_contribs = np.array( sorted(map(lambda individual: individual.contribution, archive))) self.assertTrue(np.allclose(sorted_contribs, output_contribs), "Contributions")
def test_contributions(self): contribs = contributions(self.points, self.reference) self.assertTrue(np.allclose(self.contributions, contribs))
def test_auto_refpoint_computation(self) -> None: points = random_cliff_3d(250) reference = np.max(points, axis=0) contrib_a = contributions(points, reference) contrib_b = contributions(points) self.assertTrue(np.allclose(contrib_a, contrib_b))
def test_2d_naive(self) -> None: """Test the 2-D implementation using the naive implementation.""" _, _, front, nadir = random_2d_3d_front(10, dominated=False) contrib_a = contributions_naive(front, nadir) contrib_b = contributions(front, nadir) self.assertTrue(np.allclose(contrib_a, contrib_b))
def contributions(self, points: np.ndarray) -> np.ndarray: prefer_extrema = True return hv.contributions(points, self._reference, prefer_extrema)