diff options
author | Gard Spreemann <gspr@nonempty.org> | 2020-11-16 14:16:15 +0100 |
---|---|---|
committer | Gard Spreemann <gspr@nonempty.org> | 2020-11-16 15:04:31 +0100 |
commit | 9fb88b5b3edd6235a166ca2aa20bd691f3b72229 (patch) | |
tree | b3905249bd83d65dbab91c13754aa65d881dfb64 /src/python/test | |
parent | 26c62d8a7b9567ef354fcbe6360856fe1f133641 (diff) |
Add test for IrregularBettiCurve.gspr/irregular-betti-curve
IrregularBettiCurve followed by previous-neighbor interpolation should
equal BettiCurve as long as all intervals are contained in the region
under consideration (behavior is different otherwise).
Diffstat (limited to 'src/python/test')
-rwxr-xr-x | src/python/test/test_representations.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/python/test/test_representations.py b/src/python/test/test_representations.py index 43c914f3..a1b06a35 100755 --- a/src/python/test/test_representations.py +++ b/src/python/test/test_representations.py @@ -2,6 +2,7 @@ import os import sys import matplotlib.pyplot as plt import numpy as np +import scipy.interpolate import pytest from sklearn.cluster import KMeans @@ -63,7 +64,7 @@ def test_dummy_atol(): atol_vectoriser.transform(X=[a, b, c]) -from gudhi.representations.vector_methods import BettiCurve +from gudhi.representations.vector_methods import BettiCurve, IrregularBettiCurve def test_infinity(): @@ -72,3 +73,30 @@ def test_infinity(): assert c[1] == 0 assert c[7] == 3 assert c[9] == 2 + + +def test_betti_curve_is_irregular_betti_curve_followed_by_interpolation(): + m = 10 + n = 500 + reg_res = 100 + + 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) + pds.append(pd) + + irregular = IrregularBettiCurve([0, 20]) + irregular.fit(pds) + (irr_x, irr_y) = irregular.transform(pds) + + regular = BettiCurve(resolution=reg_res, sample_range=[0, 20]) + regular.fit(pds) + reg_y = regular.transform(pds) + + for i in range(0, m): + interp = scipy.interpolate.interp1d(irr_x, irr_y[i, :], kind="previous", fill_value="extrapolate") + success = (reg_y[i, :] == interp(np.linspace(regular.sample_range[0], regular.sample_range[1], reg_res))).all() + assert(success) + |