Example #1
0
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)
Example #2
0
def test_mstump_discords(T, m):
    excl_zone = int(np.ceil(m / 4))

    left_P, left_I = naive.mstump(T, m, excl_zone, discords=True)
    right_P, right_I = mstump(T, m, discords=True)

    npt.assert_almost_equal(left_P, right_P)
    npt.assert_almost_equal(left_I, right_I)
Example #3
0
def test_mstump(T, m):
    excl_zone = int(np.ceil(m / 4))

    ref_P, ref_I, _ = naive.mstump(T, m, excl_zone)
    comp_P, comp_I = mstump(T, m)

    npt.assert_almost_equal(ref_P, comp_P)
    npt.assert_almost_equal(ref_I, comp_I)
Example #4
0
def test_mstump_discords(T, m):
    excl_zone = int(np.ceil(m / 4))

    ref_P, ref_I = naive.mstump(T, m, excl_zone, discords=True)
    comp_P, comp_I = mstump(T, m, discords=True)

    npt.assert_almost_equal(ref_P, comp_P)
    npt.assert_almost_equal(ref_I, comp_I)
Example #5
0
def test_mstumped_discords(T, m, dask_cluster):
    with Client(dask_cluster) as dask_client:
        excl_zone = int(np.ceil(m / 4))

        ref_P, ref_I = naive.mstump(T, m, excl_zone, discords=True)
        comp_P, comp_I = mstumped(dask_client, T, m, discords=True)

        npt.assert_almost_equal(ref_P, comp_P)
        npt.assert_almost_equal(ref_I, comp_I)
Example #6
0
def test_mstumped_discords(T, m, dask_cluster):
    with Client(dask_cluster) as dask_client:
        excl_zone = int(np.ceil(m / 4))

        left_P, left_I = naive.mstump(T, m, excl_zone, discords=True)
        right_P, right_I = mstumped(dask_client, T, m, discords=True)

        npt.assert_almost_equal(left_P, right_P)
        npt.assert_almost_equal(left_I, right_I)
Example #7
0
def test_mstumped_df(T, m, dask_cluster):
    with Client(dask_cluster) as dask_client:
        excl_zone = int(np.ceil(m / 4))

        ref_P, ref_I, _ = naive.mstump(T, m, excl_zone)
        df = pd.DataFrame(T.T)
        comp_P, comp_I = mstumped(dask_client, df, m)

        npt.assert_almost_equal(ref_P, comp_P)
        npt.assert_almost_equal(ref_I, comp_I)
Example #8
0
def test_mstumped_df(T, m, dask_cluster):
    with Client(dask_cluster) as dask_client:
        excl_zone = int(np.ceil(m / 4))

        left_P, left_I = naive.mstump(T, m, excl_zone)
        df = pd.DataFrame(T.T)
        right_P, right_I = mstumped(dask_client, df, m)

        npt.assert_almost_equal(left_P, right_P)
        npt.assert_almost_equal(left_I, right_I)
Example #9
0
def test_mstump_include(T, m):
    for width in range(T.shape[0]):
        for i in range(T.shape[0] - width):
            include = np.asarray(range(i, i + width + 1))
            excl_zone = int(np.ceil(m / 4))

            left_P, left_I = naive.mstump(T, m, excl_zone, include)
            right_P, right_I = mstump(T, m, include)

            npt.assert_almost_equal(left_P, right_P)
            npt.assert_almost_equal(left_I, right_I)
Example #10
0
def test_constant_subsequence_self_join():
    T_A = np.concatenate((np.zeros(20, dtype=np.float64), np.ones(5, dtype=np.float64)))
    T = np.array([T_A, T_A, np.random.rand(T_A.shape[0])])
    m = 3

    excl_zone = int(np.ceil(m / 4))

    ref_P, ref_I, _ = naive.mstump(T, m, excl_zone)
    comp_P, comp_I = mstump(T, m)

    npt.assert_almost_equal(ref_P, comp_P)  # ignore indices
Example #11
0
def test_mstump_include_discords(T, m):
    for width in range(T.shape[0]):
        for i in range(T.shape[0] - width):
            include = np.asarray(range(i, i + width + 1))

            excl_zone = int(np.ceil(m / 4))

            ref_P, ref_I, _ = naive.mstump(T, m, excl_zone, include, discords=True)
            comp_P, comp_I = mstump(T, m, include, discords=True)

            npt.assert_almost_equal(ref_P, comp_P)
            npt.assert_almost_equal(ref_I, comp_I)
Example #12
0
def test_query_mstump_profile(T, m):
    excl_zone = int(np.ceil(m / 4))
    for query_idx in range(T.shape[0] - m + 1):
        ref_P, ref_I = naive.mstump(T, m, excl_zone)
        ref_P = ref_P[:, query_idx]
        ref_I = ref_I[:, query_idx]

        M_T, Σ_T = core.compute_mean_std(T, m)
        comp_P, comp_I = _query_mstump_profile(query_idx, T, T, m, excl_zone,
                                               M_T, Σ_T, M_T, Σ_T)

        npt.assert_almost_equal(ref_P, comp_P)
        npt.assert_equal(ref_I, comp_I)
Example #13
0
def test_mstumped_one_subsequence_nan_self_join_all_dimensions(
        T, m, substitution_location, dask_cluster):
    with Client(dask_cluster) as dask_client:
        excl_zone = int(np.ceil(m / 4))

        T_sub = T.copy()
        T_sub[:, substitution_location] = np.nan

        ref_P, ref_I, _ = naive.mstump(T_sub, m, excl_zone)
        comp_P, comp_I = mstumped(dask_client, T_sub, m)

        npt.assert_almost_equal(ref_P, comp_P)
        npt.assert_almost_equal(ref_I, comp_I)
def test_mstumped_one_subsequence_inf_self_join_all_dimensions(
        T, m, substitution_location, dask_cluster):
    with Client(dask_cluster) as dask_client:
        excl_zone = int(np.ceil(m / 4))

        T_sub = T.copy()
        T_sub[:, substitution_location] = np.inf

        left_P, left_I = naive.mstump(T_sub, m, excl_zone)
        right_P, right_I = mstumped(dask_client, T_sub, m)

        npt.assert_almost_equal(left_P, right_P)
        npt.assert_almost_equal(left_I, right_I)
Example #15
0
def test_constant_subsequence_self_join(dask_cluster):
    with Client(dask_cluster) as dask_client:
        T_A = np.concatenate(
            (np.zeros(20, dtype=np.float64), np.ones(5, dtype=np.float64)))
        T = np.array([T_A, T_A, np.random.rand(T_A.shape[0])])
        m = 3

        excl_zone = int(np.ceil(m / 4))

        left_P, left_I = naive.mstump(T, m, excl_zone)
        right_P, right_I = mstumped(dask_client, T, m)

        npt.assert_almost_equal(left_P, right_P)  # ignore indices
Example #16
0
def test_mstumped_include(T, m, dask_cluster):
    with Client(dask_cluster) as dask_client:
        for width in range(T.shape[0]):
            for i in range(T.shape[0] - width):
                include = np.asarray(range(i, i + width + 1))

                excl_zone = int(np.ceil(m / 4))

                left_P, left_I = naive.mstump(T, m, excl_zone, include)
                right_P, right_I = mstumped(dask_client, T, m, include)

                npt.assert_almost_equal(left_P, right_P)
                npt.assert_almost_equal(left_I, right_I)
Example #17
0
def test_naive_mstump():
    T = np.random.uniform(-1000, 1000, [1, 1000]).astype(np.float64)
    m = 20

    zone = int(np.ceil(m / 4))

    left = naive.stamp(T[0], m, exclusion_zone=zone)
    left_P = left[np.newaxis, :, 0].T
    left_I = left[np.newaxis, :, 1].T

    right_P, right_I = naive.mstump(T, m, zone)

    npt.assert_almost_equal(left_P, right_P)
    npt.assert_almost_equal(left_I, right_I)
Example #18
0
def test_get_first_mstump_profile(T, m):
    excl_zone = int(np.ceil(m / 4))
    start = 0

    ref_P, ref_I = naive.mstump(T, m, excl_zone)
    ref_P = ref_P[start, :]
    ref_I = ref_I[start, :]

    M_T, Σ_T = core.compute_mean_std(T, m)
    comp_P, comp_I = _get_first_mstump_profile(start, T, T, m, excl_zone, M_T,
                                               Σ_T, M_T, Σ_T)

    npt.assert_almost_equal(ref_P, comp_P)
    npt.assert_equal(ref_I, comp_I)
Example #19
0
def test_mstump_nan_self_join_all_dimensions(T, m, substitute, substitution_locations):
    excl_zone = int(np.ceil(m / 4))

    T_sub = T.copy()

    for substitution_location in substitution_locations:
        T_sub[:] = T[:]
        T_sub[:, substitution_location] = substitute

        ref_P, ref_I, _ = naive.mstump(T_sub, m, excl_zone)
        comp_P, comp_I = mstump(T_sub, m)

        npt.assert_almost_equal(ref_P, comp_P)
        npt.assert_almost_equal(ref_I, comp_I)
Example #20
0
def test_naive_mstump():
    T = np.random.uniform(-1000, 1000, [1, 1000]).astype(np.float64)
    m = 20

    zone = int(np.ceil(m / 4))

    ref_mp = naive.stamp(T[0], m, exclusion_zone=zone)
    ref_P = ref_mp[np.newaxis, :, 0].T
    ref_I = ref_mp[np.newaxis, :, 1].T

    comp_P, comp_I = naive.mstump(T, m, zone)

    npt.assert_almost_equal(ref_P, comp_P)
    npt.assert_almost_equal(ref_I, comp_I)
Example #21
0
def test_mstump_wrapper(T, m):
    excl_zone = int(np.ceil(m / 4))

    ref_P, ref_I = naive.mstump(T, m, excl_zone)
    comp_P, comp_I = mstump(T, m)

    npt.assert_almost_equal(ref_P, comp_P)
    npt.assert_almost_equal(ref_I, comp_I)

    df = pd.DataFrame(T.T)
    comp_P, comp_I = mstump(df, m)

    npt.assert_almost_equal(ref_P, comp_P)
    npt.assert_almost_equal(ref_I, comp_I)
Example #22
0
def test_get_first_mstump_profile(T, m):
    excl_zone = int(np.ceil(m / 4))
    start = 0

    left_P, left_I = naive.mstump(T, m, excl_zone)
    left_P = left_P[start, :]
    left_I = left_I[start, :]

    M_T, Σ_T = core.compute_mean_std(T, m)
    right_P, right_I = _get_first_mstump_profile(start, T, T, m, excl_zone,
                                                 M_T, Σ_T, M_T, Σ_T)

    npt.assert_almost_equal(left_P, right_P)
    npt.assert_equal(left_I, right_I)
Example #23
0
def test_mstump_wrapper(T, m):
    excl_zone = int(np.ceil(m / 4))

    left_P, left_I = naive.mstump(T, m, excl_zone)
    right_P, right_I = mstump(T, m)

    npt.assert_almost_equal(left_P, right_P)
    npt.assert_almost_equal(left_I, right_I)

    df = pd.DataFrame(T.T)
    right_P, right_I = mstump(df, m)

    npt.assert_almost_equal(left_P, right_P)
    npt.assert_almost_equal(left_I, right_I)
Example #24
0
def test_mstump_nan_inf_self_join_first_dimension(T, m, substitute,
                                                  substitution_locations):
    excl_zone = int(np.ceil(m / 4))

    T_sub = T.copy()

    for substitution_location in substitution_locations:
        T_sub[:] = T[:]
        T_sub[0, substitution_location] = substitute

        left_P, left_I = naive.mstump(T_sub, m, excl_zone)
        right_P, right_I = mstump(T_sub, m)

        npt.assert_almost_equal(left_P, right_P)
        npt.assert_almost_equal(left_I, right_I)
Example #25
0
def test_identical_subsequence_self_join():
    identical = np.random.rand(8)
    T_A = np.random.rand(20)
    T_A[1:1 + identical.shape[0]] = identical
    T_A[11:11 + identical.shape[0]] = identical
    T = np.array([T_A, T_A, np.random.rand(T_A.shape[0])])
    m = 3

    excl_zone = int(np.ceil(m / 4))

    left_P, left_I = naive.mstump(T, m, excl_zone)
    right_P, right_I = mstump(T, m)

    npt.assert_almost_equal(left_P, right_P,
                            decimal=naive.PRECISION)  # ignore indices
Example #26
0
def test_identical_subsequence_self_join():
    identical = np.random.rand(8)
    T_A = np.random.rand(20)
    T_A[1:1 + identical.shape[0]] = identical
    T_A[11:11 + identical.shape[0]] = identical
    T = np.array([T_A, T_A, np.random.rand(T_A.shape[0])])
    m = 3

    excl_zone = int(np.ceil(m / 4))

    ref_P, ref_I = naive.mstump(T, m, excl_zone)
    comp_P, comp_I = mstump(T, m)

    npt.assert_almost_equal(
        ref_P, comp_P, decimal=config.STUMPY_TEST_PRECISION)  # ignore indices
Example #27
0
def test_mstumped_identical_subsequence_self_join(dask_cluster):
    with Client(dask_cluster) as dask_client:
        identical = np.random.rand(8)
        T_A = np.random.rand(20)
        T_A[1:1 + identical.shape[0]] = identical
        T_A[11:11 + identical.shape[0]] = identical
        T = np.array([T_A, T_A, np.random.rand(T_A.shape[0])])
        m = 3

        excl_zone = int(np.ceil(m / 4))

        left_P, left_I = naive.mstump(T, m, excl_zone)
        right_P, right_I = mstumped(dask_client, T, m)

        npt.assert_almost_equal(
            left_P, right_P,
            decimal=config.STUMPY_TEST_PRECISION)  # ignore indices
Example #28
0
def test_mstump_wrapper_include(T, m):
    for width in range(T.shape[0]):
        for i in range(T.shape[0] - width):
            include = np.asarray(range(i, i + width + 1))

            excl_zone = int(np.ceil(m / 4))

            ref_P, ref_I = naive.mstump(T, m, excl_zone, include)
            comp_P, comp_I = mstump(T, m, include)

            npt.assert_almost_equal(ref_P, comp_P)
            npt.assert_almost_equal(ref_I, comp_I)

            df = pd.DataFrame(T.T)
            comp_P, comp_I = mstump(df, m, include)

            npt.assert_almost_equal(ref_P, comp_P)
            npt.assert_almost_equal(ref_I, comp_I)
Example #29
0
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)
Example #30
0
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)