From a34c1fe41cd7af5dc6f218e0d6331c25b7e86dd0 Mon Sep 17 00:00:00 2001 From: SaVoAMP Date: Sun, 27 Feb 2022 19:55:56 +0100 Subject: [PATCH 01/52] [ADD] Added new test files --- tests/test_aamp_mmotifs.py | 0 tests/test_mmotifs.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/test_aamp_mmotifs.py create mode 100644 tests/test_mmotifs.py diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py new file mode 100644 index 000000000..e69de29bb From 85008918d6a8deab6669cbb90a35308ed5033fa8 Mon Sep 17 00:00:00 2001 From: SaVoAMP Date: Sun, 27 Feb 2022 19:57:12 +0100 Subject: [PATCH 02/52] [ADD] Added pytests for 'mmotifs' and 'aamp_mmotifs' --- test.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test.sh b/test.sh index 03fc1dde8..657508abd 100755 --- a/test.sh +++ b/test.sh @@ -107,6 +107,8 @@ test_unit() check_errs $? pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_motifs.py check_errs $? + pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_mmotifs.py + check_errs $? pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_gpu_mpdist.py pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_snippets.py check_errs $? @@ -128,6 +130,8 @@ test_unit() check_errs $? pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_aamp_motifs.py check_errs $? + pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_aamp_mmotifs.py + check_errs $? pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_gpu_aampdist.py pytest -x -W ignore::RuntimeWarning -W ignore::DeprecationWarning tests/test_aampdist_snippets.py check_errs $? From 8362d7412391406cfd29e371b662b2fe9af71f29 Mon Sep 17 00:00:00 2001 From: SaVoAMP Date: Sun, 27 Feb 2022 20:08:18 +0100 Subject: [PATCH 03/52] [DEL] Deleted test templates for the multidimensional case --- tests/test_motifs.py | 58 -------------------------------------------- 1 file changed, 58 deletions(-) diff --git a/tests/test_motifs.py b/tests/test_motifs.py index 49c8fe028..50a144923 100644 --- a/tests/test_motifs.py +++ b/tests/test_motifs.py @@ -236,61 +236,3 @@ def test_match(Q, T): npt.assert_almost_equal(left, right) - -""" -These are tests for multidimensional motif discovery, to be ignored for the moment - -def test_motifs_multidimensional_one_motif_all_dimensions(): - T = np.array( - [ - [0.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, 0.0, -0.5], - [0.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, 0.0, -0.5], - ] - ) - m = 3 - k = 1 - - left_indices = [[0, 5]] - left_profile_values = [0] - - P, I = mstump(T, m) - S = np.array([[0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1]], dtype=float) - right_indices, right_profile_values = search.motifs_multidimensional( - T, P, S, num_dimensions=2, k=k, atol=0.001 - ) - - npt.assert_array_equal(left_indices, right_indices) - npt.assert_almost_equal(left_profile_values, right_profile_values, decimal=4) - - -def test_motifs_multidimensional_two_motifs_all_dimensions(): - n = 200 - T = np.random.normal(size=(2, n)) - m = 20 - - T[:, 10:30] = 1 - T[:, 12:28] = 2 - T[:, 110:130] = 1 - T[:, 112:128] = 2 - T[:, 129] = 1.1 - - T[:, 70:90] = np.arange(m) * 0.1 - T[:, 170:190] = np.arange(m) * 0.1 - - k = 2 - - P, I = mstump(T, m) - S = np.zeros((2, n - m + 1), dtype=float) - S[1, :] = 1 - - left_indices = [[70, 170], [10, 110]] - left_profile_values = [P[70, 0], P[10, 0]] - - right_indices, right_profile_values = search.motifs_multidimensional( - T, P, S, num_dimensions=2, k=k - ) - right_indices = np.sort(right_indices, axis=1) - - npt.assert_array_equal(left_indices, right_indices) - npt.assert_almost_equal(left_profile_values, right_profile_values, decimal=4) -""" From 03da6326024c43ee5d81ae6f20d5aa4d1bc2ba58 Mon Sep 17 00:00:00 2001 From: SaVoAMP Date: Sun, 27 Feb 2022 21:10:46 +0100 Subject: [PATCH 04/52] [ADD] Added function to find one motif in all dimensions --- tests/test_mmotifs.py | 64 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index e69de29bb..1c6d7a789 100644 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -0,0 +1,64 @@ +import numpy as np + +# import numpy.testing as npt +# import pytest + +from stumpy import mmotifs + + +import naive + + +# These are tests for multidimensional motif discovery + + +def test_motifs_multidimensional_one_motif_all_dimensions(): + T = np.array( + [ + [5.0, 0.0, 3.0, 3.0, 7.0, 9.0, 3.0, 5.0, 2.0, 4.0, 7.0, 6.0, 8.0, 8.0, 1.0], + [ + 7.0, + 3.0, + 5.0, + 9.0, + 8.0, + 7.0, + 4.0, + 5.0, + 10.0, + 8.0, + 4.0, + 3.0, + 2.0, + 0.0, + 1.0, + ], + [6.0, 7.0, 7.0, 8.0, 1.0, 5.0, 9.0, 8.0, 9.0, 4.0, 3.0, 0.0, 3.0, 5.0, 0.0], + [ + 0.0, + 1.0, + 3.0, + 2.0, + 6.0, + 1.0, + 9.0, + 10.0, + 1.0, + 2.0, + 2.0, + 5.0, + 1.0, + 0.0, + 4.0, + ], + ] + ) + m = 3 + + P, I = naive.mstump(T, m) + motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( + T, P, I, max_motifs=1 + ) + + +# def test_motifs_multidimensional_two_motifs_all_dimensions(): From 20c2783a4ebc589eced930708a74445f3957bba5 Mon Sep 17 00:00:00 2001 From: SaVoAMP Date: Sun, 27 Feb 2022 21:18:46 +0100 Subject: [PATCH 05/52] [FIX] Reran black and flake8 --- tests/test_motifs.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_motifs.py b/tests/test_motifs.py index 50a144923..07dbf2c9b 100644 --- a/tests/test_motifs.py +++ b/tests/test_motifs.py @@ -235,4 +235,3 @@ def test_match(Q, T): ) npt.assert_almost_equal(left, right) - From f66806b6595ece78a60a962e46b3a1e5f76bce2f Mon Sep 17 00:00:00 2001 From: SaVoAMP Date: Sun, 27 Feb 2022 21:29:06 +0100 Subject: [PATCH 06/52] [ADD] Added exclusion zone to function --- tests/test_mmotifs.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index 1c6d7a789..d9ddb941c 100644 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -3,7 +3,7 @@ # import numpy.testing as npt # import pytest -from stumpy import mmotifs +from stumpy import mmotifs, config import naive @@ -55,7 +55,9 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): ) m = 3 - P, I = naive.mstump(T, m) + excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) + + P, I = naive.mstump(T, m, excl_zone) motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( T, P, I, max_motifs=1 ) From 5cbe804d67e83498f111fbf2ab44e667bfa38950 Mon Sep 17 00:00:00 2001 From: SaVoAMP Date: Sun, 27 Feb 2022 22:05:57 +0100 Subject: [PATCH 07/52] [MOD] Don't use naive implementation --- tests/test_mmotifs.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index d9ddb941c..53fd3044e 100644 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -3,10 +3,8 @@ # import numpy.testing as npt # import pytest -from stumpy import mmotifs, config - - -import naive +from stumpy.mmotifs import mmotifs +from stumpy.mstump import mstump # These are tests for multidimensional motif discovery @@ -55,9 +53,7 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): ) m = 3 - excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) - - P, I = naive.mstump(T, m, excl_zone) + P, I = mstump(T, m) motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( T, P, I, max_motifs=1 ) From 64959124e2697bed8eff5f8653591acfe2394a5e Mon Sep 17 00:00:00 2001 From: SaVoAMP Date: Mon, 28 Feb 2022 11:59:54 +0100 Subject: [PATCH 08/52] [ADD] Added arrange and assert to the first test function --- tests/test_mmotifs.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index 53fd3044e..c91c71ca9 100644 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -1,7 +1,5 @@ import numpy as np - -# import numpy.testing as npt -# import pytest +import numpy.testing as npt from stumpy.mmotifs import mmotifs from stumpy.mstump import mstump @@ -11,6 +9,15 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): + # Find the two dimensional motif pair + + # Arrange + motif_distances_expected = np.array([[0.0, 0.04540775]]) + motif_indices_expected = np.array([[3, 10]]) + motif_subspaces_expected = [np.array([1, 3])] + motif_mdls_expected = [np.array([176.0, 177.509775, 191.26466251, 235.01955001])] + + # Act T = np.array( [ [5.0, 0.0, 3.0, 3.0, 7.0, 9.0, 3.0, 5.0, 2.0, 4.0, 7.0, 6.0, 8.0, 8.0, 1.0], @@ -55,8 +62,14 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): P, I = mstump(T, m) motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( - T, P, I, max_motifs=1 + T, P, I, max_distance=np.inf, max_matches=2, k=1 ) + # Assert + npt.assert_array_equal(motif_distances_expected, motif_distances) + npt.assert_array_equal(motif_indices_expected, motif_indices) + npt.assert_array_equal(motif_subspaces_expected, motif_subspaces) + npt.assert_array_equal(motif_mdls_expected, motif_mdls) + # def test_motifs_multidimensional_two_motifs_all_dimensions(): From 5e133d2a58630b495aafe24d8430e05683ac275b Mon Sep 17 00:00:00 2001 From: SaVoAMP Date: Mon, 28 Feb 2022 12:18:39 +0100 Subject: [PATCH 09/52] [MOD] Changed assertions to 'almost_equal' --- tests/test_mmotifs.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index c91c71ca9..44ae9d100 100644 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -66,10 +66,10 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): ) # Assert - npt.assert_array_equal(motif_distances_expected, motif_distances) - npt.assert_array_equal(motif_indices_expected, motif_indices) - npt.assert_array_equal(motif_subspaces_expected, motif_subspaces) - npt.assert_array_equal(motif_mdls_expected, motif_mdls) + npt.assert_array_almost_equal(motif_distances_expected, motif_distances) + npt.assert_array_almost_equal(motif_indices_expected, motif_indices) + npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) + npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) # def test_motifs_multidimensional_two_motifs_all_dimensions(): From 5518e681dde48e345cb2f1d45b6ecd1ae4a2e40a Mon Sep 17 00:00:00 2001 From: SaVoAMP Date: Mon, 28 Feb 2022 13:55:41 +0100 Subject: [PATCH 10/52] [ADD] Added match functions from 'test_motifs.py' --- tests/test_mmotifs.py | 62 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index 44ae9d100..52ba6f3d7 100644 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -1,13 +1,52 @@ import numpy as np import numpy.testing as npt +import pytest from stumpy.mmotifs import mmotifs from stumpy.mstump import mstump +from stumpy import match + +import naive # These are tests for multidimensional motif discovery +def naive_match(Q, T, excl_zone, max_distance): + m = Q.shape[0] + D = naive.distance_profile(Q, T, m) + + matches = [] + for i in range(D.size): + dist = D[i] + if dist <= max_distance: + matches.append(i) + + # Removes indices that are inside the exclusion zone of some occurrence with + # a smaller distance to the query + matches.sort(key=lambda x: D[x]) + result = [] + while len(matches) > 0: + o = matches[0] + result.append([D[o], o]) + matches = [x for x in matches if x < o - excl_zone or x > o + excl_zone] + + return np.array(result, dtype=object) + + +test_data = [ + ( + np.array([0.0, 1.0, 0.0]), + np.array([0.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, 0.0, -0.5]), + ), + ( + np.array([0.0, 1.0, 2.0]), + np.array([0.1, 1.0, 2.0, 3.0, -1.0, 0.1, 1.0, 2.0, -0.5]), + ), + (np.random.uniform(-1000, 1000, [8]), np.random.uniform(-1000, 1000, [64])), +] + + def test_motifs_multidimensional_one_motif_all_dimensions(): # Find the two dimensional motif pair @@ -73,3 +112,26 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): # def test_motifs_multidimensional_two_motifs_all_dimensions(): + + +@pytest.mark.parametrize("Q, T", test_data) +def test_match(Q, T): + m = Q.shape[0] + excl_zone = int(np.ceil(m / 4)) + max_distance = 0.3 + + left = naive_match( + Q, + T, + excl_zone, + max_distance=max_distance, + ) + + right = match( + Q, + T, + max_matches=None, + max_distance=lambda D: max_distance, # also test lambda functionality + ) + + npt.assert_almost_equal(left, right) From d086d6bc5ecaace0e0f842634c5b07dd17357a61 Mon Sep 17 00:00:00 2001 From: SaVoAMP Date: Mon, 28 Feb 2022 16:35:16 +0100 Subject: [PATCH 11/52] [ADD] Added dummy test --- tests/test_aamp_mmotifs.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py index e69de29bb..59b6af224 100644 --- a/tests/test_aamp_mmotifs.py +++ b/tests/test_aamp_mmotifs.py @@ -0,0 +1,9 @@ +# Dummy test + + +def increment(x): + return x + 1 + + +def test_answer(): + assert increment(3) == 4 From a06f69307d893418a0ebfd833b2df9cfa338db56 Mon Sep 17 00:00:00 2001 From: SaVoAMP Date: Wed, 2 Mar 2022 10:30:33 +0100 Subject: [PATCH 12/52] [DEL & ADD] Deleted test_match() and added test function with default parameters --- tests/test_mmotifs.py | 113 ++++++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 58 deletions(-) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index 52ba6f3d7..2fc06eafc 100644 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -1,52 +1,13 @@ import numpy as np import numpy.testing as npt -import pytest from stumpy.mmotifs import mmotifs from stumpy.mstump import mstump -from stumpy import match - -import naive # These are tests for multidimensional motif discovery -def naive_match(Q, T, excl_zone, max_distance): - m = Q.shape[0] - D = naive.distance_profile(Q, T, m) - - matches = [] - for i in range(D.size): - dist = D[i] - if dist <= max_distance: - matches.append(i) - - # Removes indices that are inside the exclusion zone of some occurrence with - # a smaller distance to the query - matches.sort(key=lambda x: D[x]) - result = [] - while len(matches) > 0: - o = matches[0] - result.append([D[o], o]) - matches = [x for x in matches if x < o - excl_zone or x > o + excl_zone] - - return np.array(result, dtype=object) - - -test_data = [ - ( - np.array([0.0, 1.0, 0.0]), - np.array([0.0, 1.0, 0.0, -1.0, -1.0, 0.0, 1.0, 0.0, -0.5]), - ), - ( - np.array([0.0, 1.0, 2.0]), - np.array([0.1, 1.0, 2.0, 3.0, -1.0, 0.1, 1.0, 2.0, -0.5]), - ), - (np.random.uniform(-1000, 1000, [8]), np.random.uniform(-1000, 1000, [64])), -] - - def test_motifs_multidimensional_one_motif_all_dimensions(): # Find the two dimensional motif pair @@ -111,27 +72,63 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) -# def test_motifs_multidimensional_two_motifs_all_dimensions(): +def test_motifs_multidimensional_with_deafault_parameters(): + # Find the motif pair while only setting the default parameters + # Arrange + motif_distances_expected = np.array([[0.0, 0.0]]) + motif_indices_expected = np.array([[2, 12]]) + motif_subspaces_expected = [np.array([3])] + motif_mdls_expected = [np.array([176.0, 177.509775, 191.26466251, 235.01955001])] -@pytest.mark.parametrize("Q, T", test_data) -def test_match(Q, T): - m = Q.shape[0] - excl_zone = int(np.ceil(m / 4)) - max_distance = 0.3 - - left = naive_match( - Q, - T, - excl_zone, - max_distance=max_distance, + # Act + T = np.array( + [ + [5.0, 0.0, 3.0, 3.0, 7.0, 9.0, 3.0, 5.0, 2.0, 4.0, 7.0, 6.0, 8.0, 8.0, 1.0], + [ + 7.0, + 3.0, + 5.0, + 9.0, + 8.0, + 7.0, + 4.0, + 5.0, + 10.0, + 8.0, + 4.0, + 3.0, + 2.0, + 0.0, + 1.0, + ], + [6.0, 7.0, 7.0, 8.0, 1.0, 5.0, 9.0, 8.0, 9.0, 4.0, 3.0, 0.0, 3.0, 5.0, 0.0], + [ + 0.0, + 1.0, + 3.0, + 2.0, + 6.0, + 1.0, + 9.0, + 10.0, + 1.0, + 2.0, + 2.0, + 5.0, + 1.0, + 0.0, + 4.0, + ], + ] ) + m = 3 - right = match( - Q, - T, - max_matches=None, - max_distance=lambda D: max_distance, # also test lambda functionality - ) + P, I = mstump(T, m) + motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs(T, P, I) - npt.assert_almost_equal(left, right) + # Assert + npt.assert_array_almost_equal(motif_distances_expected, motif_distances) + npt.assert_array_almost_equal(motif_indices_expected, motif_indices) + npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) + npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) From b4356a0498e6f043c698e001ad9403108803bcdd Mon Sep 17 00:00:00 2001 From: SaVoAMP Date: Wed, 2 Mar 2022 12:30:11 +0100 Subject: [PATCH 13/52] [ADD] Added test function to find the top two motifs --- tests/test_mmotifs.py | 67 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index 2fc06eafc..638b8dd8c 100644 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -132,3 +132,70 @@ def test_motifs_multidimensional_with_deafault_parameters(): npt.assert_array_almost_equal(motif_indices_expected, motif_indices) npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) + + +def test_motifs_multidimensional_two_motifs_all_dimensions(): + # Find the best two motif pairs + + # Arrange + motif_distances_expected = np.array([[0.0, 0.0], [0.0, 0.0]]) + motif_indices_expected = np.array([[2, 12], [8, 11]]) + motif_subspaces_expected = [np.array([1])] + motif_mdls_expected = [ + np.array([176.0, 177.509775, 191.26466251, 235.01955001]), + np.array([176.0, 177.509775, 191.26466251, 235.01955001]), + ] + + # Act + T = np.array( + [ + [5.0, 0.0, 3.0, 3.0, 7.0, 9.0, 3.0, 5.0, 2.0, 4.0, 7.0, 6.0, 8.0, 8.0, 1.0], + [ + 7.0, + 3.0, + 5.0, + 9.0, + 8.0, + 7.0, + 4.0, + 5.0, + 10.0, + 8.0, + 4.0, + 3.0, + 2.0, + 0.0, + 1.0, + ], + [6.0, 7.0, 7.0, 8.0, 1.0, 5.0, 9.0, 8.0, 9.0, 4.0, 3.0, 0.0, 3.0, 5.0, 0.0], + [ + 0.0, + 1.0, + 3.0, + 2.0, + 6.0, + 1.0, + 9.0, + 10.0, + 1.0, + 2.0, + 2.0, + 5.0, + 1.0, + 0.0, + 4.0, + ], + ] + ) + m = 3 + + P, I = mstump(T, m) + motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( + T, P, I, cutoffs=np.inf, max_motifs=2 + ) + + # Assert + npt.assert_array_almost_equal(motif_distances_expected, motif_distances) + npt.assert_array_almost_equal(motif_indices_expected, motif_indices) + npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) + npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) From 46ae307040424bd30f1eed40b2723e5c526d7350 Mon Sep 17 00:00:00 2001 From: SaVoAMP Date: Wed, 2 Mar 2022 16:38:55 +0100 Subject: [PATCH 14/52] [ADD] Added function to test 2-dimensional motif discovery --- tests/test_aamp_mmotifs.py | 75 +++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 5 deletions(-) diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py index 59b6af224..44da3d02a 100644 --- a/tests/test_aamp_mmotifs.py +++ b/tests/test_aamp_mmotifs.py @@ -1,9 +1,74 @@ -# Dummy test +import numpy as np +import numpy.testing as npt +from stumpy.mmotifs import mmotifs +from stumpy.mstump import mstump -def increment(x): - return x + 1 + +# These are tests for non-normalized multidimensional motif discovery + + +def test_motifs_multidimensional_one_motif_all_dimensions(): + # Find the two dimensional motif pair + + # Arrange + motif_distances_expected = np.array([[0. , 1.72474487]]) + motif_indices_expected = np.array([[0, 5]]) + motif_subspaces_expected = [np.array([1, 2])] + motif_mdls_expected = [np.array([187. , 188. , 191.26466251, 196. ])] + + # Act + T = np.array( + [ + [5.0, 0.0, 3.0, 3.0, 7.0, 9.0, 3.0, 5.0, 2.0, 4.0, 7.0, 6.0, 8.0, 8.0, 1.0], + [ + 7.0, + 3.0, + 5.0, + 9.0, + 8.0, + 7.0, + 4.0, + 5.0, + 10.0, + 8.0, + 4.0, + 3.0, + 2.0, + 0.0, + 1.0, + ], + [6.0, 7.0, 7.0, 8.0, 1.0, 5.0, 9.0, 8.0, 9.0, 4.0, 3.0, 0.0, 3.0, 5.0, 0.0], + [ + 0.0, + 1.0, + 3.0, + 2.0, + 6.0, + 1.0, + 9.0, + 10.0, + 1.0, + 2.0, + 2.0, + 5.0, + 1.0, + 0.0, + 4.0, + ], + ] + ) + m = 3 + + P, I = mstump(T, m, normalize=False) + motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( + T, P, I, max_distance=np.inf, max_matches=2, k=1, normalize=False + ) + + # Assert + npt.assert_array_almost_equal(motif_distances_expected, motif_distances) + npt.assert_array_almost_equal(motif_indices_expected, motif_indices) + npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) + npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) -def test_answer(): - assert increment(3) == 4 From d4612dd65ba117ed51565391b9a665a9786d4f17 Mon Sep 17 00:00:00 2001 From: SaVoAMP Date: Wed, 2 Mar 2022 16:42:53 +0100 Subject: [PATCH 15/52] [FIX] Fixed formatting --- tests/test_aamp_mmotifs.py | 66 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py index 44da3d02a..0e1fddbb1 100644 --- a/tests/test_aamp_mmotifs.py +++ b/tests/test_aamp_mmotifs.py @@ -12,10 +12,10 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): # Find the two dimensional motif pair # Arrange - motif_distances_expected = np.array([[0. , 1.72474487]]) + motif_distances_expected = np.array([[0.0, 1.72474487]]) motif_indices_expected = np.array([[0, 5]]) motif_subspaces_expected = [np.array([1, 2])] - motif_mdls_expected = [np.array([187. , 188. , 191.26466251, 196. ])] + motif_mdls_expected = [np.array([187.0, 188.0, 191.26466251, 196.0])] # Act T = np.array( @@ -72,3 +72,65 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) +def test_motifs_multidimensional_with_deafault_parameters(): + # Find the motif pair while only setting the default parameters + + # Arrange + motif_distances_expected = np.array([[0.0, 1.72474487]]) + motif_indices_expected = np.array([[0, 5]]) + motif_subspaces_expected = [np.array([1, 2])] + motif_mdls_expected = [np.array([187.0, 188.0, 191.26466251, 196.0])] + + # Act + T = np.array( + [ + [5.0, 0.0, 3.0, 3.0, 7.0, 9.0, 3.0, 5.0, 2.0, 4.0, 7.0, 6.0, 8.0, 8.0, 1.0], + [ + 7.0, + 3.0, + 5.0, + 9.0, + 8.0, + 7.0, + 4.0, + 5.0, + 10.0, + 8.0, + 4.0, + 3.0, + 2.0, + 0.0, + 1.0, + ], + [6.0, 7.0, 7.0, 8.0, 1.0, 5.0, 9.0, 8.0, 9.0, 4.0, 3.0, 0.0, 3.0, 5.0, 0.0], + [ + 0.0, + 1.0, + 3.0, + 2.0, + 6.0, + 1.0, + 9.0, + 10.0, + 1.0, + 2.0, + 2.0, + 5.0, + 1.0, + 0.0, + 4.0, + ], + ] + ) + m = 3 + + P, I = mstump(T, m, normalize=False) + motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( + T, P, I, max_distance=np.inf, max_matches=2, k=1, normalize=False + ) + + # Assert + npt.assert_array_almost_equal(motif_distances_expected, motif_distances) + npt.assert_array_almost_equal(motif_indices_expected, motif_indices) + npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) + npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) From d169441d8130a18ac37c5f4de92ef75f07e9ae4e Mon Sep 17 00:00:00 2001 From: SaVoAMP Date: Wed, 2 Mar 2022 17:01:39 +0100 Subject: [PATCH 16/52] [ADD] Added test function to find motifs with the 'max_motifs' parameter only --- tests/test_aamp_mmotifs.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py index 0e1fddbb1..b27ec9ae5 100644 --- a/tests/test_aamp_mmotifs.py +++ b/tests/test_aamp_mmotifs.py @@ -72,13 +72,16 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) -def test_motifs_multidimensional_with_deafault_parameters(): - # Find the motif pair while only setting the default parameters +def test_motifs_multidimensional_with_default_parameters_and_max_distance_set(): + # Find the motif pair while only setting the default parameters and max_distance, + # since there is nothing found instead. # Arrange - motif_distances_expected = np.array([[0.0, 1.72474487]]) - motif_indices_expected = np.array([[0, 5]]) - motif_subspaces_expected = [np.array([1, 2])] + motif_distances_expected = np.array( + [[0.0, 1.0, 2.44948974, 5.74456265, 6.4807407, 7.87400787]] + ) + motif_indices_expected = np.array([[0, 5, 9, 3, 11, 7]]) + motif_subspaces_expected = [np.array([1])] motif_mdls_expected = [np.array([187.0, 188.0, 191.26466251, 196.0])] # Act @@ -126,7 +129,7 @@ def test_motifs_multidimensional_with_deafault_parameters(): P, I = mstump(T, m, normalize=False) motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( - T, P, I, max_distance=np.inf, max_matches=2, k=1, normalize=False + T, P, I, max_distance=np.inf, normalize=False ) # Assert From 373dd5f4bac9c7aa4bcc386ba3568f64b7342d49 Mon Sep 17 00:00:00 2001 From: SaVoAMP Date: Wed, 2 Mar 2022 17:03:41 +0100 Subject: [PATCH 17/52] Revert "[ADD] Added test function to find motifs with the 'max_matches' parameter only" This reverts commit d169441d8130a18ac37c5f4de92ef75f07e9ae4e. --- tests/test_aamp_mmotifs.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py index b27ec9ae5..0e1fddbb1 100644 --- a/tests/test_aamp_mmotifs.py +++ b/tests/test_aamp_mmotifs.py @@ -72,16 +72,13 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) -def test_motifs_multidimensional_with_default_parameters_and_max_distance_set(): - # Find the motif pair while only setting the default parameters and max_distance, - # since there is nothing found instead. +def test_motifs_multidimensional_with_deafault_parameters(): + # Find the motif pair while only setting the default parameters # Arrange - motif_distances_expected = np.array( - [[0.0, 1.0, 2.44948974, 5.74456265, 6.4807407, 7.87400787]] - ) - motif_indices_expected = np.array([[0, 5, 9, 3, 11, 7]]) - motif_subspaces_expected = [np.array([1])] + motif_distances_expected = np.array([[0.0, 1.72474487]]) + motif_indices_expected = np.array([[0, 5]]) + motif_subspaces_expected = [np.array([1, 2])] motif_mdls_expected = [np.array([187.0, 188.0, 191.26466251, 196.0])] # Act @@ -129,7 +126,7 @@ def test_motifs_multidimensional_with_default_parameters_and_max_distance_set(): P, I = mstump(T, m, normalize=False) motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( - T, P, I, max_distance=np.inf, normalize=False + T, P, I, max_distance=np.inf, max_matches=2, k=1, normalize=False ) # Assert From bbf24d2f8fb1eaf8afacd8b3fa206be242f21eaa Mon Sep 17 00:00:00 2001 From: SaVoAMP Date: Wed, 2 Mar 2022 17:13:01 +0100 Subject: [PATCH 18/52] [ADD] Added test function to find motifs with the 'max_distance' parameter --- tests/test_aamp_mmotifs.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py index 0e1fddbb1..adf907c7b 100644 --- a/tests/test_aamp_mmotifs.py +++ b/tests/test_aamp_mmotifs.py @@ -72,13 +72,16 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) -def test_motifs_multidimensional_with_deafault_parameters(): - # Find the motif pair while only setting the default parameters +def test_motifs_multidimensional_with_default_parameters_and_max_distance(): + # Find the motif pair while only setting the default parameters and + # max_distance # Arrange - motif_distances_expected = np.array([[0.0, 1.72474487]]) - motif_indices_expected = np.array([[0, 5]]) - motif_subspaces_expected = [np.array([1, 2])] + motif_distances_expected = np.array( + [[0.0, 1.0, 2.44948974, 5.74456265, 6.4807407, 7.87400787]] + ) + motif_indices_expected = np.array([[0, 5, 9, 3, 11, 7]]) + motif_subspaces_expected = [np.array([1])] motif_mdls_expected = [np.array([187.0, 188.0, 191.26466251, 196.0])] # Act @@ -126,7 +129,7 @@ def test_motifs_multidimensional_with_deafault_parameters(): P, I = mstump(T, m, normalize=False) motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( - T, P, I, max_distance=np.inf, max_matches=2, k=1, normalize=False + T, P, I, max_distance=np.inf, normalize=False ) # Assert From 5315fefe7f17689502ae06eb07a3de941616868e Mon Sep 17 00:00:00 2001 From: SaVoAMP Date: Wed, 2 Mar 2022 19:32:44 +0100 Subject: [PATCH 19/52] [ADD] Make copy of the matrix profile --- stumpy/mmotifs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/stumpy/mmotifs.py b/stumpy/mmotifs.py index 071ebe177..19ad89cd4 100644 --- a/stumpy/mmotifs.py +++ b/stumpy/mmotifs.py @@ -137,6 +137,7 @@ def mmotifs( max_motifs = 1 T, M_T, Σ_T = core.preprocess(T, m) + P = P.copy() excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) From 52e916c6b503c65dc2f33d228760699e1efa0cb7 Mon Sep 17 00:00:00 2001 From: SaVoAMP Date: Wed, 2 Mar 2022 19:35:28 +0100 Subject: [PATCH 20/52] [ADD] Also make copy of matrix profile in 'aamp_mmotifs.py' --- stumpy/aamp_mmotifs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/stumpy/aamp_mmotifs.py b/stumpy/aamp_mmotifs.py index b2cf34327..7b067bdc5 100644 --- a/stumpy/aamp_mmotifs.py +++ b/stumpy/aamp_mmotifs.py @@ -118,6 +118,7 @@ def aamp_mmotifs( max_motifs = 1 T, T_subseq_isfinite = core.preprocess_non_normalized(T, m) + P = P.copy() excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) From eb49f1ba2020a8dec50056d76c716273a6bc7be6 Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 4 Mar 2022 20:36:00 +0100 Subject: [PATCH 21/52] [FIX] Corrected the expected motif subspaces --- tests/test_mmotifs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 tests/test_mmotifs.py diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py old mode 100644 new mode 100755 index 638b8dd8c..74d378a54 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -140,7 +140,7 @@ def test_motifs_multidimensional_two_motifs_all_dimensions(): # Arrange motif_distances_expected = np.array([[0.0, 0.0], [0.0, 0.0]]) motif_indices_expected = np.array([[2, 12], [8, 11]]) - motif_subspaces_expected = [np.array([1])] + motif_subspaces_expected = [np.array([3]), np.array([1])] motif_mdls_expected = [ np.array([176.0, 177.509775, 191.26466251, 235.01955001]), np.array([176.0, 177.509775, 191.26466251, 235.01955001]), From 5199cb1f3b90cffc69cd2cbf2b0d33967f26185f Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 4 Mar 2022 21:46:44 +0100 Subject: [PATCH 22/52] [ADD] Added function to test the two dimensional and non-normalized motif discovery --- tests/test_aamp_mmotifs.py | 74 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) mode change 100644 => 100755 tests/test_aamp_mmotifs.py diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py old mode 100644 new mode 100755 index adf907c7b..c0f4dd17b --- a/tests/test_aamp_mmotifs.py +++ b/tests/test_aamp_mmotifs.py @@ -137,3 +137,77 @@ def test_motifs_multidimensional_with_default_parameters_and_max_distance(): npt.assert_array_almost_equal(motif_indices_expected, motif_indices) npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) + + +def test_motifs_multidimensional_two_motifs_all_dimensions(): + # Find the best two motif pairs + + # Arrange + motif_distances_expected = np.array([[0.0, 1.0], [0.0, 1.0]]) + motif_indices_expected = np.array([[0, 5], [2, 7]]) + motif_subspaces_expected = [np.array([1]), np.array([1])] + motif_mdls_expected = [ + np.array([187.0, 188.0, 191.26466251, 196.0]), + np.array([187.0, 188.0, 201.2661943, 196.0]), + ] + + # Act + T = np.array( + [ + [5.0, 0.0, 3.0, 3.0, 7.0, 9.0, 3.0, 5.0, 2.0, 4.0, 7.0, 6.0, 8.0, 8.0, 1.0], + [ + 7.0, + 3.0, + 5.0, + 9.0, + 8.0, + 7.0, + 4.0, + 5.0, + 10.0, + 8.0, + 4.0, + 3.0, + 2.0, + 0.0, + 1.0, + ], + [6.0, 7.0, 7.0, 8.0, 1.0, 5.0, 9.0, 8.0, 9.0, 4.0, 3.0, 0.0, 3.0, 5.0, 0.0], + [ + 0.0, + 1.0, + 3.0, + 2.0, + 6.0, + 1.0, + 9.0, + 10.0, + 1.0, + 2.0, + 2.0, + 5.0, + 1.0, + 0.0, + 4.0, + ], + ] + ) + m = 3 + + P, I = mstump(T, m, normalize=False) + motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( + T, + P, + I, + max_distance=np.inf, + cutoffs=np.inf, + max_matches=2, + max_motifs=2, + normalize=False, + ) + + # Assert + npt.assert_array_almost_equal(motif_distances_expected, motif_distances) + npt.assert_array_almost_equal(motif_indices_expected, motif_indices) + npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) + npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) From 3313ebe193aae7aeb1b50444f766bbfa1cdf9582 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 7 Mar 2022 22:09:08 +0100 Subject: [PATCH 23/52] [MOD] Changed to naive matrix profile computation --- tests/test_mmotifs.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index 74d378a54..68daba898 100755 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -1,8 +1,9 @@ import numpy as np import numpy.testing as npt +import naive from stumpy.mmotifs import mmotifs -from stumpy.mstump import mstump +from stumpy import config # These are tests for multidimensional motif discovery @@ -60,7 +61,8 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): ) m = 3 - P, I = mstump(T, m) + excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) + P, I = naive.mstump(T, m, excl_zone) motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( T, P, I, max_distance=np.inf, max_matches=2, k=1 ) @@ -124,7 +126,8 @@ def test_motifs_multidimensional_with_deafault_parameters(): ) m = 3 - P, I = mstump(T, m) + excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) + P, I = naive.mstump(T, m, excl_zone) motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs(T, P, I) # Assert @@ -189,7 +192,8 @@ def test_motifs_multidimensional_two_motifs_all_dimensions(): ) m = 3 - P, I = mstump(T, m) + excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) + P, I = naive.mstump(T, m, excl_zone) motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( T, P, I, cutoffs=np.inf, max_motifs=2 ) From 65270e233fa04f7d5500a86909f25a9a9bd50054 Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 9 Mar 2022 11:58:49 +0100 Subject: [PATCH 24/52] [ADD] Added 'query_idx' parameter to ensure that the self-match is returned if the query is a part of the time series. --- stumpy/mmotifs.py | 1 + stumpy/motifs.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/stumpy/mmotifs.py b/stumpy/mmotifs.py index 19ad89cd4..1bc3080bf 100644 --- a/stumpy/mmotifs.py +++ b/stumpy/mmotifs.py @@ -190,6 +190,7 @@ def mmotifs( max_matches=max_matches, max_distance=max_distance, atol=atol, + query_idx=motif_idx, normalize=normalize, p=p, ) diff --git a/stumpy/motifs.py b/stumpy/motifs.py index a880d01cb..e80bac480 100644 --- a/stumpy/motifs.py +++ b/stumpy/motifs.py @@ -317,6 +317,7 @@ def match( max_distance=None, max_matches=None, atol=1e-8, + query_idx = None, normalize=True, p=2.0, ): @@ -428,7 +429,11 @@ def max_distance(D): matches = [] - candidate_idx = np.argmin(D) + if query_idx is not None: + candidate_idx = query_idx + else: + candidate_idx = np.argmin(D) + while ( D[candidate_idx] <= atol + max_distance and np.isfinite(D[candidate_idx]) From c8e5992fe6636c816e171ab87529fc91c8630a0f Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 9 Mar 2022 17:37:43 +0100 Subject: [PATCH 25/52] [MOD] Change subsequence length m and time series T --- tests/test_mmotifs.py | 192 +++++++++++++++++++++--------------------- 1 file changed, 97 insertions(+), 95 deletions(-) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index 68daba898..599077283 100755 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -10,56 +10,56 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): - # Find the two dimensional motif pair + # Find the two-dimensional motif pair # Arrange - motif_distances_expected = np.array([[0.0, 0.04540775]]) - motif_indices_expected = np.array([[3, 10]]) + motif_distances_expected = np.array([[0.0, 0.20948156]]) + motif_indices_expected = np.array([[2, 9]]) motif_subspaces_expected = [np.array([1, 3])] - motif_mdls_expected = [np.array([176.0, 177.509775, 191.26466251, 235.01955001])] + motif_mdls_expected = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] # Act T = np.array( [ - [5.0, 0.0, 3.0, 3.0, 7.0, 9.0, 3.0, 5.0, 2.0, 4.0, 7.0, 6.0, 8.0, 8.0, 1.0], + [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], [ - 7.0, - 3.0, - 5.0, - 9.0, - 8.0, - 7.0, - 4.0, + 7.3, + 3.2, 5.0, + 9.1, + 8.2, + 7.3, + 4.8, + 8.2, 10.0, - 8.0, - 4.0, - 3.0, - 2.0, 0.0, - 1.0, + 4.1, + 3.2, + 2.3, + 0.1, + 1.4, ], - [6.0, 7.0, 7.0, 8.0, 1.0, 5.0, 9.0, 8.0, 9.0, 4.0, 3.0, 0.0, 3.0, 5.0, 0.0], + [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], [ - 0.0, - 1.0, + 0.1, + 1.3, 3.0, - 2.0, - 6.0, - 1.0, - 9.0, + 2.1, + 6.2, + 1.3, + 9.5, 10.0, - 1.0, - 2.0, + 1.8, 2.0, - 5.0, - 1.0, - 0.0, - 4.0, + 2.1, + 5.2, + 1.3, + 0.5, + 4.3, ], ] ) - m = 3 + m = 4 excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) @@ -78,53 +78,53 @@ def test_motifs_multidimensional_with_deafault_parameters(): # Find the motif pair while only setting the default parameters # Arrange - motif_distances_expected = np.array([[0.0, 0.0]]) - motif_indices_expected = np.array([[2, 12]]) - motif_subspaces_expected = [np.array([3])] - motif_mdls_expected = [np.array([176.0, 177.509775, 191.26466251, 235.01955001])] + motif_distances_expected = np.array([[0.0000000e00, 1.1151008e-07]]) + motif_indices_expected = np.array([[2, 9]]) + motif_subspaces_expected = [np.array([1])] + motif_mdls_expected = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] # Act T = np.array( [ - [5.0, 0.0, 3.0, 3.0, 7.0, 9.0, 3.0, 5.0, 2.0, 4.0, 7.0, 6.0, 8.0, 8.0, 1.0], + [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], [ - 7.0, - 3.0, - 5.0, - 9.0, - 8.0, - 7.0, - 4.0, + 7.3, + 3.2, 5.0, + 9.1, + 8.2, + 7.3, + 4.8, + 8.2, 10.0, - 8.0, - 4.0, - 3.0, - 2.0, 0.0, - 1.0, + 4.1, + 3.2, + 2.3, + 0.1, + 1.4, ], - [6.0, 7.0, 7.0, 8.0, 1.0, 5.0, 9.0, 8.0, 9.0, 4.0, 3.0, 0.0, 3.0, 5.0, 0.0], + [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], [ - 0.0, - 1.0, + 0.1, + 1.3, 3.0, - 2.0, - 6.0, - 1.0, - 9.0, + 2.1, + 6.2, + 1.3, + 9.5, 10.0, - 1.0, - 2.0, + 1.8, 2.0, - 5.0, - 1.0, - 0.0, - 4.0, + 2.1, + 5.2, + 1.3, + 0.5, + 4.3, ], ] ) - m = 3 + m = 4 excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) @@ -141,61 +141,63 @@ def test_motifs_multidimensional_two_motifs_all_dimensions(): # Find the best two motif pairs # Arrange - motif_distances_expected = np.array([[0.0, 0.0], [0.0, 0.0]]) - motif_indices_expected = np.array([[2, 12], [8, 11]]) - motif_subspaces_expected = [np.array([3]), np.array([1])] + motif_distances_expected = np.array( + [[0.00000000e00, 1.11510080e-07], [1.68587394e-07, 2.58694429e-01]] + ) + motif_indices_expected = np.array([[2, 9], [6, 1]]) + motif_subspaces_expected = [np.array([1]), np.array([2])] motif_mdls_expected = [ - np.array([176.0, 177.509775, 191.26466251, 235.01955001]), - np.array([176.0, 177.509775, 191.26466251, 235.01955001]), + np.array([232.0, 250.57542476, 260.0, 271.3509059]), + np.array([264.0, 280.0, 299.01955001, 310.51024953]), ] # Act T = np.array( [ - [5.0, 0.0, 3.0, 3.0, 7.0, 9.0, 3.0, 5.0, 2.0, 4.0, 7.0, 6.0, 8.0, 8.0, 1.0], + [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], [ - 7.0, - 3.0, - 5.0, - 9.0, - 8.0, - 7.0, - 4.0, + 7.3, + 3.2, 5.0, + 9.1, + 8.2, + 7.3, + 4.8, + 8.2, 10.0, - 8.0, - 4.0, - 3.0, - 2.0, 0.0, - 1.0, + 4.1, + 3.2, + 2.3, + 0.1, + 1.4, ], - [6.0, 7.0, 7.0, 8.0, 1.0, 5.0, 9.0, 8.0, 9.0, 4.0, 3.0, 0.0, 3.0, 5.0, 0.0], + [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], [ - 0.0, - 1.0, + 0.1, + 1.3, 3.0, - 2.0, - 6.0, - 1.0, - 9.0, + 2.1, + 6.2, + 1.3, + 9.5, 10.0, - 1.0, + 1.8, 2.0, - 2.0, - 5.0, - 1.0, - 0.0, - 4.0, + 2.1, + 5.2, + 1.3, + 0.5, + 4.3, ], ] ) - m = 3 + m = 4 excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( - T, P, I, cutoffs=np.inf, max_motifs=2 + T, P, I, cutoffs=np.inf, max_motifs=2, max_distance=np.inf, max_matches=2 ) # Assert From ccc50c7445c73b62882c723a2b759de643f68fae Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 9 Mar 2022 18:08:59 +0100 Subject: [PATCH 26/52] [MOD] Change to naive computation and change time series --- tests/test_aamp_mmotifs.py | 213 +++++++++++++++++++------------------ 1 file changed, 108 insertions(+), 105 deletions(-) diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py index c0f4dd17b..a40e854fa 100755 --- a/tests/test_aamp_mmotifs.py +++ b/tests/test_aamp_mmotifs.py @@ -1,68 +1,70 @@ import numpy as np import numpy.testing as npt +import naive -from stumpy.mmotifs import mmotifs -from stumpy.mstump import mstump +from stumpy.aamp_mmotifs import aamp_mmotifs +from stumpy import config # These are tests for non-normalized multidimensional motif discovery def test_motifs_multidimensional_one_motif_all_dimensions(): - # Find the two dimensional motif pair + # Find the two-dimensional motif pair # Arrange - motif_distances_expected = np.array([[0.0, 1.72474487]]) + motif_distances_expected = np.array([[0.0, 2.87778559]]) motif_indices_expected = np.array([[0, 5]]) - motif_subspaces_expected = [np.array([1, 2])] - motif_mdls_expected = [np.array([187.0, 188.0, 191.26466251, 196.0])] + motif_subspaces_expected = [np.array([2, 1])] + motif_mdls_expected = [np.array([244.0, 260.67970001, 279.86313714, 281.35940001])] # Act T = np.array( [ - [5.0, 0.0, 3.0, 3.0, 7.0, 9.0, 3.0, 5.0, 2.0, 4.0, 7.0, 6.0, 8.0, 8.0, 1.0], + [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], [ - 7.0, - 3.0, - 5.0, - 9.0, - 8.0, - 7.0, - 4.0, + 7.3, + 3.2, 5.0, + 9.1, + 8.2, + 7.3, + 4.8, + 8.2, 10.0, - 8.0, - 4.0, - 3.0, - 2.0, 0.0, - 1.0, + 4.1, + 3.2, + 2.3, + 0.1, + 1.4, ], - [6.0, 7.0, 7.0, 8.0, 1.0, 5.0, 9.0, 8.0, 9.0, 4.0, 3.0, 0.0, 3.0, 5.0, 0.0], + [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], [ - 0.0, - 1.0, + 0.1, + 1.3, 3.0, - 2.0, - 6.0, - 1.0, - 9.0, + 2.1, + 6.2, + 1.3, + 9.5, 10.0, - 1.0, - 2.0, + 1.8, 2.0, - 5.0, - 1.0, - 0.0, - 4.0, + 2.1, + 5.2, + 1.3, + 0.5, + 4.3, ], ] ) - m = 3 + m = 4 - P, I = mstump(T, m, normalize=False) - motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( - T, P, I, max_distance=np.inf, max_matches=2, k=1, normalize=False + excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) + P, I = naive.maamp(T, m, excl_zone) + motif_distances, motif_indices, motif_subspaces, motif_mdls = aamp_mmotifs( + T, P, I, max_distance=np.inf, max_matches=2, k=1 ) # Assert @@ -78,58 +80,59 @@ def test_motifs_multidimensional_with_default_parameters_and_max_distance(): # Arrange motif_distances_expected = np.array( - [[0.0, 1.0, 2.44948974, 5.74456265, 6.4807407, 7.87400787]] + [[0.0, 1.41421356, 4.46430286, 6.85346628, 8.207923, 8.50529247]] ) - motif_indices_expected = np.array([[0, 5, 9, 3, 11, 7]]) - motif_subspaces_expected = [np.array([1])] - motif_mdls_expected = [np.array([187.0, 188.0, 191.26466251, 196.0])] + motif_indices_expected = np.array([[2, 9, 0, 11, 7, 5]]) + motif_subspaces_expected = [np.array([3])] + motif_mdls_expected = [np.array([244.0, 260.67970001, 279.86313714, 281.35940001])] # Act T = np.array( [ - [5.0, 0.0, 3.0, 3.0, 7.0, 9.0, 3.0, 5.0, 2.0, 4.0, 7.0, 6.0, 8.0, 8.0, 1.0], + [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], [ - 7.0, - 3.0, - 5.0, - 9.0, - 8.0, - 7.0, - 4.0, + 7.3, + 3.2, 5.0, + 9.1, + 8.2, + 7.3, + 4.8, + 8.2, 10.0, - 8.0, - 4.0, - 3.0, - 2.0, 0.0, - 1.0, + 4.1, + 3.2, + 2.3, + 0.1, + 1.4, ], - [6.0, 7.0, 7.0, 8.0, 1.0, 5.0, 9.0, 8.0, 9.0, 4.0, 3.0, 0.0, 3.0, 5.0, 0.0], + [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], [ - 0.0, - 1.0, + 0.1, + 1.3, 3.0, - 2.0, - 6.0, - 1.0, - 9.0, + 2.1, + 6.2, + 1.3, + 9.5, 10.0, - 1.0, - 2.0, + 1.8, 2.0, - 5.0, - 1.0, - 0.0, - 4.0, + 2.1, + 5.2, + 1.3, + 0.5, + 4.3, ], ] ) - m = 3 + m = 4 - P, I = mstump(T, m, normalize=False) - motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( - T, P, I, max_distance=np.inf, normalize=False + excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) + P, I = naive.maamp(T, m, excl_zone) + motif_distances, motif_indices, motif_subspaces, motif_mdls = aamp_mmotifs( + T, P, I, max_distance=np.inf ) # Assert @@ -143,59 +146,60 @@ def test_motifs_multidimensional_two_motifs_all_dimensions(): # Find the best two motif pairs # Arrange - motif_distances_expected = np.array([[0.0, 1.0], [0.0, 1.0]]) - motif_indices_expected = np.array([[0, 5], [2, 7]]) - motif_subspaces_expected = [np.array([1]), np.array([1])] + motif_distances_expected = np.array([[0.0, 1.41421356], [0.0, 2.06639783]]) + motif_indices_expected = np.array([[2, 9], [0, 5]]) + motif_subspaces_expected = [np.array([3]), np.array([2])] motif_mdls_expected = [ - np.array([187.0, 188.0, 191.26466251, 196.0]), - np.array([187.0, 188.0, 201.2661943, 196.0]), + np.array([244.0, 260.67970001, 279.86313714, 281.35940001]), + np.array([254.33985, 260.67970001, 279.86313714, 291.20703549]), ] # Act T = np.array( [ - [5.0, 0.0, 3.0, 3.0, 7.0, 9.0, 3.0, 5.0, 2.0, 4.0, 7.0, 6.0, 8.0, 8.0, 1.0], + [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], [ - 7.0, - 3.0, - 5.0, - 9.0, - 8.0, - 7.0, - 4.0, + 7.3, + 3.2, 5.0, + 9.1, + 8.2, + 7.3, + 4.8, + 8.2, 10.0, - 8.0, - 4.0, - 3.0, - 2.0, 0.0, - 1.0, + 4.1, + 3.2, + 2.3, + 0.1, + 1.4, ], - [6.0, 7.0, 7.0, 8.0, 1.0, 5.0, 9.0, 8.0, 9.0, 4.0, 3.0, 0.0, 3.0, 5.0, 0.0], + [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], [ - 0.0, - 1.0, + 0.1, + 1.3, 3.0, - 2.0, - 6.0, - 1.0, - 9.0, + 2.1, + 6.2, + 1.3, + 9.5, 10.0, - 1.0, + 1.8, 2.0, - 2.0, - 5.0, - 1.0, - 0.0, - 4.0, + 2.1, + 5.2, + 1.3, + 0.5, + 4.3, ], ] ) - m = 3 + m = 4 - P, I = mstump(T, m, normalize=False) - motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( + excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) + P, I = naive.maamp(T, m, excl_zone) + motif_distances, motif_indices, motif_subspaces, motif_mdls = aamp_mmotifs( T, P, I, @@ -203,7 +207,6 @@ def test_motifs_multidimensional_two_motifs_all_dimensions(): cutoffs=np.inf, max_matches=2, max_motifs=2, - normalize=False, ) # Assert From 443bb1d18ff315756ee77c3b9fe684c6a9b63e16 Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 9 Mar 2022 18:12:18 +0100 Subject: [PATCH 27/52] [MOD] Reformat file --- stumpy/motifs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stumpy/motifs.py b/stumpy/motifs.py index 9098f6a4a..f2938e984 100644 --- a/stumpy/motifs.py +++ b/stumpy/motifs.py @@ -322,7 +322,7 @@ def match( max_distance=None, max_matches=None, atol=1e-8, - query_idx = None, + query_idx=None, normalize=True, p=2.0, ): From d0c785907c6378a9a125fbee52055ba15608d276 Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 9 Mar 2022 18:38:23 +0100 Subject: [PATCH 28/52] [ADD] Add docstring documentation --- stumpy/motifs.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stumpy/motifs.py b/stumpy/motifs.py index f2938e984..e5d9f9f87 100644 --- a/stumpy/motifs.py +++ b/stumpy/motifs.py @@ -366,6 +366,10 @@ def match( The absolute tolerance parameter. This value will be added to `max_distance` when comparing distances between subsequences. + query_idx : int, default None + This parameter is used when the matrix profile is a self-join. + If a specific integer value is set, the parameter will ensure that the self-match will be returned first. + normalize : bool, default True When set to `True`, this z-normalizes subsequences prior to computing distances. Otherwise, this function gets re-routed to its complementary non-normalized From 870cf15dc624455d60c3c08613ab562ac989a836 Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 9 Mar 2022 19:32:02 +0100 Subject: [PATCH 29/52] [MOD] Reformat file --- stumpy/motifs.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stumpy/motifs.py b/stumpy/motifs.py index e5d9f9f87..62ff9fe56 100644 --- a/stumpy/motifs.py +++ b/stumpy/motifs.py @@ -368,7 +368,8 @@ def match( query_idx : int, default None This parameter is used when the matrix profile is a self-join. - If a specific integer value is set, the parameter will ensure that the self-match will be returned first. + If a specific integer value is set, the parameter will ensure that the + self-match will be returned first. normalize : bool, default True When set to `True`, this z-normalizes subsequences prior to computing distances. From 498c8d9d0e0ec6e800cd4486235e3bcc6fadac2e Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 9 Mar 2022 20:46:27 +0100 Subject: [PATCH 30/52] [MOD] Modified docstring description for the 'query_idx' parameter --- stumpy/motifs.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/stumpy/motifs.py b/stumpy/motifs.py index 62ff9fe56..9a2de8fb3 100644 --- a/stumpy/motifs.py +++ b/stumpy/motifs.py @@ -367,9 +367,12 @@ def match( when comparing distances between subsequences. query_idx : int, default None - This parameter is used when the matrix profile is a self-join. - If a specific integer value is set, the parameter will ensure that the - self-match will be returned first. + This is the index position along the time series, `T`, where the query + subsequence, `Q`, is located. + `query_idx` should only be used when the matrix profile is a self-join and + should be set to `None` for matrix profiles computed from AB-joins. + If `query_idx` is set to a specific integer value, then this will help ensure + that the self-match will be returned first. normalize : bool, default True When set to `True`, this z-normalizes subsequences prior to computing distances. From b9c2e66af6e11519d6b4b5ccdbc91d422bbd7f98 Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 9 Mar 2022 20:51:46 +0100 Subject: [PATCH 31/52] [ADD] Added 'query_idx' to 'aamp_motifs' --- stumpy/aamp_motifs.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/stumpy/aamp_motifs.py b/stumpy/aamp_motifs.py index 5f93fc5d2..b0dae9836 100644 --- a/stumpy/aamp_motifs.py +++ b/stumpy/aamp_motifs.py @@ -295,6 +295,7 @@ def aamp_match( max_distance=None, max_matches=None, atol=1e-8, + query_idx=None, p=2.0, ): """ @@ -334,6 +335,14 @@ def aamp_match( The absolute tolerance parameter. This value will be added to `max_distance` when comparing distances between subsequences. + query_idx : int, default None + This is the index position along the time series, `T`, where the query + subsequence, `Q`, is located. + `query_idx` should only be used when the matrix profile is a self-join and + should be set to `None` for matrix profiles computed from AB-joins. + If `query_idx` is set to a specific integer value, then this will help ensure + that the self-match will be returned first. + p : float, default 2.0 The p-norm to apply for computing the Minkowski distance. @@ -381,7 +390,11 @@ def max_distance(D): matches = [] - candidate_idx = np.argmin(D) + if query_idx is not None: + candidate_idx = query_idx + else: + candidate_idx = np.argmin(D) + while ( D[candidate_idx] <= atol + max_distance and np.isfinite(D[candidate_idx]) From d34d67265d459c8937fd832ca71df208668362a2 Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 9 Mar 2022 21:47:44 +0100 Subject: [PATCH 32/52] [ADD] Added 'query_idx' to function call of 'aamp_match' --- stumpy/aamp_mmotifs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/stumpy/aamp_mmotifs.py b/stumpy/aamp_mmotifs.py index 7b067bdc5..e95f8e81e 100644 --- a/stumpy/aamp_mmotifs.py +++ b/stumpy/aamp_mmotifs.py @@ -170,6 +170,7 @@ def aamp_mmotifs( max_matches=max_matches, max_distance=max_distance, atol=atol, + query_idx=motif_idx, p=p, ) From f920c1221fbaf54dbd0eb8d48af0088dbc28b66f Mon Sep 17 00:00:00 2001 From: Sarah Date: Thu, 10 Mar 2022 19:50:16 +0100 Subject: [PATCH 33/52] [ADD] Added 'query_idx' to '_motifs' and '_aamp_motifs' --- stumpy/aamp_motifs.py | 1 + stumpy/motifs.py | 1 + 2 files changed, 2 insertions(+) diff --git a/stumpy/aamp_motifs.py b/stumpy/aamp_motifs.py index b0dae9836..5fc6cb6ca 100644 --- a/stumpy/aamp_motifs.py +++ b/stumpy/aamp_motifs.py @@ -118,6 +118,7 @@ def _aamp_motifs( max_matches=None, max_distance=max_distance, atol=atol, + query_idx=candidate_idx, p=p, ) diff --git a/stumpy/motifs.py b/stumpy/motifs.py index 9a2de8fb3..4a00a5b79 100644 --- a/stumpy/motifs.py +++ b/stumpy/motifs.py @@ -119,6 +119,7 @@ def _motifs( max_matches=None, max_distance=max_distance, atol=atol, + query_idx=candidate_idx, ) if len(query_matches) > min_neighbors: From 45221538fd6d88d85322d5e3b0a97ed0b11518f2 Mon Sep 17 00:00:00 2001 From: Sarah Date: Sat, 12 Mar 2022 12:13:19 +0100 Subject: [PATCH 34/52] [ADD] Added test function for 'max_matches=None' --- tests/test_mmotifs.py | 65 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index 599077283..94234de6f 100755 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -137,6 +137,71 @@ def test_motifs_multidimensional_with_deafault_parameters(): npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) +def test_motifs_multidimensional_one_motif_max_matches_none(): + # Find the best multidimensional motif when max_distance is None + + # Arrange + motif_distances_expected = np.array([[0.0000000e00, 1.1151008e-07]]) + motif_indices_expected = np.array([[2, 9]]) + motif_subspaces_expected = [np.array([1])] + motif_mdls_expected = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] + + # Act + T = np.array( + [ + [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], + [ + 7.3, + 3.2, + 5.0, + 9.1, + 8.2, + 7.3, + 4.8, + 8.2, + 10.0, + 0.0, + 4.1, + 3.2, + 2.3, + 0.1, + 1.4, + ], + [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], + [ + 0.1, + 1.3, + 3.0, + 2.1, + 6.2, + 1.3, + 9.5, + 10.0, + 1.8, + 2.0, + 2.1, + 5.2, + 1.3, + 0.5, + 4.3, + ], + ] + ) + m = 4 + + excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) + P, I = naive.mstump(T, m, excl_zone) + motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( + T, P, I, max_distance=None + ) + + # Assert + npt.assert_array_almost_equal(motif_distances_expected, motif_distances) + npt.assert_array_almost_equal(motif_indices_expected, motif_indices) + npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) + npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) + + def test_motifs_multidimensional_two_motifs_all_dimensions(): # Find the best two motif pairs From cd65aea52709c4b8dcfc6d01a97d09f9a5db4f5b Mon Sep 17 00:00:00 2001 From: Sarah Date: Sat, 12 Mar 2022 12:23:55 +0100 Subject: [PATCH 35/52] [FIX] Set 'max_matches=None' instead of 'max_distance=None' --- tests/test_mmotifs.py | 65 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index 94234de6f..a6efa6f98 100755 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -189,6 +189,71 @@ def test_motifs_multidimensional_one_motif_max_matches_none(): ) m = 4 + excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) + P, I = naive.mstump(T, m, excl_zone) + motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( + T, P, I, max_matches=None + ) + + # Assert + npt.assert_array_almost_equal(motif_distances_expected, motif_distances) + npt.assert_array_almost_equal(motif_indices_expected, motif_indices) + npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) + npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) + + +def test_motifs_multidimensional_more_motifs_cutoff(): + # Find the best multidimensional motifs if cutoff is set + + # Arrange + motif_distances_expected = np.array([[0.0000000e00, 1.1151008e-07]]) + motif_indices_expected = np.array([[2, 9]]) + motif_subspaces_expected = [np.array([1])] + motif_mdls_expected = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] + + # Act + T = np.array( + [ + [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], + [ + 7.3, + 3.2, + 5.0, + 9.1, + 8.2, + 7.3, + 4.8, + 8.2, + 10.0, + 0.0, + 4.1, + 3.2, + 2.3, + 0.1, + 1.4, + ], + [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], + [ + 0.1, + 1.3, + 3.0, + 2.1, + 6.2, + 1.3, + 9.5, + 10.0, + 1.8, + 2.0, + 2.1, + 5.2, + 1.3, + 0.5, + 4.3, + ], + ] + ) + m = 4 + excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( From 6e17bb0430d6f640586825a6ccd42ac4883a8e00 Mon Sep 17 00:00:00 2001 From: Sarah Date: Sat, 12 Mar 2022 12:41:33 +0100 Subject: [PATCH 36/52] [ADD] Add test function for cutoffs parameter --- tests/test_mmotifs.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index a6efa6f98..7e5efd78e 100755 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -202,8 +202,8 @@ def test_motifs_multidimensional_one_motif_max_matches_none(): npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) -def test_motifs_multidimensional_more_motifs_cutoff(): - # Find the best multidimensional motifs if cutoff is set +def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): + # Find the best multidimensional motif pairs if cutoffs is set # Arrange motif_distances_expected = np.array([[0.0000000e00, 1.1151008e-07]]) @@ -257,7 +257,7 @@ def test_motifs_multidimensional_more_motifs_cutoff(): excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( - T, P, I, max_distance=None + T, P, I, cutoffs=3, max_motifs=10 ) # Assert From b3c3a9e5d835193899933248bb513b78d2734a98 Mon Sep 17 00:00:00 2001 From: Sarah Date: Sat, 12 Mar 2022 13:01:08 +0100 Subject: [PATCH 37/52] [ADD] Add test function for setting 'max_matches=None' --- tests/test_aamp_mmotifs.py | 67 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py index a40e854fa..feed1c5f0 100755 --- a/tests/test_aamp_mmotifs.py +++ b/tests/test_aamp_mmotifs.py @@ -142,6 +142,73 @@ def test_motifs_multidimensional_with_default_parameters_and_max_distance(): npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) +def test_motifs_multidimensional_with_one_motif_max_matches_none(): + # Find the motif pair while setting 'max_matches=None' + + # Arrange + motif_distances_expected = np.array( + [[0.0, 1.41421356, 4.46430286, 6.85346628, 8.207923, 8.50529247]] + ) + motif_indices_expected = np.array([[2, 9, 0, 11, 7, 5]]) + motif_subspaces_expected = [np.array([3])] + motif_mdls_expected = [np.array([244.0, 260.67970001, 279.86313714, 281.35940001])] + + # Act + T = np.array( + [ + [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], + [ + 7.3, + 3.2, + 5.0, + 9.1, + 8.2, + 7.3, + 4.8, + 8.2, + 10.0, + 0.0, + 4.1, + 3.2, + 2.3, + 0.1, + 1.4, + ], + [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], + [ + 0.1, + 1.3, + 3.0, + 2.1, + 6.2, + 1.3, + 9.5, + 10.0, + 1.8, + 2.0, + 2.1, + 5.2, + 1.3, + 0.5, + 4.3, + ], + ] + ) + m = 4 + + excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) + P, I = naive.maamp(T, m, excl_zone) + motif_distances, motif_indices, motif_subspaces, motif_mdls = aamp_mmotifs( + T, P, I, max_distance=np.inf, max_matches=None + ) + + # Assert + npt.assert_array_almost_equal(motif_distances_expected, motif_distances) + npt.assert_array_almost_equal(motif_indices_expected, motif_indices) + npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) + npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) + + def test_motifs_multidimensional_two_motifs_all_dimensions(): # Find the best two motif pairs From e33a57ede4ae2a909ec0e3bb50ed18a9d13ec3c1 Mon Sep 17 00:00:00 2001 From: Sarah Date: Sat, 12 Mar 2022 13:07:53 +0100 Subject: [PATCH 38/52] [ADD] Added comment to explain function in more detail --- tests/test_mmotifs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index 7e5efd78e..7d05a4f27 100755 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -204,6 +204,7 @@ def test_motifs_multidimensional_one_motif_max_matches_none(): def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): # Find the best multidimensional motif pairs if cutoffs is set + # Only one pair here since 'max_motifs' is set per default # Arrange motif_distances_expected = np.array([[0.0000000e00, 1.1151008e-07]]) From 736120bbfd6509877d85e87015981c7d98c51847 Mon Sep 17 00:00:00 2001 From: Sarah Date: Sat, 12 Mar 2022 13:18:24 +0100 Subject: [PATCH 39/52] [ADD] Added test function for finding multiple motifs with the cutoffs parameter --- tests/test_aamp_mmotifs.py | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py index feed1c5f0..350747316 100755 --- a/tests/test_aamp_mmotifs.py +++ b/tests/test_aamp_mmotifs.py @@ -209,6 +209,74 @@ def test_motifs_multidimensional_with_one_motif_max_matches_none(): npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) +def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): + # Find the best multidimensional motif pairs if cutoffs is set + + # Arrange + motif_distances_expected = np.array([[0.0, 1.41421356], [0.0, 2.06639783]]) + motif_indices_expected = np.array([[2, 9], [0, 5]]) + motif_subspaces_expected = [np.array([3]), np.array([2])] + motif_mdls_expected = [ + np.array([244.0, 260.67970001, 279.86313714, 281.35940001]), + np.array([254.33985, 260.67970001, 279.86313714, 291.20703549]), + ] + + # Act + T = np.array( + [ + [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], + [ + 7.3, + 3.2, + 5.0, + 9.1, + 8.2, + 7.3, + 4.8, + 8.2, + 10.0, + 0.0, + 4.1, + 3.2, + 2.3, + 0.1, + 1.4, + ], + [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], + [ + 0.1, + 1.3, + 3.0, + 2.1, + 6.2, + 1.3, + 9.5, + 10.0, + 1.8, + 2.0, + 2.1, + 5.2, + 1.3, + 0.5, + 4.3, + ], + ] + ) + m = 4 + + excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) + P, I = naive.maamp(T, m, excl_zone) + motif_distances, motif_indices, motif_subspaces, motif_mdls = aamp_mmotifs( + T, P, I, max_distance=np.inf, cutoffs=3, max_matches=2, max_motifs=10 + ) + + # Assert + npt.assert_array_almost_equal(motif_distances_expected, motif_distances) + npt.assert_array_almost_equal(motif_indices_expected, motif_indices) + npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) + npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) + + def test_motifs_multidimensional_two_motifs_all_dimensions(): # Find the best two motif pairs From f7e3340a0cdcb27cf3306f768a4a83a24bdeb35d Mon Sep 17 00:00:00 2001 From: Sarah Date: Sun, 13 Mar 2022 13:00:47 +0100 Subject: [PATCH 40/52] [ADD] Added 'pragma: no cover' comment --- stumpy/aamp_mmotifs.py | 2 +- stumpy/mmotifs.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stumpy/aamp_mmotifs.py b/stumpy/aamp_mmotifs.py index e95f8e81e..10b43435a 100644 --- a/stumpy/aamp_mmotifs.py +++ b/stumpy/aamp_mmotifs.py @@ -160,7 +160,7 @@ def aamp_mmotifs( motif_value > cutoffs[k] or not np.isfinite(motif_value) or (isinstance(max_distance, float) and motif_value > max_distance) - ): + ): # pragma: no cover break query_matches = aamp_match( diff --git a/stumpy/mmotifs.py b/stumpy/mmotifs.py index a4643dc75..04460ae1c 100644 --- a/stumpy/mmotifs.py +++ b/stumpy/mmotifs.py @@ -179,7 +179,7 @@ def mmotifs( motif_value > cutoffs[k] or not np.isfinite(motif_value) or (isinstance(max_distance, float) and motif_value > max_distance) - ): + ): # pragma: no cover break query_matches = match( From f126d7e1826c805646e37048345cc2d5407c91ed Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 14 Mar 2022 20:43:58 +0100 Subject: [PATCH 41/52] [DEL] Remove comment --- tests/test_aamp_mmotifs.py | 3 --- tests/test_mmotifs.py | 3 --- 2 files changed, 6 deletions(-) diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py index 350747316..faa3f31a5 100755 --- a/tests/test_aamp_mmotifs.py +++ b/tests/test_aamp_mmotifs.py @@ -6,9 +6,6 @@ from stumpy import config -# These are tests for non-normalized multidimensional motif discovery - - def test_motifs_multidimensional_one_motif_all_dimensions(): # Find the two-dimensional motif pair diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index 7d05a4f27..ef2f185a3 100755 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -6,9 +6,6 @@ from stumpy import config -# These are tests for multidimensional motif discovery - - def test_motifs_multidimensional_one_motif_all_dimensions(): # Find the two-dimensional motif pair From 519ec5136f998f2acd6a136c5f14d953794a7be1 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 14 Mar 2022 20:55:38 +0100 Subject: [PATCH 42/52] [MOD & DEL] Modified function ordering and removed comments --- tests/test_aamp_mmotifs.py | 51 ++++++++++++++------------------------ tests/test_mmotifs.py | 45 +++++++++++---------------------- 2 files changed, 33 insertions(+), 63 deletions(-) diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py index faa3f31a5..c013903cd 100755 --- a/tests/test_aamp_mmotifs.py +++ b/tests/test_aamp_mmotifs.py @@ -6,16 +6,17 @@ from stumpy import config -def test_motifs_multidimensional_one_motif_all_dimensions(): - # Find the two-dimensional motif pair +def test_motifs_multidimensional_with_default_parameters_and_max_distance(): + # Find the motif pair while only setting the default parameters and + # max_distance - # Arrange - motif_distances_expected = np.array([[0.0, 2.87778559]]) - motif_indices_expected = np.array([[0, 5]]) - motif_subspaces_expected = [np.array([2, 1])] + motif_distances_expected = np.array( + [[0.0, 1.41421356, 4.46430286, 6.85346628, 8.207923, 8.50529247]] + ) + motif_indices_expected = np.array([[2, 9, 0, 11, 7, 5]]) + motif_subspaces_expected = [np.array([3])] motif_mdls_expected = [np.array([244.0, 260.67970001, 279.86313714, 281.35940001])] - # Act T = np.array( [ [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], @@ -61,21 +62,18 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.maamp(T, m, excl_zone) motif_distances, motif_indices, motif_subspaces, motif_mdls = aamp_mmotifs( - T, P, I, max_distance=np.inf, max_matches=2, k=1 + T, P, I, max_distance=np.inf ) - # Assert npt.assert_array_almost_equal(motif_distances_expected, motif_distances) npt.assert_array_almost_equal(motif_indices_expected, motif_indices) npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) -def test_motifs_multidimensional_with_default_parameters_and_max_distance(): - # Find the motif pair while only setting the default parameters and - # max_distance +def test_motifs_multidimensional_with_one_motif_max_matches_none(): + # Find the motif pair while setting 'max_matches=None' - # Arrange motif_distances_expected = np.array( [[0.0, 1.41421356, 4.46430286, 6.85346628, 8.207923, 8.50529247]] ) @@ -83,7 +81,6 @@ def test_motifs_multidimensional_with_default_parameters_and_max_distance(): motif_subspaces_expected = [np.array([3])] motif_mdls_expected = [np.array([244.0, 260.67970001, 279.86313714, 281.35940001])] - # Act T = np.array( [ [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], @@ -129,28 +126,23 @@ def test_motifs_multidimensional_with_default_parameters_and_max_distance(): excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.maamp(T, m, excl_zone) motif_distances, motif_indices, motif_subspaces, motif_mdls = aamp_mmotifs( - T, P, I, max_distance=np.inf + T, P, I, max_distance=np.inf, max_matches=None ) - # Assert npt.assert_array_almost_equal(motif_distances_expected, motif_distances) npt.assert_array_almost_equal(motif_indices_expected, motif_indices) npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) -def test_motifs_multidimensional_with_one_motif_max_matches_none(): - # Find the motif pair while setting 'max_matches=None' +def test_motifs_multidimensional_one_motif_all_dimensions(): + # Find the two-dimensional motif pair - # Arrange - motif_distances_expected = np.array( - [[0.0, 1.41421356, 4.46430286, 6.85346628, 8.207923, 8.50529247]] - ) - motif_indices_expected = np.array([[2, 9, 0, 11, 7, 5]]) - motif_subspaces_expected = [np.array([3])] + motif_distances_expected = np.array([[0.0, 2.87778559]]) + motif_indices_expected = np.array([[0, 5]]) + motif_subspaces_expected = [np.array([2, 1])] motif_mdls_expected = [np.array([244.0, 260.67970001, 279.86313714, 281.35940001])] - # Act T = np.array( [ [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], @@ -196,10 +188,9 @@ def test_motifs_multidimensional_with_one_motif_max_matches_none(): excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.maamp(T, m, excl_zone) motif_distances, motif_indices, motif_subspaces, motif_mdls = aamp_mmotifs( - T, P, I, max_distance=np.inf, max_matches=None + T, P, I, max_distance=np.inf, max_matches=2, k=1 ) - # Assert npt.assert_array_almost_equal(motif_distances_expected, motif_distances) npt.assert_array_almost_equal(motif_indices_expected, motif_indices) npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) @@ -209,7 +200,6 @@ def test_motifs_multidimensional_with_one_motif_max_matches_none(): def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): # Find the best multidimensional motif pairs if cutoffs is set - # Arrange motif_distances_expected = np.array([[0.0, 1.41421356], [0.0, 2.06639783]]) motif_indices_expected = np.array([[2, 9], [0, 5]]) motif_subspaces_expected = [np.array([3]), np.array([2])] @@ -218,7 +208,6 @@ def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): np.array([254.33985, 260.67970001, 279.86313714, 291.20703549]), ] - # Act T = np.array( [ [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], @@ -267,7 +256,6 @@ def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): T, P, I, max_distance=np.inf, cutoffs=3, max_matches=2, max_motifs=10 ) - # Assert npt.assert_array_almost_equal(motif_distances_expected, motif_distances) npt.assert_array_almost_equal(motif_indices_expected, motif_indices) npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) @@ -277,7 +265,6 @@ def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): def test_motifs_multidimensional_two_motifs_all_dimensions(): # Find the best two motif pairs - # Arrange motif_distances_expected = np.array([[0.0, 1.41421356], [0.0, 2.06639783]]) motif_indices_expected = np.array([[2, 9], [0, 5]]) motif_subspaces_expected = [np.array([3]), np.array([2])] @@ -286,7 +273,6 @@ def test_motifs_multidimensional_two_motifs_all_dimensions(): np.array([254.33985, 260.67970001, 279.86313714, 291.20703549]), ] - # Act T = np.array( [ [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], @@ -341,7 +327,6 @@ def test_motifs_multidimensional_two_motifs_all_dimensions(): max_motifs=2, ) - # Assert npt.assert_array_almost_equal(motif_distances_expected, motif_distances) npt.assert_array_almost_equal(motif_indices_expected, motif_indices) npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index ef2f185a3..3efd0343d 100755 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -6,16 +6,14 @@ from stumpy import config -def test_motifs_multidimensional_one_motif_all_dimensions(): - # Find the two-dimensional motif pair +def test_motifs_multidimensional_with_deafault_parameters(): + # Find the motif pair while only setting the default parameters - # Arrange - motif_distances_expected = np.array([[0.0, 0.20948156]]) + motif_distances_expected = np.array([[0.0000000e00, 1.1151008e-07]]) motif_indices_expected = np.array([[2, 9]]) - motif_subspaces_expected = [np.array([1, 3])] + motif_subspaces_expected = [np.array([1])] motif_mdls_expected = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] - # Act T = np.array( [ [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], @@ -60,27 +58,22 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) - motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( - T, P, I, max_distance=np.inf, max_matches=2, k=1 - ) + motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs(T, P, I) - # Assert npt.assert_array_almost_equal(motif_distances_expected, motif_distances) npt.assert_array_almost_equal(motif_indices_expected, motif_indices) npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) -def test_motifs_multidimensional_with_deafault_parameters(): - # Find the motif pair while only setting the default parameters +def test_motifs_multidimensional_one_motif_max_matches_none(): + # Find the best multidimensional motif when max_distance is None - # Arrange motif_distances_expected = np.array([[0.0000000e00, 1.1151008e-07]]) motif_indices_expected = np.array([[2, 9]]) motif_subspaces_expected = [np.array([1])] motif_mdls_expected = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] - # Act T = np.array( [ [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], @@ -125,25 +118,24 @@ def test_motifs_multidimensional_with_deafault_parameters(): excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) - motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs(T, P, I) + motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( + T, P, I, max_matches=None + ) - # Assert npt.assert_array_almost_equal(motif_distances_expected, motif_distances) npt.assert_array_almost_equal(motif_indices_expected, motif_indices) npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) -def test_motifs_multidimensional_one_motif_max_matches_none(): - # Find the best multidimensional motif when max_distance is None +def test_motifs_multidimensional_one_motif_all_dimensions(): + # Find the two-dimensional motif pair - # Arrange - motif_distances_expected = np.array([[0.0000000e00, 1.1151008e-07]]) + motif_distances_expected = np.array([[0.0, 0.20948156]]) motif_indices_expected = np.array([[2, 9]]) - motif_subspaces_expected = [np.array([1])] + motif_subspaces_expected = [np.array([1, 3])] motif_mdls_expected = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] - # Act T = np.array( [ [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], @@ -189,10 +181,9 @@ def test_motifs_multidimensional_one_motif_max_matches_none(): excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( - T, P, I, max_matches=None + T, P, I, max_distance=np.inf, max_matches=2, k=1 ) - # Assert npt.assert_array_almost_equal(motif_distances_expected, motif_distances) npt.assert_array_almost_equal(motif_indices_expected, motif_indices) npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) @@ -203,13 +194,11 @@ def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): # Find the best multidimensional motif pairs if cutoffs is set # Only one pair here since 'max_motifs' is set per default - # Arrange motif_distances_expected = np.array([[0.0000000e00, 1.1151008e-07]]) motif_indices_expected = np.array([[2, 9]]) motif_subspaces_expected = [np.array([1])] motif_mdls_expected = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] - # Act T = np.array( [ [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], @@ -258,7 +247,6 @@ def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): T, P, I, cutoffs=3, max_motifs=10 ) - # Assert npt.assert_array_almost_equal(motif_distances_expected, motif_distances) npt.assert_array_almost_equal(motif_indices_expected, motif_indices) npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) @@ -268,7 +256,6 @@ def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): def test_motifs_multidimensional_two_motifs_all_dimensions(): # Find the best two motif pairs - # Arrange motif_distances_expected = np.array( [[0.00000000e00, 1.11510080e-07], [1.68587394e-07, 2.58694429e-01]] ) @@ -279,7 +266,6 @@ def test_motifs_multidimensional_two_motifs_all_dimensions(): np.array([264.0, 280.0, 299.01955001, 310.51024953]), ] - # Act T = np.array( [ [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], @@ -328,7 +314,6 @@ def test_motifs_multidimensional_two_motifs_all_dimensions(): T, P, I, cutoffs=np.inf, max_motifs=2, max_distance=np.inf, max_matches=2 ) - # Assert npt.assert_array_almost_equal(motif_distances_expected, motif_distances) npt.assert_array_almost_equal(motif_indices_expected, motif_indices) npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) From 07e6f3927dfd723421a45cecf84fafd79034b9b3 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 14 Mar 2022 21:05:53 +0100 Subject: [PATCH 43/52] [MOD] Changed '_expected' to '_ref' --- tests/test_aamp_mmotifs.py | 80 +++++++++++++++++++------------------- tests/test_mmotifs.py | 80 +++++++++++++++++++------------------- 2 files changed, 80 insertions(+), 80 deletions(-) diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py index c013903cd..18a02a470 100755 --- a/tests/test_aamp_mmotifs.py +++ b/tests/test_aamp_mmotifs.py @@ -10,12 +10,12 @@ def test_motifs_multidimensional_with_default_parameters_and_max_distance(): # Find the motif pair while only setting the default parameters and # max_distance - motif_distances_expected = np.array( + motif_distances_ref = np.array( [[0.0, 1.41421356, 4.46430286, 6.85346628, 8.207923, 8.50529247]] ) - motif_indices_expected = np.array([[2, 9, 0, 11, 7, 5]]) - motif_subspaces_expected = [np.array([3])] - motif_mdls_expected = [np.array([244.0, 260.67970001, 279.86313714, 281.35940001])] + motif_indices_ref = np.array([[2, 9, 0, 11, 7, 5]]) + motif_subspaces_ref = [np.array([3])] + motif_mdls_ref = [np.array([244.0, 260.67970001, 279.86313714, 281.35940001])] T = np.array( [ @@ -65,21 +65,21 @@ def test_motifs_multidimensional_with_default_parameters_and_max_distance(): T, P, I, max_distance=np.inf ) - npt.assert_array_almost_equal(motif_distances_expected, motif_distances) - npt.assert_array_almost_equal(motif_indices_expected, motif_indices) - npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) - npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) + npt.assert_array_almost_equal(motif_distances_ref, motif_distances) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls) def test_motifs_multidimensional_with_one_motif_max_matches_none(): # Find the motif pair while setting 'max_matches=None' - motif_distances_expected = np.array( + motif_distances_ref = np.array( [[0.0, 1.41421356, 4.46430286, 6.85346628, 8.207923, 8.50529247]] ) - motif_indices_expected = np.array([[2, 9, 0, 11, 7, 5]]) - motif_subspaces_expected = [np.array([3])] - motif_mdls_expected = [np.array([244.0, 260.67970001, 279.86313714, 281.35940001])] + motif_indices_ref = np.array([[2, 9, 0, 11, 7, 5]]) + motif_subspaces_ref = [np.array([3])] + motif_mdls_ref = [np.array([244.0, 260.67970001, 279.86313714, 281.35940001])] T = np.array( [ @@ -129,19 +129,19 @@ def test_motifs_multidimensional_with_one_motif_max_matches_none(): T, P, I, max_distance=np.inf, max_matches=None ) - npt.assert_array_almost_equal(motif_distances_expected, motif_distances) - npt.assert_array_almost_equal(motif_indices_expected, motif_indices) - npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) - npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) + npt.assert_array_almost_equal(motif_distances_ref, motif_distances) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls) def test_motifs_multidimensional_one_motif_all_dimensions(): # Find the two-dimensional motif pair - motif_distances_expected = np.array([[0.0, 2.87778559]]) - motif_indices_expected = np.array([[0, 5]]) - motif_subspaces_expected = [np.array([2, 1])] - motif_mdls_expected = [np.array([244.0, 260.67970001, 279.86313714, 281.35940001])] + motif_distances_ref = np.array([[0.0, 2.87778559]]) + motif_indices_ref = np.array([[0, 5]]) + motif_subspaces_ref = [np.array([2, 1])] + motif_mdls_ref = [np.array([244.0, 260.67970001, 279.86313714, 281.35940001])] T = np.array( [ @@ -191,19 +191,19 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): T, P, I, max_distance=np.inf, max_matches=2, k=1 ) - npt.assert_array_almost_equal(motif_distances_expected, motif_distances) - npt.assert_array_almost_equal(motif_indices_expected, motif_indices) - npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) - npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) + npt.assert_array_almost_equal(motif_distances_ref, motif_distances) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls) def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): # Find the best multidimensional motif pairs if cutoffs is set - motif_distances_expected = np.array([[0.0, 1.41421356], [0.0, 2.06639783]]) - motif_indices_expected = np.array([[2, 9], [0, 5]]) - motif_subspaces_expected = [np.array([3]), np.array([2])] - motif_mdls_expected = [ + motif_distances_ref = np.array([[0.0, 1.41421356], [0.0, 2.06639783]]) + motif_indices_ref = np.array([[2, 9], [0, 5]]) + motif_subspaces_ref = [np.array([3]), np.array([2])] + motif_mdls_ref = [ np.array([244.0, 260.67970001, 279.86313714, 281.35940001]), np.array([254.33985, 260.67970001, 279.86313714, 291.20703549]), ] @@ -256,19 +256,19 @@ def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): T, P, I, max_distance=np.inf, cutoffs=3, max_matches=2, max_motifs=10 ) - npt.assert_array_almost_equal(motif_distances_expected, motif_distances) - npt.assert_array_almost_equal(motif_indices_expected, motif_indices) - npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) - npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) + npt.assert_array_almost_equal(motif_distances_ref, motif_distances) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls) def test_motifs_multidimensional_two_motifs_all_dimensions(): # Find the best two motif pairs - motif_distances_expected = np.array([[0.0, 1.41421356], [0.0, 2.06639783]]) - motif_indices_expected = np.array([[2, 9], [0, 5]]) - motif_subspaces_expected = [np.array([3]), np.array([2])] - motif_mdls_expected = [ + motif_distances_ref = np.array([[0.0, 1.41421356], [0.0, 2.06639783]]) + motif_indices_ref = np.array([[2, 9], [0, 5]]) + motif_subspaces_ref = [np.array([3]), np.array([2])] + motif_mdls_ref = [ np.array([244.0, 260.67970001, 279.86313714, 281.35940001]), np.array([254.33985, 260.67970001, 279.86313714, 291.20703549]), ] @@ -327,7 +327,7 @@ def test_motifs_multidimensional_two_motifs_all_dimensions(): max_motifs=2, ) - npt.assert_array_almost_equal(motif_distances_expected, motif_distances) - npt.assert_array_almost_equal(motif_indices_expected, motif_indices) - npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) - npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) + npt.assert_array_almost_equal(motif_distances_ref, motif_distances) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index 3efd0343d..33e444966 100755 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -9,10 +9,10 @@ def test_motifs_multidimensional_with_deafault_parameters(): # Find the motif pair while only setting the default parameters - motif_distances_expected = np.array([[0.0000000e00, 1.1151008e-07]]) - motif_indices_expected = np.array([[2, 9]]) - motif_subspaces_expected = [np.array([1])] - motif_mdls_expected = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] + motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) + motif_indices_ref = np.array([[2, 9]]) + motif_subspaces_ref = [np.array([1])] + motif_mdls_ref = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] T = np.array( [ @@ -60,19 +60,19 @@ def test_motifs_multidimensional_with_deafault_parameters(): P, I = naive.mstump(T, m, excl_zone) motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs(T, P, I) - npt.assert_array_almost_equal(motif_distances_expected, motif_distances) - npt.assert_array_almost_equal(motif_indices_expected, motif_indices) - npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) - npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) + npt.assert_array_almost_equal(motif_distances_ref, motif_distances) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls) def test_motifs_multidimensional_one_motif_max_matches_none(): # Find the best multidimensional motif when max_distance is None - motif_distances_expected = np.array([[0.0000000e00, 1.1151008e-07]]) - motif_indices_expected = np.array([[2, 9]]) - motif_subspaces_expected = [np.array([1])] - motif_mdls_expected = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] + motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) + motif_indices_ref = np.array([[2, 9]]) + motif_subspaces_ref = [np.array([1])] + motif_mdls_ref = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] T = np.array( [ @@ -122,19 +122,19 @@ def test_motifs_multidimensional_one_motif_max_matches_none(): T, P, I, max_matches=None ) - npt.assert_array_almost_equal(motif_distances_expected, motif_distances) - npt.assert_array_almost_equal(motif_indices_expected, motif_indices) - npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) - npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) + npt.assert_array_almost_equal(motif_distances_ref, motif_distances) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls) def test_motifs_multidimensional_one_motif_all_dimensions(): # Find the two-dimensional motif pair - motif_distances_expected = np.array([[0.0, 0.20948156]]) - motif_indices_expected = np.array([[2, 9]]) - motif_subspaces_expected = [np.array([1, 3])] - motif_mdls_expected = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] + motif_distances_ref = np.array([[0.0, 0.20948156]]) + motif_indices_ref = np.array([[2, 9]]) + motif_subspaces_ref = [np.array([1, 3])] + motif_mdls_ref = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] T = np.array( [ @@ -184,20 +184,20 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): T, P, I, max_distance=np.inf, max_matches=2, k=1 ) - npt.assert_array_almost_equal(motif_distances_expected, motif_distances) - npt.assert_array_almost_equal(motif_indices_expected, motif_indices) - npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) - npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) + npt.assert_array_almost_equal(motif_distances_ref, motif_distances) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls) def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): # Find the best multidimensional motif pairs if cutoffs is set # Only one pair here since 'max_motifs' is set per default - motif_distances_expected = np.array([[0.0000000e00, 1.1151008e-07]]) - motif_indices_expected = np.array([[2, 9]]) - motif_subspaces_expected = [np.array([1])] - motif_mdls_expected = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] + motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) + motif_indices_ref = np.array([[2, 9]]) + motif_subspaces_ref = [np.array([1])] + motif_mdls_ref = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] T = np.array( [ @@ -247,21 +247,21 @@ def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): T, P, I, cutoffs=3, max_motifs=10 ) - npt.assert_array_almost_equal(motif_distances_expected, motif_distances) - npt.assert_array_almost_equal(motif_indices_expected, motif_indices) - npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) - npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) + npt.assert_array_almost_equal(motif_distances_ref, motif_distances) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls) def test_motifs_multidimensional_two_motifs_all_dimensions(): # Find the best two motif pairs - motif_distances_expected = np.array( + motif_distances_ref = np.array( [[0.00000000e00, 1.11510080e-07], [1.68587394e-07, 2.58694429e-01]] ) - motif_indices_expected = np.array([[2, 9], [6, 1]]) - motif_subspaces_expected = [np.array([1]), np.array([2])] - motif_mdls_expected = [ + motif_indices_ref = np.array([[2, 9], [6, 1]]) + motif_subspaces_ref = [np.array([1]), np.array([2])] + motif_mdls_ref = [ np.array([232.0, 250.57542476, 260.0, 271.3509059]), np.array([264.0, 280.0, 299.01955001, 310.51024953]), ] @@ -314,7 +314,7 @@ def test_motifs_multidimensional_two_motifs_all_dimensions(): T, P, I, cutoffs=np.inf, max_motifs=2, max_distance=np.inf, max_matches=2 ) - npt.assert_array_almost_equal(motif_distances_expected, motif_distances) - npt.assert_array_almost_equal(motif_indices_expected, motif_indices) - npt.assert_array_almost_equal(motif_subspaces_expected, motif_subspaces) - npt.assert_array_almost_equal(motif_mdls_expected, motif_mdls) + npt.assert_array_almost_equal(motif_distances_ref, motif_distances) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls) From bd35644848ea476c07f1ea2779f0c600b4d91306 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 14 Mar 2022 21:18:17 +0100 Subject: [PATCH 44/52] [MOD] Marked comparison values with '_cmp' --- tests/test_aamp_mmotifs.py | 81 +++++++++++++++++++++++--------------- tests/test_mmotifs.py | 81 +++++++++++++++++++++++--------------- 2 files changed, 100 insertions(+), 62 deletions(-) diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py index 18a02a470..8b3fd4c75 100755 --- a/tests/test_aamp_mmotifs.py +++ b/tests/test_aamp_mmotifs.py @@ -61,14 +61,17 @@ def test_motifs_multidimensional_with_default_parameters_and_max_distance(): excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.maamp(T, m, excl_zone) - motif_distances, motif_indices, motif_subspaces, motif_mdls = aamp_mmotifs( - T, P, I, max_distance=np.inf - ) + ( + motif_distances_cmp, + motif_indices_cmp, + motif_subspaces_cmp, + motif_mdls_cmp, + ) = aamp_mmotifs(T, P, I, max_distance=np.inf) - npt.assert_array_almost_equal(motif_distances_ref, motif_distances) - npt.assert_array_almost_equal(motif_indices_ref, motif_indices) - npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces) - npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls) + npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces_cmp) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) def test_motifs_multidimensional_with_one_motif_max_matches_none(): @@ -125,14 +128,17 @@ def test_motifs_multidimensional_with_one_motif_max_matches_none(): excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.maamp(T, m, excl_zone) - motif_distances, motif_indices, motif_subspaces, motif_mdls = aamp_mmotifs( - T, P, I, max_distance=np.inf, max_matches=None - ) + ( + motif_distances_cmp, + motif_indices_cmp, + motif_subspaces_cmp, + motif_mdls_cmp, + ) = aamp_mmotifs(T, P, I, max_distance=np.inf, max_matches=None) - npt.assert_array_almost_equal(motif_distances_ref, motif_distances) - npt.assert_array_almost_equal(motif_indices_ref, motif_indices) - npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces) - npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls) + npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces_cmp) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) def test_motifs_multidimensional_one_motif_all_dimensions(): @@ -187,14 +193,17 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.maamp(T, m, excl_zone) - motif_distances, motif_indices, motif_subspaces, motif_mdls = aamp_mmotifs( - T, P, I, max_distance=np.inf, max_matches=2, k=1 - ) + ( + motif_distances_cmp, + motif_indices_cmp, + motif_subspaces_cmp, + motif_mdls_cmp, + ) = aamp_mmotifs(T, P, I, max_distance=np.inf, max_matches=2, k=1) - npt.assert_array_almost_equal(motif_distances_ref, motif_distances) - npt.assert_array_almost_equal(motif_indices_ref, motif_indices) - npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces) - npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls) + npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces_cmp) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): @@ -252,14 +261,19 @@ def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.maamp(T, m, excl_zone) - motif_distances, motif_indices, motif_subspaces, motif_mdls = aamp_mmotifs( + ( + motif_distances_cmp, + motif_indices_cmp, + motif_subspaces_cmp, + motif_mdls_cmp, + ) = aamp_mmotifs( T, P, I, max_distance=np.inf, cutoffs=3, max_matches=2, max_motifs=10 ) - npt.assert_array_almost_equal(motif_distances_ref, motif_distances) - npt.assert_array_almost_equal(motif_indices_ref, motif_indices) - npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces) - npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls) + npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces_cmp) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) def test_motifs_multidimensional_two_motifs_all_dimensions(): @@ -317,7 +331,12 @@ def test_motifs_multidimensional_two_motifs_all_dimensions(): excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.maamp(T, m, excl_zone) - motif_distances, motif_indices, motif_subspaces, motif_mdls = aamp_mmotifs( + ( + motif_distances_cmp, + motif_indices_cmp, + motif_subspaces_cmp, + motif_mdls_cmp, + ) = aamp_mmotifs( T, P, I, @@ -327,7 +346,7 @@ def test_motifs_multidimensional_two_motifs_all_dimensions(): max_motifs=2, ) - npt.assert_array_almost_equal(motif_distances_ref, motif_distances) - npt.assert_array_almost_equal(motif_indices_ref, motif_indices) - npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces) - npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls) + npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces_cmp) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index 33e444966..e6b04c94f 100755 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -58,12 +58,17 @@ def test_motifs_multidimensional_with_deafault_parameters(): excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) - motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs(T, P, I) + ( + motif_distances_cmp, + motif_indices_cmp, + motif_subspaces_cmp, + motif_mdls_cmp, + ) = mmotifs(T, P, I) - npt.assert_array_almost_equal(motif_distances_ref, motif_distances) - npt.assert_array_almost_equal(motif_indices_ref, motif_indices) - npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces) - npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls) + npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces_cmp) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) def test_motifs_multidimensional_one_motif_max_matches_none(): @@ -118,14 +123,17 @@ def test_motifs_multidimensional_one_motif_max_matches_none(): excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) - motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( - T, P, I, max_matches=None - ) + ( + motif_distances_cmp, + motif_indices_cmp, + motif_subspaces_cmp, + motif_mdls_cmp, + ) = mmotifs(T, P, I, max_matches=None) - npt.assert_array_almost_equal(motif_distances_ref, motif_distances) - npt.assert_array_almost_equal(motif_indices_ref, motif_indices) - npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces) - npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls) + npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces_cmp) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) def test_motifs_multidimensional_one_motif_all_dimensions(): @@ -180,14 +188,17 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) - motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( - T, P, I, max_distance=np.inf, max_matches=2, k=1 - ) + ( + motif_distances_cmp, + motif_indices_cmp, + motif_subspaces_cmp, + motif_mdls_cmp, + ) = mmotifs(T, P, I, max_distance=np.inf, max_matches=2, k=1) - npt.assert_array_almost_equal(motif_distances_ref, motif_distances) - npt.assert_array_almost_equal(motif_indices_ref, motif_indices) - npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces) - npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls) + npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces_cmp) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): @@ -243,14 +254,17 @@ def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) - motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( - T, P, I, cutoffs=3, max_motifs=10 - ) + ( + motif_distances_cmp, + motif_indices_cmp, + motif_subspaces_cmp, + motif_mdls_cmp, + ) = mmotifs(T, P, I, cutoffs=3, max_motifs=10) - npt.assert_array_almost_equal(motif_distances_ref, motif_distances) - npt.assert_array_almost_equal(motif_indices_ref, motif_indices) - npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces) - npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls) + npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces_cmp) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) def test_motifs_multidimensional_two_motifs_all_dimensions(): @@ -310,11 +324,16 @@ def test_motifs_multidimensional_two_motifs_all_dimensions(): excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) - motif_distances, motif_indices, motif_subspaces, motif_mdls = mmotifs( + ( + motif_distances_cmp, + motif_indices_cmp, + motif_subspaces_cmp, + motif_mdls_cmp, + ) = mmotifs( T, P, I, cutoffs=np.inf, max_motifs=2, max_distance=np.inf, max_matches=2 ) - npt.assert_array_almost_equal(motif_distances_ref, motif_distances) - npt.assert_array_almost_equal(motif_indices_ref, motif_indices) - npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces) - npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls) + npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces_cmp) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) From 8043e22dff9fa579e2704dc3cee37c874152425b Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 14 Mar 2022 21:54:06 +0100 Subject: [PATCH 45/52] [MOD] Renamed functions --- tests/test_aamp_mmotifs.py | 10 +++++----- tests/test_mmotifs.py | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py index 8b3fd4c75..cdb272918 100755 --- a/tests/test_aamp_mmotifs.py +++ b/tests/test_aamp_mmotifs.py @@ -6,7 +6,7 @@ from stumpy import config -def test_motifs_multidimensional_with_default_parameters_and_max_distance(): +def test_aamp_mmotifs_max_distance(): # Find the motif pair while only setting the default parameters and # max_distance @@ -74,7 +74,7 @@ def test_motifs_multidimensional_with_default_parameters_and_max_distance(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) -def test_motifs_multidimensional_with_one_motif_max_matches_none(): +def test_aamp_motifs_max_distance_max_matches_none(): # Find the motif pair while setting 'max_matches=None' motif_distances_ref = np.array( @@ -141,7 +141,7 @@ def test_motifs_multidimensional_with_one_motif_max_matches_none(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) -def test_motifs_multidimensional_one_motif_all_dimensions(): +def test_aamp_mmotifs_one_motif_k_chosen(): # Find the two-dimensional motif pair motif_distances_ref = np.array([[0.0, 2.87778559]]) @@ -206,7 +206,7 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) -def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): +def test_aamp_mmotifs_more_motifs_when_cutoffs_is_set(): # Find the best multidimensional motif pairs if cutoffs is set motif_distances_ref = np.array([[0.0, 1.41421356], [0.0, 2.06639783]]) @@ -276,7 +276,7 @@ def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) -def test_motifs_multidimensional_two_motifs_all_dimensions(): +def test_aamp_mmotifs_two_motif_pairs(): # Find the best two motif pairs motif_distances_ref = np.array([[0.0, 1.41421356], [0.0, 2.06639783]]) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index e6b04c94f..304bbd774 100755 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -6,7 +6,7 @@ from stumpy import config -def test_motifs_multidimensional_with_deafault_parameters(): +def test_mmotifs_with_deafault_parameters(): # Find the motif pair while only setting the default parameters motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) @@ -71,7 +71,7 @@ def test_motifs_multidimensional_with_deafault_parameters(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) -def test_motifs_multidimensional_one_motif_max_matches_none(): +def test_mmotifs_max_matches_none(): # Find the best multidimensional motif when max_distance is None motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) @@ -136,7 +136,7 @@ def test_motifs_multidimensional_one_motif_max_matches_none(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) -def test_motifs_multidimensional_one_motif_all_dimensions(): +def test_mmotifs_one_motif_k_chosen(): # Find the two-dimensional motif pair motif_distances_ref = np.array([[0.0, 0.20948156]]) @@ -201,9 +201,9 @@ def test_motifs_multidimensional_one_motif_all_dimensions(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) -def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): +def test_mmotifs_more_motifs_when_cutoffs_is_set(): # Find the best multidimensional motif pairs if cutoffs is set - # Only one pair here since 'max_motifs' is set per default + # Only one pair here since 'max_distance' is set per default motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) motif_indices_ref = np.array([[2, 9]]) @@ -267,7 +267,7 @@ def test_motifs_multidimensional_more_motifs_when_cutoffs_is_set(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) -def test_motifs_multidimensional_two_motifs_all_dimensions(): +def test_mmotifs_two_motifs_pairs(): # Find the best two motif pairs motif_distances_ref = np.array( From 42a9c3ae680cd70ebb532b0fa0875c1b0b234572 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 14 Mar 2022 22:31:42 +0100 Subject: [PATCH 46/52] [ADD] Added function that tests when cutoffs are a list --- tests/test_mmotifs.py | 69 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index 304bbd774..06aa20214 100755 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -202,7 +202,7 @@ def test_mmotifs_one_motif_k_chosen(): def test_mmotifs_more_motifs_when_cutoffs_is_set(): - # Find the best multidimensional motif pairs if cutoffs is set + # Find the best multidimensional motifs if cutoffs is set # Only one pair here since 'max_distance' is set per default motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) @@ -267,6 +267,73 @@ def test_mmotifs_more_motifs_when_cutoffs_is_set(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) +def test_mmotifs_more_motifs_cutoffs_is_list(): + # Find the best multidimensional motifs if cutoffs is set + # Only one pair here since 'max_distance' is set per default + + motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) + motif_indices_ref = np.array([[2, 9]]) + motif_subspaces_ref = [np.array([1])] + motif_mdls_ref = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] + + T = np.array( + [ + [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], + [ + 7.3, + 3.2, + 5.0, + 9.1, + 8.2, + 7.3, + 4.8, + 8.2, + 10.0, + 0.0, + 4.1, + 3.2, + 2.3, + 0.1, + 1.4, + ], + [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], + [ + 0.1, + 1.3, + 3.0, + 2.1, + 6.2, + 1.3, + 9.5, + 10.0, + 1.8, + 2.0, + 2.1, + 5.2, + 1.3, + 0.5, + 4.3, + ], + ] + ) + m = 4 + + cutoffs = [2, 3, 4, 5] + excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) + P, I = naive.mstump(T, m, excl_zone) + ( + motif_distances_cmp, + motif_indices_cmp, + motif_subspaces_cmp, + motif_mdls_cmp, + ) = mmotifs(T, P, I, cutoffs=cutoffs, max_motifs=10) + + npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces_cmp) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) + + def test_mmotifs_two_motifs_pairs(): # Find the best two motif pairs From 3cca0213962e06fa4cc22bacce9c5d2203ef4bdd Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 14 Mar 2022 22:44:10 +0100 Subject: [PATCH 47/52] [ADD] Also tested cutoffs as list in 'test_aamp_mmotifs' --- tests/test_aamp_mmotifs.py | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py index cdb272918..b7defa188 100755 --- a/tests/test_aamp_mmotifs.py +++ b/tests/test_aamp_mmotifs.py @@ -276,6 +276,74 @@ def test_aamp_mmotifs_more_motifs_when_cutoffs_is_set(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) +def test_aamp_mmotifs_more_motifs_cutoffs_as_list(): + # Find the best multidimensional motif pairs if cutoffs is a list + + motif_distances_ref = np.array([[0.0, 1.41421356]]) + motif_indices_ref = np.array([[2, 9]]) + motif_subspaces_ref = [np.array([3])] + motif_mdls_ref = [np.array([244.0, 260.67970001, 279.86313714, 281.35940001])] + + T = np.array( + [ + [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], + [ + 7.3, + 3.2, + 5.0, + 9.1, + 8.2, + 7.3, + 4.8, + 8.2, + 10.0, + 0.0, + 4.1, + 3.2, + 2.3, + 0.1, + 1.4, + ], + [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], + [ + 0.1, + 1.3, + 3.0, + 2.1, + 6.2, + 1.3, + 9.5, + 10.0, + 1.8, + 2.0, + 2.1, + 5.2, + 1.3, + 0.5, + 4.3, + ], + ] + ) + m = 4 + + cutoffs = [2, 3, 4, 5] + excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) + P, I = naive.maamp(T, m, excl_zone) + ( + motif_distances_cmp, + motif_indices_cmp, + motif_subspaces_cmp, + motif_mdls_cmp, + ) = aamp_mmotifs( + T, P, I, max_distance=np.inf, cutoffs=cutoffs, max_matches=2, max_motifs=10 + ) + + npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces_cmp) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) + + def test_aamp_mmotifs_two_motif_pairs(): # Find the best two motif pairs From 73afb696bbe124b6e085b6e0bfda6681709d9820 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 14 Mar 2022 22:46:55 +0100 Subject: [PATCH 48/52] [MOD] Changed function ordering --- tests/test_mmotifs.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index 06aa20214..e2f0ab455 100755 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -136,12 +136,13 @@ def test_mmotifs_max_matches_none(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) -def test_mmotifs_one_motif_k_chosen(): - # Find the two-dimensional motif pair +def test_mmotifs_more_motifs_when_cutoffs_is_set(): + # Find the best multidimensional motifs if cutoffs is set + # Only one pair here since 'max_distance' is set per default - motif_distances_ref = np.array([[0.0, 0.20948156]]) + motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) motif_indices_ref = np.array([[2, 9]]) - motif_subspaces_ref = [np.array([1, 3])] + motif_subspaces_ref = [np.array([1])] motif_mdls_ref = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] T = np.array( @@ -193,7 +194,7 @@ def test_mmotifs_one_motif_k_chosen(): motif_indices_cmp, motif_subspaces_cmp, motif_mdls_cmp, - ) = mmotifs(T, P, I, max_distance=np.inf, max_matches=2, k=1) + ) = mmotifs(T, P, I, cutoffs=3, max_motifs=10) npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) @@ -201,7 +202,7 @@ def test_mmotifs_one_motif_k_chosen(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) -def test_mmotifs_more_motifs_when_cutoffs_is_set(): +def test_mmotifs_more_motifs_cutoffs_is_list(): # Find the best multidimensional motifs if cutoffs is set # Only one pair here since 'max_distance' is set per default @@ -252,6 +253,7 @@ def test_mmotifs_more_motifs_when_cutoffs_is_set(): ) m = 4 + cutoffs = [2, 3, 4, 5] excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) ( @@ -259,7 +261,7 @@ def test_mmotifs_more_motifs_when_cutoffs_is_set(): motif_indices_cmp, motif_subspaces_cmp, motif_mdls_cmp, - ) = mmotifs(T, P, I, cutoffs=3, max_motifs=10) + ) = mmotifs(T, P, I, cutoffs=cutoffs, max_motifs=10) npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) @@ -267,13 +269,12 @@ def test_mmotifs_more_motifs_when_cutoffs_is_set(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) -def test_mmotifs_more_motifs_cutoffs_is_list(): - # Find the best multidimensional motifs if cutoffs is set - # Only one pair here since 'max_distance' is set per default +def test_mmotifs_one_motif_k_chosen(): + # Find the two-dimensional motif pair - motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) + motif_distances_ref = np.array([[0.0, 0.20948156]]) motif_indices_ref = np.array([[2, 9]]) - motif_subspaces_ref = [np.array([1])] + motif_subspaces_ref = [np.array([1, 3])] motif_mdls_ref = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] T = np.array( @@ -318,7 +319,6 @@ def test_mmotifs_more_motifs_cutoffs_is_list(): ) m = 4 - cutoffs = [2, 3, 4, 5] excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) ( @@ -326,7 +326,7 @@ def test_mmotifs_more_motifs_cutoffs_is_list(): motif_indices_cmp, motif_subspaces_cmp, motif_mdls_cmp, - ) = mmotifs(T, P, I, cutoffs=cutoffs, max_motifs=10) + ) = mmotifs(T, P, I, max_distance=np.inf, max_matches=2, k=1) npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) From ed8ea7fc4d9ef3804b2ead8fdd1459627f885e12 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 14 Mar 2022 23:21:35 +0100 Subject: [PATCH 49/52] [MOD] Declare time series array once at the beginning --- tests/test_aamp_mmotifs.py | 251 +++++-------------------------------- tests/test_mmotifs.py | 245 ++++-------------------------------- 2 files changed, 53 insertions(+), 443 deletions(-) diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py index b7defa188..680b8ab71 100755 --- a/tests/test_aamp_mmotifs.py +++ b/tests/test_aamp_mmotifs.py @@ -1,23 +1,14 @@ import numpy as np import numpy.testing as npt import naive +import pytest from stumpy.aamp_mmotifs import aamp_mmotifs from stumpy import config -def test_aamp_mmotifs_max_distance(): - # Find the motif pair while only setting the default parameters and - # max_distance - - motif_distances_ref = np.array( - [[0.0, 1.41421356, 4.46430286, 6.85346628, 8.207923, 8.50529247]] - ) - motif_indices_ref = np.array([[2, 9, 0, 11, 7, 5]]) - motif_subspaces_ref = [np.array([3])] - motif_mdls_ref = [np.array([244.0, 260.67970001, 279.86313714, 281.35940001])] - - T = np.array( +test_data = [ + np.array( [ [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], [ @@ -57,8 +48,22 @@ def test_aamp_mmotifs_max_distance(): ], ] ) - m = 4 +] + + +@pytest.mark.parametrize("T", test_data) +def test_aamp_mmotifs_max_distance(T): + # Find the motif pair while only setting the default parameters and + # max_distance + + motif_distances_ref = np.array( + [[0.0, 1.41421356, 4.46430286, 6.85346628, 8.207923, 8.50529247]] + ) + motif_indices_ref = np.array([[2, 9, 0, 11, 7, 5]]) + motif_subspaces_ref = [np.array([3])] + motif_mdls_ref = [np.array([244.0, 260.67970001, 279.86313714, 281.35940001])] + m = 4 excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.maamp(T, m, excl_zone) ( @@ -74,7 +79,8 @@ def test_aamp_mmotifs_max_distance(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) -def test_aamp_motifs_max_distance_max_matches_none(): +@pytest.mark.parametrize("T", test_data) +def test_aamp_motifs_max_distance_max_matches_none(T): # Find the motif pair while setting 'max_matches=None' motif_distances_ref = np.array( @@ -84,48 +90,7 @@ def test_aamp_motifs_max_distance_max_matches_none(): motif_subspaces_ref = [np.array([3])] motif_mdls_ref = [np.array([244.0, 260.67970001, 279.86313714, 281.35940001])] - T = np.array( - [ - [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], - [ - 7.3, - 3.2, - 5.0, - 9.1, - 8.2, - 7.3, - 4.8, - 8.2, - 10.0, - 0.0, - 4.1, - 3.2, - 2.3, - 0.1, - 1.4, - ], - [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], - [ - 0.1, - 1.3, - 3.0, - 2.1, - 6.2, - 1.3, - 9.5, - 10.0, - 1.8, - 2.0, - 2.1, - 5.2, - 1.3, - 0.5, - 4.3, - ], - ] - ) m = 4 - excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.maamp(T, m, excl_zone) ( @@ -141,7 +106,8 @@ def test_aamp_motifs_max_distance_max_matches_none(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) -def test_aamp_mmotifs_one_motif_k_chosen(): +@pytest.mark.parametrize("T", test_data) +def test_aamp_mmotifs_one_motif_k_chosen(T): # Find the two-dimensional motif pair motif_distances_ref = np.array([[0.0, 2.87778559]]) @@ -149,48 +115,7 @@ def test_aamp_mmotifs_one_motif_k_chosen(): motif_subspaces_ref = [np.array([2, 1])] motif_mdls_ref = [np.array([244.0, 260.67970001, 279.86313714, 281.35940001])] - T = np.array( - [ - [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], - [ - 7.3, - 3.2, - 5.0, - 9.1, - 8.2, - 7.3, - 4.8, - 8.2, - 10.0, - 0.0, - 4.1, - 3.2, - 2.3, - 0.1, - 1.4, - ], - [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], - [ - 0.1, - 1.3, - 3.0, - 2.1, - 6.2, - 1.3, - 9.5, - 10.0, - 1.8, - 2.0, - 2.1, - 5.2, - 1.3, - 0.5, - 4.3, - ], - ] - ) m = 4 - excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.maamp(T, m, excl_zone) ( @@ -206,7 +131,8 @@ def test_aamp_mmotifs_one_motif_k_chosen(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) -def test_aamp_mmotifs_more_motifs_when_cutoffs_is_set(): +@pytest.mark.parametrize("T", test_data) +def test_aamp_mmotifs_more_motifs_when_cutoffs_is_set(T): # Find the best multidimensional motif pairs if cutoffs is set motif_distances_ref = np.array([[0.0, 1.41421356], [0.0, 2.06639783]]) @@ -217,48 +143,7 @@ def test_aamp_mmotifs_more_motifs_when_cutoffs_is_set(): np.array([254.33985, 260.67970001, 279.86313714, 291.20703549]), ] - T = np.array( - [ - [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], - [ - 7.3, - 3.2, - 5.0, - 9.1, - 8.2, - 7.3, - 4.8, - 8.2, - 10.0, - 0.0, - 4.1, - 3.2, - 2.3, - 0.1, - 1.4, - ], - [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], - [ - 0.1, - 1.3, - 3.0, - 2.1, - 6.2, - 1.3, - 9.5, - 10.0, - 1.8, - 2.0, - 2.1, - 5.2, - 1.3, - 0.5, - 4.3, - ], - ] - ) m = 4 - excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.maamp(T, m, excl_zone) ( @@ -276,7 +161,8 @@ def test_aamp_mmotifs_more_motifs_when_cutoffs_is_set(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) -def test_aamp_mmotifs_more_motifs_cutoffs_as_list(): +@pytest.mark.parametrize("T", test_data) +def test_aamp_mmotifs_more_motifs_cutoffs_as_list(T): # Find the best multidimensional motif pairs if cutoffs is a list motif_distances_ref = np.array([[0.0, 1.41421356]]) @@ -284,48 +170,7 @@ def test_aamp_mmotifs_more_motifs_cutoffs_as_list(): motif_subspaces_ref = [np.array([3])] motif_mdls_ref = [np.array([244.0, 260.67970001, 279.86313714, 281.35940001])] - T = np.array( - [ - [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], - [ - 7.3, - 3.2, - 5.0, - 9.1, - 8.2, - 7.3, - 4.8, - 8.2, - 10.0, - 0.0, - 4.1, - 3.2, - 2.3, - 0.1, - 1.4, - ], - [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], - [ - 0.1, - 1.3, - 3.0, - 2.1, - 6.2, - 1.3, - 9.5, - 10.0, - 1.8, - 2.0, - 2.1, - 5.2, - 1.3, - 0.5, - 4.3, - ], - ] - ) m = 4 - cutoffs = [2, 3, 4, 5] excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.maamp(T, m, excl_zone) @@ -344,7 +189,8 @@ def test_aamp_mmotifs_more_motifs_cutoffs_as_list(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) -def test_aamp_mmotifs_two_motif_pairs(): +@pytest.mark.parametrize("T", test_data) +def test_aamp_mmotifs_two_motif_pairs(T): # Find the best two motif pairs motif_distances_ref = np.array([[0.0, 1.41421356], [0.0, 2.06639783]]) @@ -355,48 +201,7 @@ def test_aamp_mmotifs_two_motif_pairs(): np.array([254.33985, 260.67970001, 279.86313714, 291.20703549]), ] - T = np.array( - [ - [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], - [ - 7.3, - 3.2, - 5.0, - 9.1, - 8.2, - 7.3, - 4.8, - 8.2, - 10.0, - 0.0, - 4.1, - 3.2, - 2.3, - 0.1, - 1.4, - ], - [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], - [ - 0.1, - 1.3, - 3.0, - 2.1, - 6.2, - 1.3, - 9.5, - 10.0, - 1.8, - 2.0, - 2.1, - 5.2, - 1.3, - 0.5, - 4.3, - ], - ] - ) m = 4 - excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.maamp(T, m, excl_zone) ( diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index e2f0ab455..146e13df8 100755 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -1,20 +1,14 @@ import numpy as np import numpy.testing as npt import naive +import pytest from stumpy.mmotifs import mmotifs from stumpy import config -def test_mmotifs_with_deafault_parameters(): - # Find the motif pair while only setting the default parameters - - motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) - motif_indices_ref = np.array([[2, 9]]) - motif_subspaces_ref = [np.array([1])] - motif_mdls_ref = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] - - T = np.array( +test_data = [ + np.array( [ [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], [ @@ -54,8 +48,19 @@ def test_mmotifs_with_deafault_parameters(): ], ] ) - m = 4 +] + + +@pytest.mark.parametrize("T", test_data) +def test_mmotifs_with_deafault_parameters(T): + # Find the motif pair while only setting the default parameters + + motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) + motif_indices_ref = np.array([[2, 9]]) + motif_subspaces_ref = [np.array([1])] + motif_mdls_ref = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] + m = 4 excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) ( @@ -71,7 +76,8 @@ def test_mmotifs_with_deafault_parameters(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) -def test_mmotifs_max_matches_none(): +@pytest.mark.parametrize("T", test_data) +def test_mmotifs_max_matches_none(T): # Find the best multidimensional motif when max_distance is None motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) @@ -79,48 +85,7 @@ def test_mmotifs_max_matches_none(): motif_subspaces_ref = [np.array([1])] motif_mdls_ref = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] - T = np.array( - [ - [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], - [ - 7.3, - 3.2, - 5.0, - 9.1, - 8.2, - 7.3, - 4.8, - 8.2, - 10.0, - 0.0, - 4.1, - 3.2, - 2.3, - 0.1, - 1.4, - ], - [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], - [ - 0.1, - 1.3, - 3.0, - 2.1, - 6.2, - 1.3, - 9.5, - 10.0, - 1.8, - 2.0, - 2.1, - 5.2, - 1.3, - 0.5, - 4.3, - ], - ] - ) m = 4 - excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) ( @@ -136,7 +101,8 @@ def test_mmotifs_max_matches_none(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) -def test_mmotifs_more_motifs_when_cutoffs_is_set(): +@pytest.mark.parametrize("T", test_data) +def test_mmotifs_more_motifs_when_cutoffs_is_set(T): # Find the best multidimensional motifs if cutoffs is set # Only one pair here since 'max_distance' is set per default @@ -145,48 +111,7 @@ def test_mmotifs_more_motifs_when_cutoffs_is_set(): motif_subspaces_ref = [np.array([1])] motif_mdls_ref = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] - T = np.array( - [ - [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], - [ - 7.3, - 3.2, - 5.0, - 9.1, - 8.2, - 7.3, - 4.8, - 8.2, - 10.0, - 0.0, - 4.1, - 3.2, - 2.3, - 0.1, - 1.4, - ], - [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], - [ - 0.1, - 1.3, - 3.0, - 2.1, - 6.2, - 1.3, - 9.5, - 10.0, - 1.8, - 2.0, - 2.1, - 5.2, - 1.3, - 0.5, - 4.3, - ], - ] - ) m = 4 - excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) ( @@ -202,7 +127,8 @@ def test_mmotifs_more_motifs_when_cutoffs_is_set(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) -def test_mmotifs_more_motifs_cutoffs_is_list(): +@pytest.mark.parametrize("T", test_data) +def test_mmotifs_more_motifs_cutoffs_is_list(T): # Find the best multidimensional motifs if cutoffs is set # Only one pair here since 'max_distance' is set per default @@ -211,48 +137,7 @@ def test_mmotifs_more_motifs_cutoffs_is_list(): motif_subspaces_ref = [np.array([1])] motif_mdls_ref = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] - T = np.array( - [ - [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], - [ - 7.3, - 3.2, - 5.0, - 9.1, - 8.2, - 7.3, - 4.8, - 8.2, - 10.0, - 0.0, - 4.1, - 3.2, - 2.3, - 0.1, - 1.4, - ], - [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], - [ - 0.1, - 1.3, - 3.0, - 2.1, - 6.2, - 1.3, - 9.5, - 10.0, - 1.8, - 2.0, - 2.1, - 5.2, - 1.3, - 0.5, - 4.3, - ], - ] - ) m = 4 - cutoffs = [2, 3, 4, 5] excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) @@ -269,7 +154,8 @@ def test_mmotifs_more_motifs_cutoffs_is_list(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) -def test_mmotifs_one_motif_k_chosen(): +@pytest.mark.parametrize("T", test_data) +def test_mmotifs_one_motif_k_chosen(T): # Find the two-dimensional motif pair motif_distances_ref = np.array([[0.0, 0.20948156]]) @@ -277,48 +163,7 @@ def test_mmotifs_one_motif_k_chosen(): motif_subspaces_ref = [np.array([1, 3])] motif_mdls_ref = [np.array([232.0, 250.57542476, 260.0, 271.3509059])] - T = np.array( - [ - [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], - [ - 7.3, - 3.2, - 5.0, - 9.1, - 8.2, - 7.3, - 4.8, - 8.2, - 10.0, - 0.0, - 4.1, - 3.2, - 2.3, - 0.1, - 1.4, - ], - [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], - [ - 0.1, - 1.3, - 3.0, - 2.1, - 6.2, - 1.3, - 9.5, - 10.0, - 1.8, - 2.0, - 2.1, - 5.2, - 1.3, - 0.5, - 4.3, - ], - ] - ) m = 4 - excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) ( @@ -334,7 +179,8 @@ def test_mmotifs_one_motif_k_chosen(): npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) -def test_mmotifs_two_motifs_pairs(): +@pytest.mark.parametrize("T", test_data) +def test_mmotifs_two_motif_pairs(T): # Find the best two motif pairs motif_distances_ref = np.array( @@ -347,48 +193,7 @@ def test_mmotifs_two_motifs_pairs(): np.array([264.0, 280.0, 299.01955001, 310.51024953]), ] - T = np.array( - [ - [5.2, 0.1, 3.5, 3.4, 7.1, 9.8, 3.7, 5.0, 2.1, 4.3, 7.5, 6.8, 8.0, 8.1, 1.2], - [ - 7.3, - 3.2, - 5.0, - 9.1, - 8.2, - 7.3, - 4.8, - 8.2, - 10.0, - 0.0, - 4.1, - 3.2, - 2.3, - 0.1, - 1.4, - ], - [6.2, 7.6, 7.6, 8.4, 1.1, 5.9, 9.2, 8.5, 9.3, 4.6, 3.5, 0.0, 3.1, 5.3, 0.9], - [ - 0.1, - 1.3, - 3.0, - 2.1, - 6.2, - 1.3, - 9.5, - 10.0, - 1.8, - 2.0, - 2.1, - 5.2, - 1.3, - 0.5, - 4.3, - ], - ] - ) m = 4 - excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) P, I = naive.mstump(T, m, excl_zone) ( From 97730b94a9b8e5356cbf95db474ccf113f92f606 Mon Sep 17 00:00:00 2001 From: Sarah Date: Tue, 15 Mar 2022 11:33:25 +0100 Subject: [PATCH 50/52] [MOD] Renamed functions --- tests/test_aamp_mmotifs.py | 15 ++++----------- tests/test_mmotifs.py | 12 ++---------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py index 680b8ab71..812adb79c 100755 --- a/tests/test_aamp_mmotifs.py +++ b/tests/test_aamp_mmotifs.py @@ -53,8 +53,6 @@ @pytest.mark.parametrize("T", test_data) def test_aamp_mmotifs_max_distance(T): - # Find the motif pair while only setting the default parameters and - # max_distance motif_distances_ref = np.array( [[0.0, 1.41421356, 4.46430286, 6.85346628, 8.207923, 8.50529247]] @@ -81,7 +79,6 @@ def test_aamp_mmotifs_max_distance(T): @pytest.mark.parametrize("T", test_data) def test_aamp_motifs_max_distance_max_matches_none(T): - # Find the motif pair while setting 'max_matches=None' motif_distances_ref = np.array( [[0.0, 1.41421356, 4.46430286, 6.85346628, 8.207923, 8.50529247]] @@ -107,8 +104,7 @@ def test_aamp_motifs_max_distance_max_matches_none(T): @pytest.mark.parametrize("T", test_data) -def test_aamp_mmotifs_one_motif_k_chosen(T): - # Find the two-dimensional motif pair +def test_aamp_mmotifs_exactly_one_motif_pair_k_chosen(T): motif_distances_ref = np.array([[0.0, 2.87778559]]) motif_indices_ref = np.array([[0, 5]]) @@ -132,8 +128,7 @@ def test_aamp_mmotifs_one_motif_k_chosen(T): @pytest.mark.parametrize("T", test_data) -def test_aamp_mmotifs_more_motifs_when_cutoffs_is_set(T): - # Find the best multidimensional motif pairs if cutoffs is set +def test_aamp_mmotifs_more_motif_pairs_when_cutoffs_is_set(T): motif_distances_ref = np.array([[0.0, 1.41421356], [0.0, 2.06639783]]) motif_indices_ref = np.array([[2, 9], [0, 5]]) @@ -162,8 +157,7 @@ def test_aamp_mmotifs_more_motifs_when_cutoffs_is_set(T): @pytest.mark.parametrize("T", test_data) -def test_aamp_mmotifs_more_motifs_cutoffs_as_list(T): - # Find the best multidimensional motif pairs if cutoffs is a list +def test_aamp_mmotifs_more_motif_pairs_cutoffs_as_list(T): motif_distances_ref = np.array([[0.0, 1.41421356]]) motif_indices_ref = np.array([[2, 9]]) @@ -190,8 +184,7 @@ def test_aamp_mmotifs_more_motifs_cutoffs_as_list(T): @pytest.mark.parametrize("T", test_data) -def test_aamp_mmotifs_two_motif_pairs(T): - # Find the best two motif pairs +def test_aamp_mmotifs_exactly_two_motif_pairs(T): motif_distances_ref = np.array([[0.0, 1.41421356], [0.0, 2.06639783]]) motif_indices_ref = np.array([[2, 9], [0, 5]]) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index 146e13df8..24d93963c 100755 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -53,7 +53,6 @@ @pytest.mark.parametrize("T", test_data) def test_mmotifs_with_deafault_parameters(T): - # Find the motif pair while only setting the default parameters motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) motif_indices_ref = np.array([[2, 9]]) @@ -78,7 +77,6 @@ def test_mmotifs_with_deafault_parameters(T): @pytest.mark.parametrize("T", test_data) def test_mmotifs_max_matches_none(T): - # Find the best multidimensional motif when max_distance is None motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) motif_indices_ref = np.array([[2, 9]]) @@ -103,8 +101,6 @@ def test_mmotifs_max_matches_none(T): @pytest.mark.parametrize("T", test_data) def test_mmotifs_more_motifs_when_cutoffs_is_set(T): - # Find the best multidimensional motifs if cutoffs is set - # Only one pair here since 'max_distance' is set per default motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) motif_indices_ref = np.array([[2, 9]]) @@ -129,8 +125,6 @@ def test_mmotifs_more_motifs_when_cutoffs_is_set(T): @pytest.mark.parametrize("T", test_data) def test_mmotifs_more_motifs_cutoffs_is_list(T): - # Find the best multidimensional motifs if cutoffs is set - # Only one pair here since 'max_distance' is set per default motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) motif_indices_ref = np.array([[2, 9]]) @@ -155,8 +149,7 @@ def test_mmotifs_more_motifs_cutoffs_is_list(T): @pytest.mark.parametrize("T", test_data) -def test_mmotifs_one_motif_k_chosen(T): - # Find the two-dimensional motif pair +def test_mmotifs_one_motif_pair_k_chosen(T): motif_distances_ref = np.array([[0.0, 0.20948156]]) motif_indices_ref = np.array([[2, 9]]) @@ -180,8 +173,7 @@ def test_mmotifs_one_motif_k_chosen(T): @pytest.mark.parametrize("T", test_data) -def test_mmotifs_two_motif_pairs(T): - # Find the best two motif pairs +def test_mmotifs_exactly_two_motif_pairs(T): motif_distances_ref = np.array( [[0.00000000e00, 1.11510080e-07], [1.68587394e-07, 2.58694429e-01]] From 1f97aa1fdfc9b9294d506dbdbbd0e89035e5b631 Mon Sep 17 00:00:00 2001 From: Sarah Date: Tue, 15 Mar 2022 11:55:39 +0100 Subject: [PATCH 51/52] [ADD] Added function with default parameters --- tests/test_aamp_mmotifs.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py index 812adb79c..a5f0505d9 100755 --- a/tests/test_aamp_mmotifs.py +++ b/tests/test_aamp_mmotifs.py @@ -51,6 +51,36 @@ ] +def test_aamp_mmotifs_default_parameters(): + + motif_distances_ref = np.array( + [[0.0, 0.06315749, 0.25275899, 0.34087884, 0.3452315]] + ) + motif_indices_ref = np.array([[19, 77, 63, 52, 71]]) + motif_subspaces_ref = [np.array([2])] + motif_mdls_ref = [ + np.array([411.60964047, 423.69925001, 449.11032383, 476.95855027, 506.62406252]) + ] + + np.random.seed(0) + T = np.random.rand(500).reshape(5, 100) + + m = 5 + excl_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM)) + P, I = naive.maamp(T, m, excl_zone) + ( + motif_distances_cmp, + motif_indices_cmp, + motif_subspaces_cmp, + motif_mdls_cmp, + ) = aamp_mmotifs(T, P, I) + + npt.assert_array_almost_equal(motif_distances_ref, motif_distances_cmp) + npt.assert_array_almost_equal(motif_indices_ref, motif_indices_cmp) + npt.assert_array_almost_equal(motif_subspaces_ref, motif_subspaces_cmp) + npt.assert_array_almost_equal(motif_mdls_ref, motif_mdls_cmp) + + @pytest.mark.parametrize("T", test_data) def test_aamp_mmotifs_max_distance(T): From 76848253a1c2218d3a958e9b3c8759e86d152ee1 Mon Sep 17 00:00:00 2001 From: Sarah Date: Tue, 15 Mar 2022 14:46:24 +0100 Subject: [PATCH 52/52] [FIX] Fixed function names --- tests/test_aamp_mmotifs.py | 8 ++++---- tests/test_mmotifs.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py index a5f0505d9..49100a836 100755 --- a/tests/test_aamp_mmotifs.py +++ b/tests/test_aamp_mmotifs.py @@ -108,7 +108,7 @@ def test_aamp_mmotifs_max_distance(T): @pytest.mark.parametrize("T", test_data) -def test_aamp_motifs_max_distance_max_matches_none(T): +def test_aamp_mmotifs_max_distance_max_matches_none(T): motif_distances_ref = np.array( [[0.0, 1.41421356, 4.46430286, 6.85346628, 8.207923, 8.50529247]] @@ -134,7 +134,7 @@ def test_aamp_motifs_max_distance_max_matches_none(T): @pytest.mark.parametrize("T", test_data) -def test_aamp_mmotifs_exactly_one_motif_pair_k_chosen(T): +def test_aamp_mmotifs_max_motifs_1_max_matches_2_k_1(T): motif_distances_ref = np.array([[0.0, 2.87778559]]) motif_indices_ref = np.array([[0, 5]]) @@ -158,7 +158,7 @@ def test_aamp_mmotifs_exactly_one_motif_pair_k_chosen(T): @pytest.mark.parametrize("T", test_data) -def test_aamp_mmotifs_more_motif_pairs_when_cutoffs_is_set(T): +def test_aamp_mmotifs_more_motif_pairs_cutoffs_3(T): motif_distances_ref = np.array([[0.0, 1.41421356], [0.0, 2.06639783]]) motif_indices_ref = np.array([[2, 9], [0, 5]]) @@ -214,7 +214,7 @@ def test_aamp_mmotifs_more_motif_pairs_cutoffs_as_list(T): @pytest.mark.parametrize("T", test_data) -def test_aamp_mmotifs_exactly_two_motif_pairs(T): +def test_aamp_mmotifs_two_motif_pairs_max_motifs_2(T): motif_distances_ref = np.array([[0.0, 1.41421356], [0.0, 2.06639783]]) motif_indices_ref = np.array([[2, 9], [0, 5]]) diff --git a/tests/test_mmotifs.py b/tests/test_mmotifs.py index 24d93963c..75c8e19ce 100755 --- a/tests/test_mmotifs.py +++ b/tests/test_mmotifs.py @@ -52,7 +52,7 @@ @pytest.mark.parametrize("T", test_data) -def test_mmotifs_with_deafault_parameters(T): +def test_mmotifs_with_default_parameters(T): motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) motif_indices_ref = np.array([[2, 9]]) @@ -100,7 +100,7 @@ def test_mmotifs_max_matches_none(T): @pytest.mark.parametrize("T", test_data) -def test_mmotifs_more_motifs_when_cutoffs_is_set(T): +def test_mmotifs_more_motifs_when_cutoffs_3(T): motif_distances_ref = np.array([[0.0000000e00, 1.1151008e-07]]) motif_indices_ref = np.array([[2, 9]]) @@ -149,7 +149,7 @@ def test_mmotifs_more_motifs_cutoffs_is_list(T): @pytest.mark.parametrize("T", test_data) -def test_mmotifs_one_motif_pair_k_chosen(T): +def test_mmotifs_max_matches_2_k_1(T): motif_distances_ref = np.array([[0.0, 0.20948156]]) motif_indices_ref = np.array([[2, 9]]) @@ -173,7 +173,7 @@ def test_mmotifs_one_motif_pair_k_chosen(T): @pytest.mark.parametrize("T", test_data) -def test_mmotifs_exactly_two_motif_pairs(T): +def test_mmotifs_two_motif_pairs_max_motifs_2(T): motif_distances_ref = np.array( [[0.00000000e00, 1.11510080e-07], [1.68587394e-07, 2.58694429e-01]]