Exemple #1
0
def test_stumpi_self_join_egress():
    m = 3

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

    ref_mp = naive.stumpi_egress(T, m)
    ref_P = ref_mp.P_.copy()
    ref_I = ref_mp.I_
    ref_left_P = ref_mp.left_P_.copy()
    ref_left_I = ref_mp.left_I_

    stream = stumpi(T, m, egress=True)

    comp_P = stream.P_.copy()
    comp_I = stream.I_
    comp_left_P = stream.left_P_.copy()
    comp_left_I = stream.left_I_

    naive.replace_inf(ref_P)
    naive.replace_inf(ref_left_P)
    naive.replace_inf(comp_P)
    naive.replace_inf(comp_left_P)

    npt.assert_almost_equal(ref_P, comp_P)
    npt.assert_almost_equal(ref_I, comp_I)
    npt.assert_almost_equal(ref_left_P, comp_left_P)
    npt.assert_almost_equal(ref_left_I, comp_left_I)

    for i in range(34):
        t = np.random.rand()
        ref_mp.update(t)
        stream.update(t)

        comp_P = stream.P_.copy()
        comp_I = stream.I_
        comp_left_P = stream.left_P_.copy()
        comp_left_I = stream.left_I_

        ref_P = ref_mp.P_.copy()
        ref_I = ref_mp.I_
        ref_left_P = ref_mp.left_P_.copy()
        ref_left_I = ref_mp.left_I_

        naive.replace_inf(ref_P)
        naive.replace_inf(ref_left_P)
        naive.replace_inf(comp_P)
        naive.replace_inf(comp_left_P)

        npt.assert_almost_equal(ref_P, comp_P)
        npt.assert_almost_equal(ref_I, comp_I)
        npt.assert_almost_equal(ref_left_P, comp_left_P)
        npt.assert_almost_equal(ref_left_I, comp_left_I)

    np.random.seed(seed)
    T = np.random.rand(n)
    T = pd.Series(T)

    ref_mp = naive.stumpi_egress(T, m)
    ref_P = ref_mp.P_.copy()
    ref_I = ref_mp.I_
    ref_left_P = ref_mp.left_P_.copy()
    ref_left_I = ref_mp.left_I_

    stream = stumpi(T, m, egress=True)

    comp_P = stream.P_.copy()
    comp_I = stream.I_
    comp_left_P = stream.left_P_.copy()
    comp_left_I = stream.left_I_

    naive.replace_inf(ref_P)
    naive.replace_inf(ref_left_P)
    naive.replace_inf(comp_P)
    naive.replace_inf(comp_left_P)

    npt.assert_almost_equal(ref_P, comp_P)
    npt.assert_almost_equal(ref_I, comp_I)
    npt.assert_almost_equal(ref_left_P, comp_left_P)
    npt.assert_almost_equal(ref_left_I, comp_left_I)

    for i in range(34):
        t = np.random.rand()
        t = np.random.rand()
        ref_mp.update(t)
        stream.update(t)

        comp_P = stream.P_.copy()
        comp_I = stream.I_
        comp_left_P = stream.left_P_.copy()
        comp_left_I = stream.left_I_

        ref_P = ref_mp.P_.copy()
        ref_I = ref_mp.I_
        ref_left_P = ref_mp.left_P_.copy()
        ref_left_I = ref_mp.left_I_

        naive.replace_inf(ref_P)
        naive.replace_inf(ref_left_P)
        naive.replace_inf(comp_P)
        naive.replace_inf(comp_left_P)

        npt.assert_almost_equal(ref_P, comp_P)
        npt.assert_almost_equal(ref_I, comp_I)
        npt.assert_almost_equal(ref_left_P, comp_left_P)
        npt.assert_almost_equal(ref_left_I, comp_left_I)
Exemple #2
0
def test_stumpi_constant_subsequence_self_join_egress():
    m = 3

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

    T = np.concatenate(
        (np.zeros(20, dtype=np.float64), np.ones(10, dtype=np.float64)))

    ref_mp = naive.stumpi_egress(T, m)
    ref_P = ref_mp.P_.copy()
    # ref_I = ref_mp.I_
    ref_left_P = ref_mp.left_P_.copy()
    # ref_left_I = ref_mp.left_I_

    stream = stumpi(T, m, egress=True)

    comp_P = stream.P_.copy()
    # comp_I = stream.I_
    comp_left_P = stream.left_P_.copy()
    # comp_left_I = stream.left_I_

    naive.replace_inf(ref_P)
    naive.replace_inf(ref_left_P)
    naive.replace_inf(comp_P)
    naive.replace_inf(comp_left_P)

    npt.assert_almost_equal(ref_P, comp_P)
    # npt.assert_almost_equal(ref_I, comp_I)
    npt.assert_almost_equal(ref_left_P, comp_left_P)
    # npt.assert_almost_equal(ref_left_I, comp_left_I)

    for i in range(34):
        t = np.random.rand()
        ref_mp.update(t)
        stream.update(t)

        comp_P = stream.P_.copy()
        # comp_I = stream.I_
        comp_left_P = stream.left_P_.copy()
        # comp_left_I = stream.left_I_

        ref_P = ref_mp.P_.copy()
        # ref_I = ref_mp.I_
        ref_left_P = ref_mp.left_P_.copy()
        # ref_left_I = ref_mp.left_I_

        naive.replace_inf(ref_P)
        naive.replace_inf(ref_left_P)
        naive.replace_inf(comp_P)
        naive.replace_inf(comp_left_P)

        npt.assert_almost_equal(ref_P, comp_P)
        # npt.assert_almost_equal(ref_I, comp_I)
        npt.assert_almost_equal(ref_left_P, comp_left_P)
        # npt.assert_almost_equal(ref_left_I, comp_left_I)

    np.random.seed(seed)
    T = np.concatenate(
        (np.zeros(20, dtype=np.float64), np.ones(10, dtype=np.float64)))
    T = pd.Series(T)

    ref_mp = naive.stumpi_egress(T, m)
    ref_P = ref_mp.P_.copy()
    # ref_I = ref_mp.I_
    ref_left_P = ref_mp.left_P_.copy()
    # ref_left_I = ref_mp.left_I_

    stream = stumpi(T, m, egress=True)

    comp_P = stream.P_.copy()
    # comp_I = stream.I_
    comp_left_P = stream.left_P_.copy()
    # comp_left_I = stream.left_I_

    naive.replace_inf(ref_P)
    naive.replace_inf(ref_left_P)
    naive.replace_inf(comp_P)
    naive.replace_inf(comp_left_P)

    npt.assert_almost_equal(ref_P, comp_P)
    # npt.assert_almost_equal(ref_I, comp_I)
    npt.assert_almost_equal(ref_left_P, comp_left_P)
    # npt.assert_almost_equal(ref_left_I, comp_left_I)

    for i in range(34):
        t = np.random.rand()
        ref_mp.update(t)
        stream.update(t)

        comp_P = stream.P_.copy()
        # comp_I = stream.I_
        comp_left_P = stream.left_P_.copy()
        # comp_left_I = stream.left_I_

        ref_P = ref_mp.P_.copy()
        # ref_I = ref_mp.I_
        ref_left_P = ref_mp.left_P_.copy()
        # ref_left_I = ref_mp.left_I_

        naive.replace_inf(ref_P)
        naive.replace_inf(ref_left_P)
        naive.replace_inf(comp_P)
        naive.replace_inf(comp_left_P)

        npt.assert_almost_equal(ref_P, comp_P)
        # npt.assert_almost_equal(ref_I, comp_I)
        npt.assert_almost_equal(ref_left_P, comp_left_P)
Exemple #3
0
def test_stumpi_identical_subsequence_self_join_egress():
    m = 3

    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

    ref_mp = naive.stumpi_egress(T, m)
    ref_P = ref_mp.P_.copy()
    # ref_I = ref_mp.I_
    ref_left_P = ref_mp.left_P_.copy()
    # ref_left_I = ref_mp.left_I_

    stream = stumpi(T, m, egress=True)

    comp_P = stream.P_.copy()
    # comp_I = stream.I_
    comp_left_P = stream.left_P_.copy()
    # comp_left_I = stream.left_I_

    naive.replace_inf(ref_P)
    naive.replace_inf(ref_left_P)
    naive.replace_inf(comp_P)
    naive.replace_inf(comp_left_P)

    npt.assert_almost_equal(ref_P,
                            comp_P,
                            decimal=config.STUMPY_TEST_PRECISION)
    # npt.assert_almost_equal(ref_I, comp_I)
    npt.assert_almost_equal(ref_left_P,
                            comp_left_P,
                            decimal=config.STUMPY_TEST_PRECISION)
    # npt.assert_almost_equal(ref_left_I, comp_left_I)

    for i in range(34):
        t = np.random.rand()
        ref_mp.update(t)
        stream.update(t)

        comp_P = stream.P_.copy()
        # comp_I = stream.I_
        comp_left_P = stream.left_P_.copy()
        # comp_left_I = stream.left_I_

        ref_P = ref_mp.P_.copy()
        # ref_I = ref_mp.I_
        ref_left_P = ref_mp.left_P_.copy()
        # ref_left_I = ref_mp.left_I_

        naive.replace_inf(ref_P)
        naive.replace_inf(ref_left_P)
        naive.replace_inf(comp_P)
        naive.replace_inf(comp_left_P)

        npt.assert_almost_equal(ref_P,
                                comp_P,
                                decimal=config.STUMPY_TEST_PRECISION)
        # npt.assert_almost_equal(ref_I, comp_I)
        npt.assert_almost_equal(ref_left_P,
                                comp_left_P,
                                decimal=config.STUMPY_TEST_PRECISION)
        # npt.assert_almost_equal(ref_left_I, comp_left_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)
    ref_mp = naive.stumpi_egress(T, m)
    ref_P = ref_mp.P_.copy()
    # ref_I = ref_mp.I_
    ref_left_P = ref_mp.left_P_.copy()
    # ref_left_I = ref_mp.left_I_

    stream = stumpi(T, m, egress=True)

    comp_P = stream.P_.copy()
    # comp_I = stream.I_
    comp_left_P = stream.left_P_.copy()
    # comp_left_I = stream.left_I_

    naive.replace_inf(ref_P)
    naive.replace_inf(ref_left_P)
    naive.replace_inf(comp_P)
    naive.replace_inf(comp_left_P)

    npt.assert_almost_equal(ref_P,
                            comp_P,
                            decimal=config.STUMPY_TEST_PRECISION)
    # npt.assert_almost_equal(ref_I, comp_I)
    npt.assert_almost_equal(ref_left_P,
                            comp_left_P,
                            decimal=config.STUMPY_TEST_PRECISION)
    # npt.assert_almost_equal(ref_left_I, comp_left_I)

    for i in range(34):
        t = np.random.rand()
        ref_mp.update(t)
        stream.update(t)

        comp_P = stream.P_.copy()
        # comp_I = stream.I_
        comp_left_P = stream.left_P_.copy()
        # comp_left_I = stream.left_I_

        ref_P = ref_mp.P_.copy()
        # ref_I = ref_mp.I_
        ref_left_P = ref_mp.left_P_.copy()
        # ref_left_I = ref_mp.left_I_

        naive.replace_inf(ref_P)
        naive.replace_inf(ref_left_P)
        naive.replace_inf(comp_P)
        naive.replace_inf(comp_left_P)

        npt.assert_almost_equal(ref_P,
                                comp_P,
                                decimal=config.STUMPY_TEST_PRECISION)
        # npt.assert_almost_equal(ref_I, comp_I)
        npt.assert_almost_equal(ref_left_P,
                                comp_left_P,
                                decimal=config.STUMPY_TEST_PRECISION)
Exemple #4
0
def test_stumpi_init_nan_inf_self_join_egress(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

        ref_mp = naive.stumpi_egress(T, m)
        ref_P = ref_mp.P_.copy()
        ref_I = ref_mp.I_
        ref_left_P = ref_mp.left_P_.copy()
        ref_left_I = ref_mp.left_I_

        stream = stumpi(T, m, egress=True)

        comp_P = stream.P_.copy()
        comp_I = stream.I_
        comp_left_P = stream.left_P_.copy()
        comp_left_I = stream.left_I_

        naive.replace_inf(ref_P)
        naive.replace_inf(ref_left_P)
        naive.replace_inf(comp_P)
        naive.replace_inf(comp_left_P)

        npt.assert_almost_equal(ref_P, comp_P)
        npt.assert_almost_equal(ref_I, comp_I)
        npt.assert_almost_equal(ref_left_P, comp_left_P)
        npt.assert_almost_equal(ref_left_I, comp_left_I)

        for i in range(34):
            t = np.random.rand()
            ref_mp.update(t)
            stream.update(t)

            comp_P = stream.P_.copy()
            comp_I = stream.I_
            comp_left_P = stream.left_P_.copy()
            comp_left_I = stream.left_I_

            ref_P = ref_mp.P_.copy()
            ref_I = ref_mp.I_
            ref_left_P = ref_mp.left_P_.copy()
            ref_left_I = ref_mp.left_I_

            naive.replace_inf(ref_P)
            naive.replace_inf(ref_left_P)
            naive.replace_inf(comp_P)
            naive.replace_inf(comp_left_P)

            npt.assert_almost_equal(ref_P, comp_P)
            npt.assert_almost_equal(ref_I, comp_I)
            npt.assert_almost_equal(ref_left_P, comp_left_P)
            npt.assert_almost_equal(ref_left_I, comp_left_I)

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

        if substitution_location == -1:  # pragma: no cover
            substitution_location = T.shape[0] - 1
        T[substitution_location] = substitute
        T = pd.Series(T)

        ref_mp = naive.stumpi_egress(T, m)
        ref_P = ref_mp.P_.copy()
        ref_I = ref_mp.I_
        ref_left_P = ref_mp.left_P_.copy()
        ref_left_I = ref_mp.left_I_

        stream = stumpi(T, m, egress=True)

        comp_P = stream.P_.copy()
        comp_I = stream.I_
        comp_left_P = stream.left_P_.copy()
        comp_left_I = stream.left_I_

        naive.replace_inf(ref_P)
        naive.replace_inf(ref_left_P)
        naive.replace_inf(comp_P)
        naive.replace_inf(comp_left_P)

        npt.assert_almost_equal(ref_P, comp_P)
        npt.assert_almost_equal(ref_I, comp_I)
        npt.assert_almost_equal(ref_left_P, comp_left_P)
        npt.assert_almost_equal(ref_left_I, comp_left_I)

        for i in range(34):
            t = np.random.rand()
            ref_mp.update(t)
            stream.update(t)

            comp_P = stream.P_.copy()
            comp_I = stream.I_
            comp_left_P = stream.left_P_.copy()
            comp_left_I = stream.left_I_

            ref_P = ref_mp.P_.copy()
            ref_I = ref_mp.I_
            ref_left_P = ref_mp.left_P_.copy()
            ref_left_I = ref_mp.left_I_

            naive.replace_inf(ref_P)
            naive.replace_inf(ref_left_P)
            naive.replace_inf(comp_P)
            naive.replace_inf(comp_left_P)

            npt.assert_almost_equal(ref_P, comp_P)
            npt.assert_almost_equal(ref_I, comp_I)
            npt.assert_almost_equal(ref_left_P, comp_left_P)
            npt.assert_almost_equal(ref_left_I, comp_left_I)
Exemple #5
0
def test_stumpi_stream_nan_inf_self_join_egress(substitute,
                                                substitution_locations):
    m = 3

    seed = np.random.randint(100000)

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

        ref_mp = naive.stumpi_egress(T[:n], m)
        ref_P = ref_mp.P_.copy()
        ref_I = ref_mp.I_
        ref_left_P = ref_mp.left_P_.copy()
        ref_left_I = ref_mp.left_I_

        stream = stumpi(T[:n], m, egress=True)

        comp_P = stream.P_.copy()
        comp_I = stream.I_
        comp_left_P = stream.left_P_.copy()
        comp_left_I = stream.left_I_

        naive.replace_inf(ref_P)
        naive.replace_inf(ref_left_P)
        naive.replace_inf(comp_P)
        naive.replace_inf(comp_left_P)

        npt.assert_almost_equal(ref_P, comp_P)
        npt.assert_almost_equal(ref_I, comp_I)
        npt.assert_almost_equal(ref_left_P, comp_left_P)
        npt.assert_almost_equal(ref_left_I, comp_left_I)

        if substitution_location == -1:
            substitution_location = T[30:].shape[0] - 1
        T[n:][substitution_location] = substitute
        for t in T[n:]:
            ref_mp.update(t)
            stream.update(t)

            comp_P = stream.P_.copy()
            comp_I = stream.I_
            comp_left_P = stream.left_P_.copy()
            comp_left_I = stream.left_I_

            ref_P = ref_mp.P_.copy()
            ref_I = ref_mp.I_
            ref_left_P = ref_mp.left_P_.copy()
            ref_left_I = ref_mp.left_I_

            naive.replace_inf(ref_P)
            naive.replace_inf(ref_left_P)
            naive.replace_inf(comp_P)
            naive.replace_inf(comp_left_P)

            npt.assert_almost_equal(ref_P, comp_P)
            npt.assert_almost_equal(ref_I, comp_I)
            npt.assert_almost_equal(ref_left_P, comp_left_P)
            npt.assert_almost_equal(ref_left_I, comp_left_I)

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

        ref_mp = naive.stumpi_egress(T[:n], m)
        ref_P = ref_mp.P_.copy()
        ref_I = ref_mp.I_
        ref_left_P = ref_mp.left_P_.copy()
        ref_left_I = ref_mp.left_I_

        stream = stumpi(T[:n], m, egress=True)

        comp_P = stream.P_.copy()
        comp_I = stream.I_
        comp_left_P = stream.left_P_.copy()
        comp_left_I = stream.left_I_

        naive.replace_inf(ref_P)
        naive.replace_inf(ref_left_P)
        naive.replace_inf(comp_P)
        naive.replace_inf(comp_left_P)

        npt.assert_almost_equal(ref_P, comp_P)
        npt.assert_almost_equal(ref_I, comp_I)
        npt.assert_almost_equal(ref_left_P, comp_left_P)
        npt.assert_almost_equal(ref_left_I, comp_left_I)

        if substitution_location == -1:  # pragma: no cover
            substitution_location = T[n:].shape[0] - 1
        T[n:][substitution_location] = substitute
        for t in T[n:]:
            ref_mp.update(t)
            stream.update(t)

            comp_P = stream.P_.copy()
            comp_I = stream.I_
            comp_left_P = stream.left_P_.copy()
            comp_left_I = stream.left_I_

            ref_P = ref_mp.P_.copy()
            ref_I = ref_mp.I_
            ref_left_P = ref_mp.left_P_.copy()
            ref_left_I = ref_mp.left_I_

            naive.replace_inf(ref_P)
            naive.replace_inf(ref_left_P)
            naive.replace_inf(comp_P)
            naive.replace_inf(comp_left_P)

            npt.assert_almost_equal(ref_P, comp_P)
            npt.assert_almost_equal(ref_I, comp_I)
            npt.assert_almost_equal(ref_left_P, comp_left_P)
            npt.assert_almost_equal(ref_left_I, comp_left_I)
Exemple #6
0
def test_stumpi_self_join_egress():
    m = 3
    zone = int(np.ceil(m / 4))

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

    left = naive.stumpi_egress(T, m)
    left_P = left.P_.copy()
    left_I = left.I_
    left_left_P = left.left_P_.copy()
    left_left_I = left.left_I_

    stream = stumpi(T, m, egress=True)

    right_P = stream.P_.copy()
    right_I = stream.I_
    right_left_P = stream.left_P_.copy()
    right_left_I = stream.left_I_

    naive.replace_inf(left_P)
    naive.replace_inf(left_left_P)
    naive.replace_inf(right_P)
    naive.replace_inf(right_left_P)

    npt.assert_almost_equal(left_P, right_P)
    npt.assert_almost_equal(left_I, right_I)
    npt.assert_almost_equal(left_left_P, right_left_P)
    npt.assert_almost_equal(left_left_I, right_left_I)

    for i in range(34):
        t = np.random.rand()
        left.update(t)
        stream.update(t)

        right_P = stream.P_.copy()
        right_I = stream.I_
        right_left_P = stream.left_P_.copy()
        right_left_I = stream.left_I_

        left_P = left.P_.copy()
        left_I = left.I_
        left_left_P = left.left_P_.copy()
        left_left_I = left.left_I_

        naive.replace_inf(left_P)
        naive.replace_inf(left_left_P)
        naive.replace_inf(right_P)
        naive.replace_inf(right_left_P)

        npt.assert_almost_equal(left_P, right_P)
        npt.assert_almost_equal(left_I, right_I)
        npt.assert_almost_equal(left_left_P, right_left_P)
        npt.assert_almost_equal(left_left_I, right_left_I)

    np.random.seed(seed)
    T = np.random.rand(n)
    T = pd.Series(T)

    left = naive.stumpi_egress(T, m)
    left_P = left.P_.copy()
    left_I = left.I_
    left_left_P = left.left_P_.copy()
    left_left_I = left.left_I_

    stream = stumpi(T, m, egress=True)

    right_P = stream.P_.copy()
    right_I = stream.I_
    right_left_P = stream.left_P_.copy()
    right_left_I = stream.left_I_

    naive.replace_inf(left_P)
    naive.replace_inf(left_left_P)
    naive.replace_inf(right_P)
    naive.replace_inf(right_left_P)

    npt.assert_almost_equal(left_P, right_P)
    npt.assert_almost_equal(left_I, right_I)
    npt.assert_almost_equal(left_left_P, right_left_P)
    npt.assert_almost_equal(left_left_I, right_left_I)

    for i in range(34):
        t = np.random.rand()
        t = np.random.rand()
        left.update(t)
        stream.update(t)

        right_P = stream.P_.copy()
        right_I = stream.I_
        right_left_P = stream.left_P_.copy()
        right_left_I = stream.left_I_

        left_P = left.P_.copy()
        left_I = left.I_
        left_left_P = left.left_P_.copy()
        left_left_I = left.left_I_

        naive.replace_inf(left_P)
        naive.replace_inf(left_left_P)
        naive.replace_inf(right_P)
        naive.replace_inf(right_left_P)

        npt.assert_almost_equal(left_P, right_P)
        npt.assert_almost_equal(left_I, right_I)
        npt.assert_almost_equal(left_left_P, right_left_P)
        npt.assert_almost_equal(left_left_I, right_left_I)
Exemple #7
0
def test_stumpi_identical_subsequence_self_join_egress():
    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

    left = naive.stumpi_egress(T, m)
    left_P = left.P_.copy()
    left_I = left.I_
    left_left_P = left.left_P_.copy()
    left_left_I = left.left_I_

    stream = stumpi(T, m, egress=True)

    right_P = stream.P_.copy()
    right_I = stream.I_
    right_left_P = stream.left_P_.copy()
    right_left_I = stream.left_I_

    naive.replace_inf(left_P)
    naive.replace_inf(left_left_P)
    naive.replace_inf(right_P)
    naive.replace_inf(right_left_P)

    npt.assert_almost_equal(left_P, right_P, decimal=config.STUMPY_TEST_PRECISION)
    # npt.assert_almost_equal(left_I, right_I)
    npt.assert_almost_equal(
        left_left_P, right_left_P, decimal=config.STUMPY_TEST_PRECISION
    )
    # npt.assert_almost_equal(left_left_I, right_left_I)

    for i in range(34):
        t = np.random.rand()
        left.update(t)
        stream.update(t)

        right_P = stream.P_.copy()
        right_I = stream.I_
        right_left_P = stream.left_P_.copy()
        right_left_I = stream.left_I_

        left_P = left.P_.copy()
        left_I = left.I_
        left_left_P = left.left_P_.copy()
        left_left_I = left.left_I_

        naive.replace_inf(left_P)
        naive.replace_inf(left_left_P)
        naive.replace_inf(right_P)
        naive.replace_inf(right_left_P)

        npt.assert_almost_equal(left_P, right_P, decimal=config.STUMPY_TEST_PRECISION)
        # npt.assert_almost_equal(left_I, right_I)
        npt.assert_almost_equal(
            left_left_P, right_left_P, decimal=config.STUMPY_TEST_PRECISION
        )
        # npt.assert_almost_equal(left_left_I, right_left_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)
    left = naive.stumpi_egress(T, m)
    left_P = left.P_.copy()
    left_I = left.I_
    left_left_P = left.left_P_.copy()
    left_left_I = left.left_I_

    stream = stumpi(T, m, egress=True)

    right_P = stream.P_.copy()
    right_I = stream.I_
    right_left_P = stream.left_P_.copy()
    right_left_I = stream.left_I_

    naive.replace_inf(left_P)
    naive.replace_inf(left_left_P)
    naive.replace_inf(right_P)
    naive.replace_inf(right_left_P)

    npt.assert_almost_equal(left_P, right_P, decimal=config.STUMPY_TEST_PRECISION)
    # npt.assert_almost_equal(left_I, right_I)
    npt.assert_almost_equal(
        left_left_P, right_left_P, decimal=config.STUMPY_TEST_PRECISION
    )
    # npt.assert_almost_equal(left_left_I, right_left_I)

    for i in range(34):
        t = np.random.rand()
        left.update(t)
        stream.update(t)

        right_P = stream.P_.copy()
        right_I = stream.I_
        right_left_P = stream.left_P_.copy()
        right_left_I = stream.left_I_

        left_P = left.P_.copy()
        left_I = left.I_
        left_left_P = left.left_P_.copy()
        left_left_I = left.left_I_

        naive.replace_inf(left_P)
        naive.replace_inf(left_left_P)
        naive.replace_inf(right_P)
        naive.replace_inf(right_left_P)

        npt.assert_almost_equal(left_P, right_P, decimal=config.STUMPY_TEST_PRECISION)
        # npt.assert_almost_equal(left_I, right_I)
        npt.assert_almost_equal(
            left_left_P, right_left_P, decimal=config.STUMPY_TEST_PRECISION
        )
Exemple #8
0
def test_stumpi_constant_subsequence_self_join_egress():
    m = 3
    zone = int(np.ceil(m / 4))

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

    T = np.concatenate((np.zeros(20, dtype=np.float64), np.ones(10, dtype=np.float64)))

    left = naive.stumpi_egress(T, m)
    left_P = left.P_.copy()
    left_I = left.I_
    left_left_P = left.left_P_.copy()
    left_left_I = left.left_I_

    stream = stumpi(T, m, egress=True)

    right_P = stream.P_.copy()
    right_I = stream.I_
    right_left_P = stream.left_P_.copy()
    right_left_I = stream.left_I_

    naive.replace_inf(left_P)
    naive.replace_inf(left_left_P)
    naive.replace_inf(right_P)
    naive.replace_inf(right_left_P)

    npt.assert_almost_equal(left_P, right_P)
    # npt.assert_almost_equal(left_I, right_I)
    npt.assert_almost_equal(left_left_P, right_left_P)
    # npt.assert_almost_equal(left_left_I, right_left_I)

    for i in range(34):
        t = np.random.rand()
        left.update(t)
        stream.update(t)

        right_P = stream.P_.copy()
        right_I = stream.I_
        right_left_P = stream.left_P_.copy()
        right_left_I = stream.left_I_

        left_P = left.P_.copy()
        left_I = left.I_
        left_left_P = left.left_P_.copy()
        left_left_I = left.left_I_

        naive.replace_inf(left_P)
        naive.replace_inf(left_left_P)
        naive.replace_inf(right_P)
        naive.replace_inf(right_left_P)

        npt.assert_almost_equal(left_P, right_P)
        # npt.assert_almost_equal(left_I, right_I)
        npt.assert_almost_equal(left_left_P, right_left_P)
        # npt.assert_almost_equal(left_left_I, right_left_I)

    np.random.seed(seed)
    T = np.concatenate((np.zeros(20, dtype=np.float64), np.ones(10, dtype=np.float64)))
    T = pd.Series(T)

    left = naive.stumpi_egress(T, m)
    left_P = left.P_.copy()
    left_I = left.I_
    left_left_P = left.left_P_.copy()
    left_left_I = left.left_I_

    stream = stumpi(T, m, egress=True)

    right_P = stream.P_.copy()
    right_I = stream.I_
    right_left_P = stream.left_P_.copy()
    right_left_I = stream.left_I_

    naive.replace_inf(left_P)
    naive.replace_inf(left_left_P)
    naive.replace_inf(right_P)
    naive.replace_inf(right_left_P)

    npt.assert_almost_equal(left_P, right_P)
    # npt.assert_almost_equal(left_I, right_I)
    npt.assert_almost_equal(left_left_P, right_left_P)
    # npt.assert_almost_equal(left_left_I, right_left_I)

    for i in range(34):
        t = np.random.rand()
        left.update(t)
        stream.update(t)

        right_P = stream.P_.copy()
        right_I = stream.I_
        right_left_P = stream.left_P_.copy()
        right_left_I = stream.left_I_

        left_P = left.P_.copy()
        left_I = left.I_
        left_left_P = left.left_P_.copy()
        left_left_I = left.left_I_

        naive.replace_inf(left_P)
        naive.replace_inf(left_left_P)
        naive.replace_inf(right_P)
        naive.replace_inf(right_left_P)

        npt.assert_almost_equal(left_P, right_P)
        # npt.assert_almost_equal(left_I, right_I)
        npt.assert_almost_equal(left_left_P, right_left_P)
Exemple #9
0
def test_stumpi_stream_nan_inf_self_join_egress(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)
        n = 30

        left = naive.stumpi_egress(T[:n], m)
        left_P = left.P_.copy()
        left_I = left.I_
        left_left_P = left.left_P_.copy()
        left_left_I = left.left_I_

        stream = stumpi(T[:n], m, egress=True)

        right_P = stream.P_.copy()
        right_I = stream.I_
        right_left_P = stream.left_P_.copy()
        right_left_I = stream.left_I_

        naive.replace_inf(left_P)
        naive.replace_inf(left_left_P)
        naive.replace_inf(right_P)
        naive.replace_inf(right_left_P)

        npt.assert_almost_equal(left_P, right_P)
        npt.assert_almost_equal(left_I, right_I)
        npt.assert_almost_equal(left_left_P, right_left_P)
        npt.assert_almost_equal(left_left_I, right_left_I)

        if substitution_location == -1:
            substitution_location = T[30:].shape[0] - 1
        T[n:][substitution_location] = substitute
        for t in T[n:]:
            left.update(t)
            stream.update(t)

            right_P = stream.P_.copy()
            right_I = stream.I_
            right_left_P = stream.left_P_.copy()
            right_left_I = stream.left_I_

            left_P = left.P_.copy()
            left_I = left.I_
            left_left_P = left.left_P_.copy()
            left_left_I = left.left_I_

            naive.replace_inf(left_P)
            naive.replace_inf(left_left_P)
            naive.replace_inf(right_P)
            naive.replace_inf(right_left_P)

            npt.assert_almost_equal(left_P, right_P)
            npt.assert_almost_equal(left_I, right_I)
            npt.assert_almost_equal(left_left_P, right_left_P)
            npt.assert_almost_equal(left_left_I, right_left_I)

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

        left = naive.stumpi_egress(T[:n], m)
        left_P = left.P_.copy()
        left_I = left.I_
        left_left_P = left.left_P_.copy()
        left_left_I = left.left_I_

        stream = stumpi(T[:n], m, egress=True)

        right_P = stream.P_.copy()
        right_I = stream.I_
        right_left_P = stream.left_P_.copy()
        right_left_I = stream.left_I_

        naive.replace_inf(left_P)
        naive.replace_inf(left_left_P)
        naive.replace_inf(right_P)
        naive.replace_inf(right_left_P)

        npt.assert_almost_equal(left_P, right_P)
        npt.assert_almost_equal(left_I, right_I)
        npt.assert_almost_equal(left_left_P, right_left_P)
        npt.assert_almost_equal(left_left_I, right_left_I)

        if substitution_location == -1:
            substitution_location = T[n:].shape[0] - 1
        T[n:][substitution_location] = substitute
        for t in T[n:]:
            left.update(t)
            stream.update(t)

            right_P = stream.P_.copy()
            right_I = stream.I_
            right_left_P = stream.left_P_.copy()
            right_left_I = stream.left_I_

            left_P = left.P_.copy()
            left_I = left.I_
            left_left_P = left.left_P_.copy()
            left_left_I = left.left_I_

            naive.replace_inf(left_P)
            naive.replace_inf(left_left_P)
            naive.replace_inf(right_P)
            naive.replace_inf(right_left_P)

            npt.assert_almost_equal(left_P, right_P)
            npt.assert_almost_equal(left_I, right_I)
            npt.assert_almost_equal(left_left_P, right_left_P)
            npt.assert_almost_equal(left_left_I, right_left_I)
Exemple #10
0
def test_stumpi_init_nan_inf_self_join_egress(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

        left = naive.stumpi_egress(T, m)
        left_P = left.P_.copy()
        left_I = left.I_
        left_left_P = left.left_P_.copy()
        left_left_I = left.left_I_

        stream = stumpi(T, m, egress=True)

        right_P = stream.P_.copy()
        right_I = stream.I_
        right_left_P = stream.left_P_.copy()
        right_left_I = stream.left_I_

        naive.replace_inf(left_P)
        naive.replace_inf(left_left_P)
        naive.replace_inf(right_P)
        naive.replace_inf(right_left_P)

        npt.assert_almost_equal(left_P, right_P)
        npt.assert_almost_equal(left_I, right_I)
        npt.assert_almost_equal(left_left_P, right_left_P)
        npt.assert_almost_equal(left_left_I, right_left_I)

        for i in range(34):
            t = np.random.rand()
            left.update(t)
            stream.update(t)

            right_P = stream.P_.copy()
            right_I = stream.I_
            right_left_P = stream.left_P_.copy()
            right_left_I = stream.left_I_

            left_P = left.P_.copy()
            left_I = left.I_
            left_left_P = left.left_P_.copy()
            left_left_I = left.left_I_

            naive.replace_inf(left_P)
            naive.replace_inf(left_left_P)
            naive.replace_inf(right_P)
            naive.replace_inf(right_left_P)

            npt.assert_almost_equal(left_P, right_P)
            npt.assert_almost_equal(left_I, right_I)
            npt.assert_almost_equal(left_left_P, right_left_P)
            npt.assert_almost_equal(left_left_I, right_left_I)

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

        if substitution_location == -1:
            substitution_location = T.shape[0] - 1
        T[substitution_location] = substitute
        T = pd.Series(T)

        left = naive.stumpi_egress(T, m)
        left_P = left.P_.copy()
        left_I = left.I_
        left_left_P = left.left_P_.copy()
        left_left_I = left.left_I_

        stream = stumpi(T, m, egress=True)

        right_P = stream.P_.copy()
        right_I = stream.I_
        right_left_P = stream.left_P_.copy()
        right_left_I = stream.left_I_

        naive.replace_inf(left_P)
        naive.replace_inf(left_left_P)
        naive.replace_inf(right_P)
        naive.replace_inf(right_left_P)

        npt.assert_almost_equal(left_P, right_P)
        npt.assert_almost_equal(left_I, right_I)
        npt.assert_almost_equal(left_left_P, right_left_P)
        npt.assert_almost_equal(left_left_I, right_left_I)

        for i in range(34):
            t = np.random.rand()
            left.update(t)
            stream.update(t)

            right_P = stream.P_.copy()
            right_I = stream.I_
            right_left_P = stream.left_P_.copy()
            right_left_I = stream.left_I_

            left_P = left.P_.copy()
            left_I = left.I_
            left_left_P = left.left_P_.copy()
            left_left_I = left.left_I_

            naive.replace_inf(left_P)
            naive.replace_inf(left_left_P)
            naive.replace_inf(right_P)
            naive.replace_inf(right_left_P)

            npt.assert_almost_equal(left_P, right_P)
            npt.assert_almost_equal(left_I, right_I)
            npt.assert_almost_equal(left_left_P, right_left_P)
            npt.assert_almost_equal(left_left_I, right_left_I)