Exemple #1
0
def test_scraamp_int_input():
    with pytest.raises(TypeError):
        scraamp(np.arange(10),
                5,
                ignore_trivial=True,
                percentage=1.0,
                pre_scraamp=False)
Exemple #2
0
def test_scraamp_nan_zero_mean_self_join(percentages):
    T = np.array([-1, 0, 1, np.inf, 1, 0, -1])

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

    for percentage in percentages:
        seed = np.random.randint(100000)

        np.random.seed(seed)
        ref_mp = naive.scraamp(T, m, T, percentage, zone, False, None)
        ref_P = ref_mp[:, 0]
        ref_I = ref_mp[:, 1]
        ref_left_I = ref_mp[:, 2]
        ref_right_I = ref_mp[:, 3]

        np.random.seed(seed)
        approx = scraamp(T, m, percentage=percentage, pre_scraamp=False)
        approx.update()
        comp_P = approx.P_
        comp_I = approx.I_
        comp_left_I = approx.left_I_
        comp_right_I = approx.right_I_

        naive.replace_inf(ref_P)
        naive.replace_inf(comp_P)

        npt.assert_almost_equal(ref_P, comp_P)
        npt.assert_almost_equal(ref_I, comp_I)
        npt.assert_almost_equal(ref_left_I, comp_left_I)
        npt.assert_almost_equal(ref_right_I, comp_right_I)
Exemple #3
0
def test_scraamp_identical_subsequence_self_join(percentages):
    identical = np.random.rand(8)
    T = np.random.rand(20)
    T[1 : 1 + identical.shape[0]] = identical
    T[11 : 11 + identical.shape[0]] = identical
    m = 3
    zone = int(np.ceil(m / 4))

    for percentage in percentages:
        seed = np.random.randint(100000)

        np.random.seed(seed)
        ref_mp = naive.scraamp(T, m, T, percentage, zone, False, None)
        ref_P = ref_mp[:, 0]
        # ref_I = ref_mp[:, 1]
        # ref_left_I = ref_mp[:, 2]
        # ref_right_I = ref_mp[:, 3]

        np.random.seed(seed)
        approx = scraamp(
            T, m, ignore_trivial=True, percentage=percentage, pre_scraamp=False
        )
        approx.update()
        comp_P = approx.P_
        # comp_I = approx.I_
        # comp_left_I = approx.left_I_
        # comp_right_I = approx.right_I_

        naive.replace_inf(ref_P)
        naive.replace_inf(comp_P)

        npt.assert_almost_equal(ref_P, comp_P, decimal=config.STUMPY_TEST_PRECISION)
Exemple #4
0
def test_scraamp_constant_subsequence_self_join(percentages):
    T = np.concatenate((np.zeros(20, dtype=np.float64), np.ones(5, dtype=np.float64)))

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

    for percentage in percentages:
        seed = np.random.randint(100000)

        np.random.seed(seed)
        ref_mp = naive.scraamp(T, m, T, percentage, zone, False, None)
        ref_P = ref_mp[:, 0]
        # ref_I = ref_mp[:, 1]
        # ref_left_I = ref_mp[:, 2]
        # ref_right_I = ref_mp[:, 3]

        np.random.seed(seed)
        approx = scraamp(
            T, m, ignore_trivial=True, percentage=percentage, pre_scraamp=False
        )
        approx.update()
        comp_P = approx.P_
        # comp_I = approx.I_
        # comp_left_I = approx.left_I_
        # comp_right_I = approx.right_I_

        naive.replace_inf(ref_P)
        naive.replace_inf(comp_P)

        npt.assert_almost_equal(ref_P, comp_P)
Exemple #5
0
def test_scraamp_plus_plus_A_B_join_full_swap(T_A, T_B):
    m = 3
    zone = int(np.ceil(m / 4))

    ref_mp = naive.aamp(T_B, m, T_B=T_A)
    ref_P = ref_mp[:, 0]
    ref_I = ref_mp[:, 1]
    ref_left_I = ref_mp[:, 2]
    ref_right_I = ref_mp[:, 3]

    approx = scraamp(
        T_B, m, T_B=T_A, ignore_trivial=False, percentage=1.0, pre_scraamp=True, s=zone
    )
    approx.update()
    comp_P = approx.P_
    comp_I = approx.I_
    comp_left_I = approx.left_I_
    comp_right_I = approx.right_I_

    naive.replace_inf(ref_P)
    naive.replace_inf(comp_P)

    npt.assert_almost_equal(ref_P, comp_P)
    npt.assert_almost_equal(ref_I, comp_I)
    npt.assert_almost_equal(ref_left_I, comp_left_I)
    npt.assert_almost_equal(ref_right_I, comp_right_I)
Exemple #6
0
def test_scraamp_self_join_larger_window(T_A, T_B, m, percentages):
    if len(T_B) > m:
        zone = int(np.ceil(m / 4))

        for percentage in percentages:
            seed = np.random.randint(100000)

            np.random.seed(seed)
            ref_mp = naive.scraamp(T_B, m, T_B, percentage, zone, False, None)
            ref_P = ref_mp[:, 0]
            ref_I = ref_mp[:, 1]
            ref_left_I = ref_mp[:, 2]
            ref_right_I = ref_mp[:, 3]

            np.random.seed(seed)
            approx = scraamp(
                T_B, m, ignore_trivial=True, percentage=percentage, pre_scraamp=False
            )
            approx.update()
            comp_P = approx.P_
            comp_I = approx.I_
            comp_left_I = approx.left_I_
            comp_right_I = approx.right_I_

            naive.replace_inf(ref_P)
            naive.replace_inf(comp_P)

            npt.assert_almost_equal(ref_P, comp_P)
            npt.assert_almost_equal(ref_I, comp_I)
            npt.assert_almost_equal(ref_left_I, comp_left_I)
            npt.assert_almost_equal(ref_right_I, comp_right_I)
Exemple #7
0
def test_scraamp_A_B_join_swap(T_A, T_B, percentages):
    m = 3

    for percentage in percentages:
        seed = np.random.randint(100000)

        np.random.seed(seed)
        ref_mp = naive.scraamp(T_B, m, T_A, percentage, None, False, None)
        ref_P = ref_mp[:, 0]
        # ref_I = ref_mp[:, 1]
        ref_left_I = ref_mp[:, 2]
        ref_right_I = ref_mp[:, 3]

        np.random.seed(seed)
        approx = scraamp(
            T_B, m, T_A, ignore_trivial=False, percentage=percentage, pre_scraamp=False
        )
        approx.update()
        comp_P = approx.P_
        # comp_I = approx.I_
        comp_left_I = approx.left_I_
        comp_right_I = approx.right_I_

        naive.replace_inf(ref_P)
        naive.replace_inf(comp_P)

        npt.assert_almost_equal(ref_P, comp_P)
        npt.assert_almost_equal(ref_P, comp_P)
        npt.assert_almost_equal(ref_left_I, comp_left_I)
        npt.assert_almost_equal(ref_right_I, comp_right_I)
Exemple #8
0
def test_scraamp_self_join_full_larger_window(T_A, T_B, m):
    if len(T_B) > m:
        zone = int(np.ceil(m / 4))

        ref_mp = naive.aamp(T_B, m, exclusion_zone=zone)
        ref_P = ref_mp[:, 0]
        ref_I = ref_mp[:, 1]
        ref_left_I = ref_mp[:, 2]
        ref_right_I = ref_mp[:, 3]

        approx = scraamp(T_B,
                         m,
                         ignore_trivial=True,
                         percentage=1.0,
                         pre_scraamp=False)
        approx.update()
        comp_P = approx.P_
        comp_I = approx.I_
        comp_left_I = approx.left_I_
        comp_right_I = approx.right_I_

        naive.replace_inf(ref_P)
        naive.replace_inf(comp_P)

        npt.assert_almost_equal(ref_P, comp_P)
        npt.assert_almost_equal(ref_I, comp_I)
        npt.assert_almost_equal(ref_left_I, comp_left_I)
        npt.assert_almost_equal(ref_right_I, comp_right_I)
def test_scrump_plus_plus(T, m):
    if T.ndim > 1:
        T = T.copy()
        T = T[0]
    seed = np.random.randint(100000)

    np.random.seed(seed)
    ref = stumpy.scraamp(T, m, pre_scraamp=True)
    np.random.seed(seed)
    comp = stumpy.scrump(T, m, pre_scrump=True, normalize=False)
    npt.assert_almost_equal(ref.P_, comp.P_)

    for i in range(10):
        ref.update()
        comp.update()
        npt.assert_almost_equal(ref.P_, comp.P_)
Exemple #10
0
def test_scraamp_plus_plus_A_B_join(T_A, T_B, percentages):
    m = 3
    zone = int(np.ceil(m / 4))

    for p in [1.0, 2.0, 3.0]:
        for s in range(1, zone + 1):
            for percentage in percentages:
                seed = np.random.randint(100000)

                np.random.seed(seed)
                ref_P, ref_I = naive.prescraamp(T_A, m, T_B, s=s, p=p)
                ref_mp = naive.scraamp(T_A, m, T_B, percentage, None, False, None, p=p)
                for i in range(ref_mp.shape[0]):
                    if ref_P[i] < ref_mp[i, 0]:
                        ref_mp[i, 0] = ref_P[i]
                        ref_mp[i, 1] = ref_I[i]
                ref_P = ref_mp[:, 0]
                ref_I = ref_mp[:, 1]
                ref_left_I = ref_mp[:, 2]
                ref_right_I = ref_mp[:, 3]

                approx = scraamp(
                    T_A,
                    m,
                    T_B,
                    ignore_trivial=False,
                    percentage=percentage,
                    pre_scraamp=True,
                    s=s,
                    p=p,
                )
                approx.update()
                comp_P = approx.P_
                comp_I = approx.I_
                comp_left_I = approx.left_I_
                comp_right_I = approx.right_I_

                naive.replace_inf(ref_P)
                naive.replace_inf(comp_P)

                npt.assert_almost_equal(ref_P, comp_P)
                npt.assert_almost_equal(ref_I, comp_I)
                npt.assert_almost_equal(ref_left_I, comp_left_I)
                npt.assert_almost_equal(ref_right_I, comp_right_I)
Exemple #11
0
def test_scraamp_plus_plus_self_join(T_A, T_B, percentages):
    m = 3
    zone = int(np.ceil(m / 4))

    for s in range(1, zone + 1):
        for percentage in percentages:
            seed = np.random.randint(100000)

            np.random.seed(seed)
            ref_P, ref_I = naive_prescraamp(T_B,
                                            m,
                                            T_B,
                                            s=s,
                                            exclusion_zone=zone)
            ref_mp = naive_scraamp(T_B, m, T_B, percentage, zone, True, s)
            for i in range(ref_mp.shape[0]):
                if ref_P[i] < ref_mp[i, 0]:
                    ref_mp[i, 0] = ref_P[i]
                    ref_mp[i, 1] = ref_I[i]
            ref_P = ref_mp[:, 0]
            ref_I = ref_mp[:, 1]
            # ref_left_I = ref_mp[:, 2]
            # ref_right_I = ref_mp[:, 3]

            np.random.seed(seed)
            approx = scraamp(
                T_B,
                m,
                ignore_trivial=True,
                percentage=percentage,
                pre_scraamp=True,
                s=s,
            )
            approx.update()
            comp_P = approx.P_
            comp_I = approx.I_
            # comp_left_I = approx.left_I_
            # comp_right_I = approx.right_I_

            naive.replace_inf(ref_P)
            naive.replace_inf(comp_I)

            npt.assert_almost_equal(ref_P, comp_P)
            npt.assert_almost_equal(ref_I, comp_I)
Exemple #12
0
def test_scraamp_nan_inf_self_join(T_A, T_B, substitute,
                                   substitution_locations, percentages):
    m = 3

    T_B_sub = T_B.copy()

    for substitution_location in substitution_locations:
        T_B_sub[:] = T_B[:]
        T_B_sub[substitution_location] = substitute

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

        for percentage in percentages:
            seed = np.random.randint(100000)

            np.random.seed(seed)
            ref_mp = naive_scraamp(T_B_sub, m, T_B_sub, percentage, zone,
                                   False, None)
            ref_P = ref_mp[:, 0]
            ref_I = ref_mp[:, 1]
            ref_left_I = ref_mp[:, 2]
            ref_right_I = ref_mp[:, 3]

            np.random.seed(seed)
            approx = scraamp(T_B_sub,
                             m,
                             percentage=percentage,
                             pre_scraamp=False)
            approx.update()
            comp_P = approx.P_
            comp_I = approx.I_
            comp_left_I = approx.left_I_
            comp_right_I = approx.right_I_

            naive.replace_inf(ref_P)
            naive.replace_inf(comp_P)

            npt.assert_almost_equal(ref_P, comp_P)
            npt.assert_almost_equal(ref_I, comp_I)
            npt.assert_almost_equal(ref_left_I, comp_left_I)
            npt.assert_almost_equal(ref_right_I, comp_right_I)
Exemple #13
0
def test_scraamp_A_B_join_full(T_A, T_B):

    m = 3

    ref_mp = naive.aamp(T_A, m, T_B=T_B)
    ref_P = ref_mp[:, 0]
    ref_I = ref_mp[:, 1]
    ref_left_I = ref_mp[:, 2]
    ref_right_I = ref_mp[:, 3]

    approx = scraamp(T_A,
                     m,
                     T_B,
                     ignore_trivial=False,
                     percentage=1.0,
                     pre_scraamp=False)
    approx.update()
    comp_P = approx.P_
    comp_I = approx.I_
    comp_left_I = approx.left_I_
    comp_right_I = approx.right_I_

    naive.replace_inf(ref_P)
    naive.replace_inf(comp_P)

    npt.assert_almost_equal(ref_P, comp_P)
    npt.assert_almost_equal(ref_I, comp_I)
    npt.assert_almost_equal(ref_left_I, comp_left_I)
    npt.assert_almost_equal(ref_right_I, comp_right_I)

    ref_mp = aamp(T_A, m, T_B=T_B, ignore_trivial=False)
    ref_P = ref_mp[:, 0]
    ref_I = ref_mp[:, 1]
    ref_left_I = ref_mp[:, 2]
    ref_right_I = ref_mp[:, 3]

    npt.assert_almost_equal(ref_P, comp_P)
    npt.assert_almost_equal(ref_I, comp_I)
    npt.assert_almost_equal(ref_left_I, comp_left_I)
    npt.assert_almost_equal(ref_right_I, comp_right_I)