diff options
author | Gard Spreemann <gspr@nonempty.org> | 2020-12-20 15:22:22 +0100 |
---|---|---|
committer | Gard Spreemann <gspr@nonempty.org> | 2020-12-20 15:22:22 +0100 |
commit | 5dc55d25f71b16bd1a80f4dc9ebdfad1d861ee0d (patch) | |
tree | 10cefab25cb2ba2b6c42431e5b8031be700202c9 /src/python | |
parent | f97865b2f5a0457d98bfd75eea3abc23e249943a (diff) |
Add tests for BettiCurve2.
Diffstat (limited to 'src/python')
-rw-r--r-- | src/python/CMakeLists.txt | 5 | ||||
-rwxr-xr-x | src/python/test/test_betti_curve_representations.py | 41 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index 5c1402a6..e0e88880 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -512,6 +512,11 @@ if(PYTHONINTERP_FOUND) add_gudhi_py_test(test_representations) endif() + # Betti curves. + if(SCIPY_FOUND) + add_gudhi_py_test(test_betti_curve_representations) + endif() + # Time Delay add_gudhi_py_test(test_time_delay) diff --git a/src/python/test/test_betti_curve_representations.py b/src/python/test/test_betti_curve_representations.py new file mode 100755 index 00000000..779f6d6e --- /dev/null +++ b/src/python/test/test_betti_curve_representations.py @@ -0,0 +1,41 @@ +import numpy as np +import scipy.interpolate + +from gudhi.representations.vector_methods import BettiCurve2 + +def test_betti_curve_is_irregular_betti_curve_followed_by_interpolation(): + m = 10 + n = 1000 + pinf = 0.05 + pzero = 0.05 + res = 100 + success = True + + pds = [] + for i in range(0, m): + pd = np.zeros((n, 2)) + pd[:, 0] = np.random.uniform(0, 10, n) + pd[:, 1] = np.random.uniform(pd[:, 0], 10, n) + pd[np.random.uniform(0, 1, n) < pzero, 0] = 0 + pd[np.random.uniform(0, 1, n) < pinf, 1] = np.inf + pds.append(pd) + + bc = BettiCurve2(None) + bc.fit(pds) + bettis = bc.transform(pds) + + bc2 = BettiCurve2(None) + bettis2 = bc2.fit_transform(pds) + success = success and (bc2.grid_ == bc.grid_).all() + success = success and (bettis2 == bettis).all() + + for i in range(0, m): + grid = np.linspace(pds[i].min(), pds[i].max() + 1, res) + bc_gridded = BettiCurve2(grid) + bettis_gridded = bc_gridded(pds[i]) + + interp = scipy.interpolate.interp1d(bc.grid_, bettis[i, :], kind="previous", fill_value="extrapolate") + bettis_interp = np.array(interp(grid), dtype=int) + success = success and (bettis_interp == bettis_gridded).all() + + assert(success) |