From 500de3b265c227eadd81fb860fade4f6c416cfbc Mon Sep 17 00:00:00 2001 From: wreise Date: Thu, 2 Jun 2022 10:49:07 +0200 Subject: Add tests for Landscapes --- src/python/test/test_representations.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src') diff --git a/src/python/test/test_representations.py b/src/python/test/test_representations.py index 8be3a1db..0324b026 100755 --- a/src/python/test/test_representations.py +++ b/src/python/test/test_representations.py @@ -197,3 +197,29 @@ def test_silhouette_numeric(): expected_silhouette = np.array([0., 0.5, 0., 0., 0., 0., 0., 0.5, 0.])/np.sqrt(2) output_silhouette = slt(dgm) assert np.all(np.isclose(output_silhouette, expected_silhouette)) + + +def test_landscape_small_persistence_invariance(): + dgm = np.array([[2., 6.], [2., 5.], [3., 7.]]) + small_persistence_pts = np.random.rand(10, 2) + small_persistence_pts[:, 1] += small_persistence_pts[:, 0] + small_persistence_pts += np.min(dgm) + dgm_augmented = np.concatenate([dgm, small_persistence_pts], axis=0) + + lds = Landscape(num_landscapes=2, resolution=5) + lds_dgm, lds_dgm_augmented = lds(dgm), lds(dgm_augmented) + + assert np.all(np.isclose(lds_dgm, lds_dgm_augmented)) + + +def test_landscape_numeric(): + dgm = np.array([[2., 6.], [3., 5.]]) + lds_ref = np.array([ + 0., 0.5, 1., 1.5, 2., 1.5, 1., 0.5, 0., # tent of [2, 6] + 0., 0., 0., 0.5, 1., 0.5, 0., 0., 0. + ]) + lds_ref *= np.sqrt(2) + lds = Landscape(num_landscapes=2, resolution=9, sample_range=[2., 6.]) + lds_dgm = lds(dgm) + print(lds.sample_range, lds.new_resolution, lds_dgm.shape) + assert np.all(np.isclose(lds_dgm, lds_ref)) -- cgit v1.2.3