From 9fb88b5b3edd6235a166ca2aa20bd691f3b72229 Mon Sep 17 00:00:00 2001 From: Gard Spreemann Date: Mon, 16 Nov 2020 14:16:15 +0100 Subject: Add test for IrregularBettiCurve. 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). --- src/python/test/test_representations.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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) + -- cgit v1.2.3