diff --git a/stumpy/aamp_mmotifs.py b/stumpy/aamp_mmotifs.py index b2cf34327..10b43435a 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)) @@ -159,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( @@ -169,6 +170,7 @@ def aamp_mmotifs( max_matches=max_matches, max_distance=max_distance, atol=atol, + query_idx=motif_idx, p=p, ) diff --git a/stumpy/aamp_motifs.py b/stumpy/aamp_motifs.py index 5f93fc5d2..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, ) @@ -295,6 +296,7 @@ def aamp_match( max_distance=None, max_matches=None, atol=1e-8, + query_idx=None, p=2.0, ): """ @@ -334,6 +336,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 +391,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]) diff --git a/stumpy/mmotifs.py b/stumpy/mmotifs.py index de47e9229..04460ae1c 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)) @@ -178,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( @@ -189,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 6ec6d189a..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: @@ -322,6 +323,7 @@ def match( max_distance=None, max_matches=None, atol=1e-8, + query_idx=None, normalize=True, p=2.0, ): @@ -365,6 +367,14 @@ 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 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. Otherwise, this function gets re-routed to its complementary non-normalized @@ -433,7 +443,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]) diff --git a/test.sh b/test.sh index 729f4fe8e..fc4d3b7c3 100755 --- a/test.sh +++ b/test.sh @@ -109,6 +109,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 $? @@ -132,6 +134,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 $? diff --git a/tests/test_aamp_mmotifs.py b/tests/test_aamp_mmotifs.py new file mode 100755 index 000000000..49100a836 --- /dev/null +++ b/tests/test_aamp_mmotifs.py @@ -0,0 +1,248 @@ +import numpy as np +import numpy.testing as npt +import naive +import pytest + +from stumpy.aamp_mmotifs import aamp_mmotifs +from stumpy import config + + +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], + [ + 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, + ], + ] + ) +] + + +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): + + 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) + ( + 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_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_max_matches_none(T): + + 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) + ( + 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_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_motifs_1_max_matches_2_k_1(T): + + 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])] + + m = 4 + 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, 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) + 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_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]]) + 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]), + ] + + m = 4 + 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=3, 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) + + +@pytest.mark.parametrize("T", test_data) +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]]) + motif_subspaces_ref = [np.array([3])] + motif_mdls_ref = [np.array([244.0, 260.67970001, 279.86313714, 281.35940001])] + + 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) + + +@pytest.mark.parametrize("T", test_data) +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]]) + 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]), + ] + + m = 4 + 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=np.inf, + max_matches=2, + max_motifs=2, + ) + + 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 new file mode 100755 index 000000000..75c8e19ce --- /dev/null +++ b/tests/test_mmotifs.py @@ -0,0 +1,203 @@ +import numpy as np +import numpy.testing as npt +import naive +import pytest + +from stumpy.mmotifs import mmotifs +from stumpy import config + + +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], + [ + 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, + ], + ] + ) +] + + +@pytest.mark.parametrize("T", test_data) +def test_mmotifs_with_default_parameters(T): + + 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) + ( + 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_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_mmotifs_max_matches_none(T): + + 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) + ( + 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_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_mmotifs_more_motifs_when_cutoffs_3(T): + + 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) + ( + 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_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_mmotifs_more_motifs_cutoffs_is_list(T): + + 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 + 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) + + +@pytest.mark.parametrize("T", test_data) +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]]) + motif_subspaces_ref = [np.array([1, 3])] + 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) + ( + 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_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_mmotifs_two_motif_pairs_max_motifs_2(T): + + motif_distances_ref = np.array( + [[0.00000000e00, 1.11510080e-07], [1.68587394e-07, 2.58694429e-01]] + ) + 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]), + ] + + m = 4 + 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=np.inf, max_motifs=2, max_distance=np.inf, max_matches=2 + ) + + 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_motifs.py b/tests/test_motifs.py index 49c8fe028..07dbf2c9b 100644 --- a/tests/test_motifs.py +++ b/tests/test_motifs.py @@ -235,62 +235,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) -"""