Ejemplo n.º 1
0
def test_scrump_A_B_join_full(T_A, T_B):

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

    ref_mp = naive.stamp(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 = scrump(T_A, m, T_B, ignore_trivial=False, percentage=1.0, pre_scrump=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 = stump(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)
Ejemplo n.º 2
0
def test_scrump_self_join_full_larger_window(T_A, T_B, m):
    if len(T_B) > m:
        zone = int(np.ceil(m / 4))

        left = naive.stamp(T_B, m, exclusion_zone=zone)
        left_P = left[:, 0]
        left_I = left[:, 1]
        left_left_I = left[:, 2]
        left_right_I = left[:, 3]

        approx = scrump(T_B, m, ignore_trivial=True, percentage=1.0, pre_scrump=False)
        approx.update()
        right_P = approx.P_
        right_I = approx.I_
        right_left_I = approx.left_I_
        right_right_I = approx.right_I_

        naive.replace_inf(left_P)
        naive.replace_inf(right_P)

        npt.assert_almost_equal(left_P, right_P)
        npt.assert_almost_equal(left_I, right_I)
        npt.assert_almost_equal(left_left_I, right_left_I)
        npt.assert_almost_equal(left_right_I, right_right_I)
Ejemplo n.º 3
0
def test_scrump_plus_plus_A_B_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)
            left_P, left_I = naive_prescrump(T_A, m, T_B, s=s)
            left = naive_scrump(T_A, m, T_B, percentage, None, False, None)
            for i in range(left.shape[0]):
                if left_P[i] < left[i, 0]:
                    left[i, 0] = left_P[i]
                    left[i, 1] = left_I[i]
            left_P = left[:, 0]
            left_I = left[:, 1]

            approx = scrump(
                T_A,
                m,
                T_B,
                ignore_trivial=False,
                percentage=percentage,
                pre_scrump=True,
                s=s,
            )
            approx.update()
            right_P = approx.P_
            right_I = approx.I_

            naive.replace_inf(left_P)
            naive.replace_inf(right_P)

            npt.assert_almost_equal(left_P, right_P)
            npt.assert_almost_equal(left_I, right_I)
Ejemplo n.º 4
0
def test_scrump_A_B_join_swap(T_A, T_B, percentages):
    m = 3

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

        np.random.seed(seed)
        left = naive_scrump(T_B, m, T_A, percentage, None, False, None)
        left_P = left[:, 0]
        left_I = left[:, 1]

        np.random.seed(seed)
        approx = scrump(
            T_B, m, T_A, ignore_trivial=False, percentage=percentage, pre_scrump=False
        )
        approx.update()
        right_P = approx.P_
        right_I = approx.I_

        naive.replace_inf(left_P)
        naive.replace_inf(right_P)

        npt.assert_almost_equal(left_P, right_P)
        npt.assert_almost_equal(left_P, right_P)
Ejemplo n.º 5
0
def test_scrump_self_join_full_larger_window(T_A, T_B, m):
    if len(T_B) > m:
        zone = int(np.ceil(m / 4))

        ref_mp = naive.stamp(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 = scrump(T_B, m, ignore_trivial=True, percentage=1.0, pre_scrump=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)
Ejemplo n.º 6
0
def test_scrump_A_B_join_full(T_A, T_B):

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

    left = naive.stamp(T_A, m, T_B=T_B)
    left_P = left[:, 0]
    left_I = left[:, 1]
    left_left_I = left[:, 2]
    left_right_I = left[:, 3]

    approx = scrump(T_A, m, T_B, ignore_trivial=False, percentage=1.0, pre_scrump=False)
    approx.update()
    right_P = approx.P_
    right_I = approx.I_
    right_left_I = approx.left_I_
    right_right_I = approx.right_I_

    naive.replace_inf(left_P)
    naive.replace_inf(right_P)

    npt.assert_almost_equal(left_P, right_P)
    npt.assert_almost_equal(left_I, right_I)
    npt.assert_almost_equal(left_left_I, right_left_I)
    npt.assert_almost_equal(left_right_I, right_right_I)

    left = stump(T_A, m, T_B=T_B, ignore_trivial=False)
    left_P = left[:, 0]
    left_I = left[:, 1]
    left_left_I = left[:, 2]
    left_right_I = left[:, 3]

    npt.assert_almost_equal(left_P, right_P)
    npt.assert_almost_equal(left_I, right_I)
    npt.assert_almost_equal(left_left_I, right_left_I)
    npt.assert_almost_equal(left_right_I, right_right_I)
Ejemplo n.º 7
0
def test_scrump_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.scrump(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 = scrump(T,
                        m,
                        ignore_trivial=True,
                        percentage=percentage,
                        pre_scrump=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)
Ejemplo n.º 8
0
def test_aamp_self_join(T_A, T_B):
    m = 3
    left = naive.aamp(T_B, m)
    right = aamp(T_B, m)
    naive.replace_inf(left)
    naive.replace_inf(right)
    npt.assert_almost_equal(left, right)

    right = aamp(pd.Series(T_B), m)
    naive.replace_inf(right)
    npt.assert_almost_equal(left, right)
Ejemplo n.º 9
0
def test_aamp_self_join(T_A, T_B):
    m = 3
    ref_mp = naive.aamp(T_B, m)
    comp_mp = aamp(T_B, m)
    naive.replace_inf(ref_mp)
    naive.replace_inf(comp_mp)
    npt.assert_almost_equal(ref_mp, comp_mp)

    comp_mp = aamp(pd.Series(T_B), m)
    naive.replace_inf(comp_mp)
    npt.assert_almost_equal(ref_mp, comp_mp)
Ejemplo n.º 10
0
def test_stump_A_B_join(T_A, T_B):
    m = 3
    left = naive.stamp(T_A, m, T_B=T_B)
    right = stump(T_A, m, T_B, ignore_trivial=False)
    naive.replace_inf(left)
    naive.replace_inf(right)
    npt.assert_almost_equal(left, right)

    right = stump(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False)
    naive.replace_inf(right)
    npt.assert_almost_equal(left, right)
Ejemplo n.º 11
0
def test_aamp_A_B_join(T_A, T_B):
    m = 3
    ref_mp = naive.aamp(T_A, m, T_B=T_B)
    comp_mp = aamp(T_A, m, T_B, ignore_trivial=False)
    naive.replace_inf(ref_mp)
    naive.replace_inf(comp_mp)
    npt.assert_almost_equal(ref_mp, comp_mp)

    comp_mp = aamp(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False)
    naive.replace_inf(comp_mp)
    npt.assert_almost_equal(ref_mp, comp_mp)
Ejemplo n.º 12
0
def test_stump_self_join(T_A, T_B):
    m = 3
    zone = int(np.ceil(m / 4))
    left = naive.stamp(T_B, m, exclusion_zone=zone)
    right = stump(T_B, m, ignore_trivial=True)
    naive.replace_inf(left)
    naive.replace_inf(right)
    npt.assert_almost_equal(left, right)

    right = stump(pd.Series(T_B), m, ignore_trivial=True)
    naive.replace_inf(right)
    npt.assert_almost_equal(left, right)
Ejemplo n.º 13
0
def test_aampi_init_nan_inf_self_join(substitute, substitution_locations):
    m = 3
    zone = int(np.ceil(m / 4))

    seed = np.random.randint(100000)
    # seed = 58638

    for substitution_location in substitution_locations:
        np.random.seed(seed)
        n = 30
        T = np.random.rand(n)

        if substitution_location == -1:
            substitution_location = T.shape[0] - 1
        T[substitution_location] = substitute
        stream = aampi(T, m, egress=False)
        for i in range(34):
            t = np.random.rand()
            stream.update(t)

        right_P = stream.P_
        right_I = stream.I_

        stream.T_[substitution_location] = substitute
        left = naive.aamp(stream.T_, m)
        left_P = left[:, 0]
        left_I = left[:, 1]

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

        np.random.seed(seed)
        n = 30
        T = np.random.rand(n)

        if substitution_location == -1:
            substitution_location = T.shape[0] - 1
        T[substitution_location] = substitute
        T = pd.Series(T)
        stream = aampi(T, m, egress=False)
        for i in range(34):
            t = np.random.rand()
            stream.update(t)

        right_P = stream.P_
        right_I = stream.I_

        naive.replace_inf(right_P)

        npt.assert_almost_equal(left_P, right_P)
        npt.assert_almost_equal(left_I, right_I)
Ejemplo n.º 14
0
def test_aamp_constant_subsequence_self_join():
    T_A = np.concatenate((np.zeros(20, dtype=np.float64), np.ones(5, dtype=np.float64)))
    m = 3
    left = naive.aamp(T_A, m)
    right = aamp(T_A, m, ignore_trivial=True)
    naive.replace_inf(left)
    naive.replace_inf(right)
    npt.assert_almost_equal(left[:, 0], right[:, 0])  # ignore indices

    right = aamp(pd.Series(T_A), m, ignore_trivial=True)
    naive.replace_inf(right)
    npt.assert_almost_equal(left[:, 0], right[:, 0])  # ignore indices
Ejemplo n.º 15
0
def test_stimp_100_percent(T):
    threshold = 0.2
    percentage = 1.0
    min_m = 3
    n = T.shape[0] - min_m + 1

    pan = stimp(
        T,
        min_m=min_m,
        max_m=None,
        step=1,
        percentage=percentage,
        pre_scrump=True,
        # normalize=True,
    )

    for i in range(n):
        pan.update()

    ref_PAN = np.full((pan.M_.shape[0], T.shape[0]), fill_value=np.inf)

    for idx, m in enumerate(pan.M_[:n]):
        zone = int(np.ceil(m / 4))
        ref_mp = naive.stump(T, m, T_B=None, exclusion_zone=zone)
        ref_PAN[pan._bfs_indices[idx], :ref_mp.shape[0]] = ref_mp[:, 0]

    # Compare raw pan
    cmp_PAN = pan._PAN

    naive.replace_inf(ref_PAN)
    naive.replace_inf(cmp_PAN)

    npt.assert_almost_equal(ref_PAN, cmp_PAN)

    # Compare transformed pan
    cmp_pan = pan.PAN_
    ref_pan = naive.transform_pan(pan._PAN, pan._M, threshold,
                                  pan._bfs_indices, pan._n_processed)

    naive.replace_inf(ref_pan)
    naive.replace_inf(cmp_pan)

    npt.assert_almost_equal(ref_pan, cmp_pan)
Ejemplo n.º 16
0
def test_aamp_self_join(T_A, T_B):
    m = 3
    for p in [1.0, 2.0, 3.0]:
        ref_mp = naive.aamp(T_B, m, p=p)
        comp_mp = aamp(T_B, m, p=p)
        naive.replace_inf(ref_mp)
        naive.replace_inf(comp_mp)
        npt.assert_almost_equal(ref_mp, comp_mp)

        comp_mp = aamp(pd.Series(T_B), m, p=p)
        naive.replace_inf(comp_mp)
        npt.assert_almost_equal(ref_mp, comp_mp)
Ejemplo n.º 17
0
def test_gpu_aamp_self_join(T_A, T_B):
    m = 3
    zone = int(np.ceil(m / 4))
    ref_mp = naive.aamp(T_B, m, exclusion_zone=zone)
    comp_mp = gpu_aamp(T_B, m, ignore_trivial=True)
    naive.replace_inf(ref_mp)
    naive.replace_inf(comp_mp)
    npt.assert_almost_equal(ref_mp, comp_mp)

    comp_mp = gpu_aamp(pd.Series(T_B), m, ignore_trivial=True)
    naive.replace_inf(comp_mp)
    npt.assert_almost_equal(ref_mp, comp_mp)
Ejemplo n.º 18
0
def test_aampi_init_nan_inf_self_join(substitute, substitution_locations):
    m = 3

    seed = np.random.randint(100000)
    # seed = 58638

    for substitution_location in substitution_locations:
        np.random.seed(seed)
        n = 30
        T = np.random.rand(n)

        if substitution_location == -1:
            substitution_location = T.shape[0] - 1
        T[substitution_location] = substitute
        stream = aampi(T, m, egress=False)
        for i in range(34):
            t = np.random.rand()
            stream.update(t)

        comp_P = stream.P_
        comp_I = stream.I_

        stream.T_[substitution_location] = substitute
        ref_mp = naive.aamp(stream.T_, m)
        ref_P = ref_mp[:, 0]
        ref_I = ref_mp[:, 1]

        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)

        np.random.seed(seed)
        n = 30
        T = np.random.rand(n)

        if substitution_location == -1:
            substitution_location = T.shape[0] - 1
        T[substitution_location] = substitute
        T = pd.Series(T)
        stream = aampi(T, m, egress=False)
        for i in range(34):
            t = np.random.rand()
            stream.update(t)

        comp_P = stream.P_
        comp_I = stream.I_

        naive.replace_inf(comp_P)

        npt.assert_almost_equal(ref_P, comp_P)
        npt.assert_almost_equal(ref_I, comp_I)
Ejemplo n.º 19
0
def test_gpu_aamp_two_constant_subsequences_A_B_join():
    T_A = np.array([0, 0, 0, 0, 0, 1], dtype=np.float64)
    T_B = np.concatenate((np.zeros(20, dtype=np.float64), np.ones(5, dtype=np.float64)))
    m = 3
    ref_mp = naive.aamp(T_B, m, T_B=T_A)
    comp_mp = gpu_aamp(T_B, m, T_A, ignore_trivial=False)
    naive.replace_inf(ref_mp)
    naive.replace_inf(comp_mp)
    npt.assert_almost_equal(ref_mp[:, 0], comp_mp[:, 0])  # ignore indices

    # comp_mp = gpu_aamp(pd.Series(T_B), m, pd.Series(T_A), ignore_trivial=False)
    # naive.replace_inf(comp_mp)
    # npt.assert_almost_equal(ref_mp[:, 0], comp_mp[:, 0])  # ignore indices

    # Swap inputs
    ref_mp = naive.aamp(T_A, m, T_B=T_B)
    comp_mp = gpu_aamp(T_A, m, T_B, ignore_trivial=False)
    naive.replace_inf(ref_mp)
    naive.replace_inf(comp_mp)
    npt.assert_almost_equal(ref_mp[:, 0], comp_mp[:, 0])  # ignore indices
Ejemplo n.º 20
0
def test_aamp_constant_subsequence_self_join():
    T_A = np.concatenate(
        (np.zeros(20, dtype=np.float64), np.ones(5, dtype=np.float64)))
    m = 3
    ref_mp = naive.aamp(T_A, m)
    comp_mp = aamp(T_A, m, ignore_trivial=True)
    naive.replace_inf(ref_mp)
    naive.replace_inf(comp_mp)
    npt.assert_almost_equal(ref_mp[:, 0], comp_mp[:, 0])  # ignore indices

    comp_mp = aamp(pd.Series(T_A), m, ignore_trivial=True)
    naive.replace_inf(comp_mp)
    npt.assert_almost_equal(ref_mp[:, 0], comp_mp[:, 0])  # ignore indices
Ejemplo n.º 21
0
def test_gpu_stump_constant_subsequence_self_join():
    T_A = np.concatenate((np.zeros(20, dtype=np.float64), np.ones(5, dtype=np.float64)))
    m = 3
    zone = int(np.ceil(m / 4))
    left = naive.stamp(T_A, m, exclusion_zone=zone)
    right = gpu_stump(T_A, m, ignore_trivial=True)
    naive.replace_inf(left)
    naive.replace_inf(right)
    npt.assert_almost_equal(left[:, 0], right[:, 0])  # ignore indices

    right = gpu_stump(pd.Series(T_A), m, ignore_trivial=True)
    naive.replace_inf(right)
    npt.assert_almost_equal(left[:, 0], right[:, 0])  # ignore indices
Ejemplo n.º 22
0
def test_stumpi_init_nan_inf_self_join(substitute, substitution_locations):
    m = 3
    zone = int(np.ceil(m / 4))

    seed = np.random.randint(100000)
    # seed = 58638

    for substitution_location in substitution_locations:
        np.random.seed(seed)
        T = np.random.rand(30)

        if substitution_location == -1:
            substitution_location = T.shape[0] - 1
        T[substitution_location] = substitute
        stream = stumpi(T, m, egress=False)
        for i in range(34):
            t = np.random.rand()
            stream.update(t)

        comp_P = stream.P_
        comp_I = stream.I_

        stream.T_[substitution_location] = substitute
        ref_mp = naive.stamp(stream.T_, m, exclusion_zone=zone)
        ref_P = ref_mp[:, 0]
        ref_I = ref_mp[:, 1]

        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)

        np.random.seed(seed)
        T = np.random.rand(30)

        if substitution_location == -1:  # pragma: no cover
            substitution_location = T.shape[0] - 1
        T[substitution_location] = substitute
        T = pd.Series(T)
        stream = stumpi(T, m, egress=False)
        for i in range(34):
            t = np.random.rand()
            stream.update(t)

        comp_P = stream.P_
        comp_I = stream.I_

        naive.replace_inf(comp_P)

        npt.assert_almost_equal(ref_P, comp_P)
        npt.assert_almost_equal(ref_I, comp_I)
Ejemplo n.º 23
0
def test_stimp_100_percent(T):
    percentage = 1.0
    min_m = 3
    n = T.shape[0] - min_m + 1

    seed = np.random.randint(100000)

    np.random.seed(seed)
    pmp = stimp(
        T,
        min_m=min_m,
        max_m=None,
        step=1,
        percentage=percentage,
        pre_scrump=True,
        normalize=True,
    )

    for i in range(n):
        pmp.update()

    ref_P = np.full((pmp.M_.shape[0], T.shape[0]), fill_value=np.inf)
    ref_I = np.ones((pmp.M_.shape[0], T.shape[0]), dtype=np.int64) * -1

    np.random.seed(seed)
    for idx, m in enumerate(pmp.M_[:n]):
        zone = int(np.ceil(m / 4))
        ref_mp = naive.stump(T, m, T_B=None, exclusion_zone=zone)
        ref_P[pmp.bfs_indices_[idx], :ref_mp.shape[0]] = ref_mp[:, 0]
        ref_I[pmp.bfs_indices_[idx], :ref_mp.shape[0]] = ref_mp[:, 1]

    comp_P = pmp.P_
    comp_I = pmp.I_

    naive.replace_inf(ref_P)
    naive.replace_inf(ref_I)
    naive.replace_inf(comp_P)
    naive.replace_inf(comp_I)

    npt.assert_almost_equal(ref_P, comp_P)
    npt.assert_almost_equal(ref_I, comp_I)
Ejemplo n.º 24
0
def test_gpu_stump_two_constant_subsequences_A_B_join():
    T_A = np.array([0, 0, 0, 0, 0, 1], dtype=np.float64)
    T_B = np.concatenate(
        (np.zeros(20, dtype=np.float64), np.ones(5, dtype=np.float64)))
    m = 3
    left = naive.stamp(T_A, m, T_B=T_B)
    right = gpu_stump(T_A, m, T_B, ignore_trivial=False)
    naive.replace_inf(left)
    naive.replace_inf(right)
    npt.assert_almost_equal(left[:, 0], right[:, 0])  # ignore indices

    # right = gpu_stump(pd.Series(T_A), m, pd.Series(T_B), ignore_trivial=False)
    # naive.replace_inf(right)
    # npt.assert_almost_equal(left[:, 0], right[:, 0])  # ignore indices

    # Swap inputs
    left = naive.stamp(T_B, m, T_B=T_A)
    right = gpu_stump(T_B, m, T_A, ignore_trivial=False)
    naive.replace_inf(left)
    naive.replace_inf(right)
    npt.assert_almost_equal(left[:, 0], right[:, 0])  # ignore indices
Ejemplo n.º 25
0
def test_aampi_identical_subsequence_self_join():
    m = 3
    zone = int(np.ceil(m / 4))

    seed = np.random.randint(100000)
    np.random.seed(seed)

    identical = np.random.rand(8)
    T = np.random.rand(20)
    T[1:1 + identical.shape[0]] = identical
    T[11:11 + identical.shape[0]] = identical
    stream = aampi(T, m, egress=False)
    for i in range(34):
        t = np.random.rand()
        stream.update(t)

    right_P = stream.P_
    right_I = stream.I_

    left = naive.aamp(stream.T_, m)
    left_P = left[:, 0]
    left_I = left[:, 1]

    naive.replace_inf(left_P)
    naive.replace_inf(right_P)

    npt.assert_almost_equal(left_P,
                            right_P,
                            decimal=config.STUMPY_TEST_PRECISION)
    # npt.assert_almost_equal(left_I, right_I)

    np.random.seed(seed)
    identical = np.random.rand(8)
    T = np.random.rand(20)
    T[1:1 + identical.shape[0]] = identical
    T[11:11 + identical.shape[0]] = identical
    T = pd.Series(T)
    stream = aampi(T, m, egress=False)
    for i in range(34):
        t = np.random.rand()
        stream.update(t)

    right_P = stream.P_
    right_I = stream.I_

    naive.replace_inf(right_P)

    npt.assert_almost_equal(left_P,
                            right_P,
                            decimal=config.STUMPY_TEST_PRECISION)
Ejemplo n.º 26
0
def test_gpu_stump_self_join_larger_window(T_A, T_B):
    for m in [8, 16, 32]:
        if len(T_B) > m:
            zone = int(np.ceil(m / 4))
            left = naive.stamp(T_B, m, exclusion_zone=zone)
            right = gpu_stump(T_B, m, ignore_trivial=True)
            naive.replace_inf(left)
            naive.replace_inf(right)

            npt.assert_almost_equal(left, right)

            right = gpu_stump(pd.Series(T_B), m, ignore_trivial=True,)
            naive.replace_inf(right)
            npt.assert_almost_equal(left, right)
Ejemplo n.º 27
0
def test_parallel_gpu_stump_self_join(T_A, T_B):
    device_ids = [device.id for device in cuda.list_devices()]
    if len(T_B) > 10:
        m = 3
        zone = int(np.ceil(m / 4))
        left = naive.stamp(T_B, m, exclusion_zone=zone)
        right = gpu_stump(T_B, m, ignore_trivial=True, device_id=device_ids,)
        naive.replace_inf(left)
        naive.replace_inf(right)
        npt.assert_almost_equal(left, right)

        right = gpu_stump(pd.Series(T_B), m, ignore_trivial=True, device_id=device_ids,)
        naive.replace_inf(right)
        npt.assert_almost_equal(left, right)
Ejemplo n.º 28
0
def test_stumpi_identical_subsequence_self_join():
    m = 3
    zone = int(np.ceil(m / 4))

    seed = np.random.randint(100000)
    np.random.seed(seed)

    identical = np.random.rand(8)
    T = np.random.rand(20)
    T[1:1 + identical.shape[0]] = identical
    T[11:11 + identical.shape[0]] = identical
    stream = stumpi(T, m, egress=False)
    for i in range(34):
        t = np.random.rand()
        stream.update(t)

    comp_P = stream.P_
    # comp_I = stream.I_

    ref_mp = naive.stamp(stream.T_, m, exclusion_zone=zone)
    ref_P = ref_mp[:, 0]
    # ref_I = ref_mp[:, 1]

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

    npt.assert_almost_equal(ref_P,
                            comp_P,
                            decimal=config.STUMPY_TEST_PRECISION)
    # npt.assert_almost_equal(ref_I, comp_I)

    np.random.seed(seed)
    identical = np.random.rand(8)
    T = np.random.rand(20)
    T[1:1 + identical.shape[0]] = identical
    T[11:11 + identical.shape[0]] = identical
    T = pd.Series(T)
    stream = stumpi(T, m, egress=False)
    for i in range(34):
        t = np.random.rand()
        stream.update(t)

    comp_P = stream.P_
    # comp_I = stream.I_

    naive.replace_inf(comp_P)

    npt.assert_almost_equal(ref_P,
                            comp_P,
                            decimal=config.STUMPY_TEST_PRECISION)
Ejemplo n.º 29
0
def test_aampi_stream_nan_inf_self_join(substitute, substitution_locations):
    m = 3
    zone = int(np.ceil(m / 4))

    seed = np.random.randint(100000)

    for substitution_location in substitution_locations:
        np.random.seed(seed)
        n = 30
        T = np.random.rand(64)

        stream = aampi(T[:n], m, egress=False)
        if substitution_location == -1:
            substitution_location = T[n:].shape[0] - 1
        T[n:][substitution_location] = substitute
        for t in T[n:]:
            stream.update(t)

        right_P = stream.P_
        right_I = stream.I_

        stream.T_[n:][substitution_location] = substitute
        left = naive.aamp(stream.T_, m)
        left_P = left[:, 0]
        left_I = left[:, 1]

        naive.replace_inf(left_P)
        naive.replace_inf(right_P)

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

        np.random.seed(seed)
        T = np.random.rand(64)

        stream = aampi(pd.Series(T[:n]), m, egress=False)
        if substitution_location == -1:
            substitution_location = T[n:].shape[0] - 1
        T[n:][substitution_location] = substitute
        for t in T[n:]:
            stream.update(t)

        right_P = stream.P_
        right_I = stream.I_

        naive.replace_inf(right_P)

        npt.assert_almost_equal(left_P, right_P)
        npt.assert_almost_equal(left_I, right_I)
Ejemplo n.º 30
0
def test_stumpi_stream_nan_inf_self_join(substitute, substitution_locations):
    m = 3
    zone = int(np.ceil(m / 4))

    seed = np.random.randint(100000)

    for substitution_location in substitution_locations:
        np.random.seed(seed)
        T = np.random.rand(64)

        stream = stumpi(T[:30], m, egress=False)
        if substitution_location == -1:
            substitution_location = T[30:].shape[0] - 1
        T[30:][substitution_location] = substitute
        for t in T[30:]:
            stream.update(t)

        comp_P = stream.P_
        comp_I = stream.I_

        stream.T_[30:][substitution_location] = substitute
        ref_mp = naive.stamp(stream.T_, m, exclusion_zone=zone)
        ref_P = ref_mp[:, 0]
        ref_I = ref_mp[:, 1]

        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)

        np.random.seed(seed)
        T = np.random.rand(64)

        stream = stumpi(pd.Series(T[:30]), m, egress=False)
        if substitution_location == -1:  # pragma: no cover
            substitution_location = T[30:].shape[0] - 1
        T[30:][substitution_location] = substitute
        for t in T[30:]:
            stream.update(t)

        comp_P = stream.P_
        comp_I = stream.I_

        naive.replace_inf(comp_P)

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