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

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

    left = utils.naive_stamp(T_A, m, T_B=T_B)

    right_gen = scrump(T_A,
                       m,
                       T_B,
                       ignore_trivial=False,
                       percentage=1.0,
                       pre_scrump=False)
    right = next(right_gen)

    utils.replace_inf(left)
    utils.replace_inf(right)

    npt.assert_almost_equal(left[:, :2], right)
Exemplo n.º 2
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)
            ref_P, ref_I = naive_prescrump(T_A, m, T_B, s=s)
            ref_mp = naive_scrump(T_A, m, T_B, percentage, None, False, None)
            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 = scrump(
                T_A,
                m,
                T_B,
                ignore_trivial=False,
                percentage=percentage,
                pre_scrump=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_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)
Exemplo 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]
            left_left_I = left[:, 2]
            left_right_I = left[:, 3]

            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_
            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)
Exemplo n.º 4
0
def do_mp(model, colnames, arr_baseline, arr_highlight):

    # init some counters
    n_charts, n_dims, n_bad_data, fit_success, fit_default, fit_fail = init_counters(colnames)

    # dict to collect results into
    results = {}

    arr = np.concatenate((arr_baseline, arr_highlight))
    n_highlight = arr_highlight.shape[0]

    # loop over each col and build mp model
    for colname, n in zip(colnames, range(arr_baseline.shape[1])):

        chart = colname.split('|')[0]
        dimension = colname.split('|')[1]
        m = 30

        if model == 'mp':
            mp = stumpy.stump(arr[:, n], m)[:, 0]
        elif model == 'mp_approx':
            approx = stumpy.scrump(arr[:, n], m, percentage=0.01, pre_scrump=True)
            for _ in range(20):
                approx.update()
            mp = approx.P_
        else:
            raise ValueError(f"... unknown model '{model}'")

        fit_success += 1
        mp_highlight = mp[-n_highlight:]
        mp_thold = np.percentile(mp, 90)

        score = np.mean(np.where(mp_highlight >= mp_thold, 1, 0))
        if chart in results:
            results[chart].append({dimension: {'score': score}})
        else:
            results[chart] = [{dimension: {'score': score}}]

    # log some summary stats
    log.info(summary_info(n_charts, n_dims, n_bad_data, fit_success, fit_fail, fit_default))

    return results
Exemplo n.º 5
0
def test_scrump_plus_plus_A_B_join_full_swap(T_A, T_B):
    m = 3
    zone = int(np.ceil(m / 4))

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

    approx = scrump(
        T_B, m, T_B=T_A, ignore_trivial=False, percentage=1.0, pre_scrump=True, s=zone
    )
    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)
Exemplo 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)
Exemplo n.º 7
0
def test_scrump_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)
            left = naive_scrump(T_B_sub, m, T_B_sub, percentage, zone, False,
                                None)
            left_P = left[:, 0]
            left_I = left[:, 1]
            left_left_I = left[:, 2]
            left_right_I = left[:, 3]

            np.random.seed(seed)
            approx = scrump(T_B_sub,
                            m,
                            percentage=percentage,
                            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)
Exemplo n.º 8
0
def test_scrump_self_join(T_A, T_B, percentages):
    m = 3
    zone = int(np.ceil(m / 4))

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

        np.random.seed(seed)
        left = naive_scrump(T_B, m, T_B, percentage, zone, False, None)

        np.random.seed(seed)
        right_gen = scrump(T_B,
                           m,
                           ignore_trivial=True,
                           percentage=percentage,
                           pre_scrump=False)
        right = next(right_gen)

        naive.replace_inf(left)
        naive.replace_inf(right)
        npt.assert_almost_equal(left, right)
def test_scrump_plus_plus_full(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, percentage=0.1, pre_scraamp=True)
    np.random.seed(seed)
    comp = stumpy.scrump(T,
                         m,
                         percentage=0.1,
                         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_)
Exemplo n.º 10
0
def test_scrump_self_join_full_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)
            left_P = left[:, 0]
            left_I = left[:, 1]

            approx = scrump(
                T_B, m, ignore_trivial=True, percentage=1.0, 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_I, right_I)
Exemplo n.º 11
0
def test_scrump_A_B_join(T_A, T_B, percentages):
    m = 3

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

        np.random.seed(seed)
        left = naive_scrump(T_A, m, T_B, percentage, None, False, None)

        np.random.seed(seed)
        right_gen = scrump(T_A,
                           m,
                           T_B,
                           ignore_trivial=False,
                           percentage=percentage,
                           pre_scrump=False)
        right = next(right_gen)

        utils.replace_inf(left)
        utils.replace_inf(right)
        npt.assert_almost_equal(left, right)
Exemplo n.º 12
0
def test_scrump_A_B_join_full(T_A, T_B):

    m = 3

    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)
Exemplo n.º 13
0
def test_scrump_self_join_full(T_A, T_B):
    m = 3
    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)

    ref_mp = stump(T_B, m, ignore_trivial=True)
    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)
Exemplo n.º 14
0
def test_scrump_self_join_larger_window(T_A, T_B, percentages):
    for m in [8, 16, 32]:
        if len(T_B) > m:
            zone = int(np.ceil(m / 4))

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

                np.random.seed(seed)
                left = naive_scrump(T_B, m, T_B, percentage, zone, False, None)

                np.random.seed(seed)
                right_gen = scrump(T_B,
                                   m,
                                   ignore_trivial=True,
                                   percentage=percentage,
                                   pre_scrump=False)
                right = next(right_gen)

                utils.replace_inf(left)
                utils.replace_inf(right)
                npt.assert_almost_equal(left, right)
Exemplo n.º 15
0
def test_scrump_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)
        left = naive_scrump(T, m, T, percentage, zone, False, None)
        left_P = left[:, 0]
        left_I = left[:, 1]
        left_left_I = left[:, 2]
        left_right_I = left[:, 3]

        np.random.seed(seed)
        approx = scrump(T,
                        m,
                        ignore_trivial=True,
                        percentage=percentage,
                        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)
Exemplo n.º 16
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)
Exemplo n.º 17
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)
Exemplo n.º 18
0
def test_scrump_self_join(T):
    m = 3
    left = np.zeros(T.shape[0])
    right = scrump(T, m, percentage=0.0)
    utils.replace_inf(right)
    npt.assert_almost_equal(left, right[:, 0])
Exemplo n.º 19
0
def test_scrump_int_input():
    with pytest.raises(TypeError):
        scrump(np.arange(10), 5, ignore_trivial=True, percentage=1.0, pre_scrump=False)