From 6d3f338033fa7d254898e4d36bdec5137e73aff5 Mon Sep 17 00:00:00 2001 From: fkuehlein Date: Tue, 18 Jul 2023 15:44:01 +0200 Subject: [PATCH] MAINT: better tests for `CrossRecurrencePlot` - testing against issue #128 - for all three possible metrics - intitialize CrossRecurrencePlot - assert two calculations of distance matrix are np.allclose - remove redundant tests --- tests/test_timeseries/test_timeseries.py | 38 +++++++----------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/tests/test_timeseries/test_timeseries.py b/tests/test_timeseries/test_timeseries.py index 8de2eff6..a8d2990e 100644 --- a/tests/test_timeseries/test_timeseries.py +++ b/tests/test_timeseries/test_timeseries.py @@ -35,7 +35,6 @@ def create_test_data(): # Create test time series tdata = Data.SmallTestData().observable() - n_index, n_times = tdata.shape # subtract means form the input data tdata -= np.mean(tdata, axis=1)[:, None] # normalize the data @@ -47,45 +46,28 @@ def create_test_data(): # cross_recurrence_plot # ----------------------------------------------------------------------------- - -def testCrossRecurrencePlot(): - tdata = create_test_data() - CrossRecurrencePlot(x=tdata, y=tdata, threshold=0.2) - - -def testDistanceMatrix(): +def testSupremumDistanceMatrix(): tdata = create_test_data() crp = CrossRecurrencePlot(x=tdata, y=tdata, threshold=1.0) - crp.distance_matrix(tdata.T, tdata.T, metric='manhattan') - + supr_dist_1 = crp.distance_matrix(tdata, tdata, metric=crp.metric) + supr_dist_2 = crp.distance_matrix(tdata, tdata, metric=crp.metric) + assert np.allclose(supr_dist_1, supr_dist_2, atol=1e-04) def testManhattanDistanceMatrix(): tdata = create_test_data() - n_index, n_times = tdata.shape - crp = CrossRecurrencePlot(x=tdata, y=tdata, threshold=1.0) - manh_dist_1 = crp.manhattan_distance_matrix(tdata.T, tdata.T) - manh_dist_2 = crp.manhattan_distance_matrix(tdata.T, tdata.T) + crp = CrossRecurrencePlot(x=tdata, y=tdata, threshold=1.0, metric='manhattan') + manh_dist_1 = crp.distance_matrix(tdata, tdata, metric=crp.metric) + manh_dist_2 = crp.distance_matrix(tdata, tdata, metric=crp.metric) assert np.allclose(manh_dist_1, manh_dist_2, atol=1e-04) - def testEuclideanDistanceMatrix(): tdata = create_test_data() - n_index, n_times = tdata.shape - crp = CrossRecurrencePlot(x=tdata, y=tdata, threshold=1.0) - eucl_dist_1 = crp.euclidean_distance_matrix(tdata.T, tdata.T) - eucl_dist_2 = crp.euclidean_distance_matrix(tdata.T, tdata.T) + crp = CrossRecurrencePlot(x=tdata, y=tdata, threshold=1.0, metric='euclidean') + eucl_dist_1 = crp.distance_matrix(tdata, tdata, metric=crp.metric) + eucl_dist_2 = crp.distance_matrix(tdata, tdata, metric=crp.metric) assert np.allclose(eucl_dist_1, eucl_dist_2, atol=1e-04) -def testSupremumDistanceMatrix(): - tdata = create_test_data() - n_index, n_times = tdata.shape - crp = CrossRecurrencePlot(x=tdata, y=tdata, threshold=1.0) - supr_dist_1 = crp.supremum_distance_matrix(tdata.T, tdata.T) - supr_dist_2 = crp.supremum_distance_matrix(tdata.T, tdata.T) - assert np.allclose(supr_dist_1, supr_dist_2, atol=1e-04) - - # ----------------------------------------------------------------------------- # surrogates # -----------------------------------------------------------------------------