示例#1
0
    def test_calculate_columns_with_series_shifting(self):
        dm = np.array([[2., 2., 3., 1., -1., -5], [4., 1., 2., 4., -2., -6.],
                       [1., 3., 4., 2., -3., -7.], [3., 4., 1., 3., -4., 0.]])
        #   =============== : window

        mplr = ShiftingMatrixProfileLR()
        mplr.initialise(1, 4, 4)

        mplr.process_column(0, np.atleast_2d(dm[:, 0]))
        mplr.process_column(1, np.atleast_2d(dm[:, 1]))

        npt.assert_equal(mplr.matrix_profile_left, [2., 1, np.inf, np.inf])
        npt.assert_equal(mplr.profile_index_left, [0, 1, -1, -1])
        npt.assert_equal(mplr.matrix_profile_right, [1., 3, np.inf, np.inf])
        npt.assert_equal(mplr.profile_index_right, [2, 2, -1, -1])
        npt.assert_equal(mplr.matrix_profile(), [1., 1., np.inf, np.inf])
        npt.assert_equal(mplr.profile_index(), [2, 1, -1, -1])

        mplr.shift_series(1)
        npt.assert_equal(mplr.matrix_profile_left, [1, np.inf, np.inf, np.inf])
        npt.assert_equal(mplr.profile_index_left, [1, -1, -1, -1])
        npt.assert_equal(mplr.matrix_profile_right,
                         [3, np.inf, np.inf, np.inf])
        npt.assert_equal(mplr.profile_index_right, [2, -1, -1, -1])
        npt.assert_equal(mplr.matrix_profile(), [1., np.inf, np.inf, np.inf])
        npt.assert_equal(mplr.profile_index(), [1, -1, -1, -1])

        mplr.process_column(1, np.atleast_2d(dm[:, 2]))
        npt.assert_equal(mplr.matrix_profile_left, [1, 2, np.inf, np.inf])
        npt.assert_equal(mplr.profile_index_left, [1, 1, -1, -1])
        npt.assert_equal(mplr.matrix_profile_right, [3, 1, np.inf, np.inf])
        npt.assert_equal(mplr.profile_index_right, [2, 3, -1, -1])
        npt.assert_equal(mplr.matrix_profile(), [1., 1, np.inf, np.inf])
        npt.assert_equal(mplr.profile_index(), [1, 3, -1, -1])

        mplr.shift_series(1)
        mplr.process_column(1, np.atleast_2d(dm[:, 3]))
        npt.assert_equal(mplr.matrix_profile_left, [2., 1, np.inf, np.inf])
        npt.assert_equal(mplr.profile_index_left, [1, 0, -1, -1])
        npt.assert_equal(mplr.matrix_profile_right,
                         [1., np.inf, np.inf, np.inf])
        npt.assert_equal(mplr.profile_index_right, [3, -1, -1, -1])
        npt.assert_equal(mplr.matrix_profile(), [1., 1., np.inf, np.inf])
        npt.assert_equal(mplr.profile_index(), [3, 0, -1, -1])

        mplr.process_column(2, np.atleast_2d(dm[:, 4]))
        mplr.process_column(3, np.atleast_2d(dm[:, 5]))

        npt.assert_equal(mplr.matrix_profile_left, [2., 1, -4, -7])
        npt.assert_equal(mplr.profile_index_left, [1, 0, 3, 2])
        npt.assert_equal(mplr.matrix_profile_right,
                         [1., np.inf, np.inf, np.inf])
        npt.assert_equal(mplr.profile_index_right, [3, -1, -1, -1])
        npt.assert_equal(mplr.matrix_profile(), [1., 1., -4, -7])
        npt.assert_equal(mplr.profile_index(), [3, 0, 3, 2])
示例#2
0
    def test_calculate_diagonals_with_series_shifting(self):
        dm = np.array([[2., 2., 3., 1., -1., -5], [4., 1., 2., 4., -2., -6.],
                       [1., 3., 4., 2., -3., -7.], [3., 4., 1., 3., -4., 0.]])
        #   =============== : window

        mplr = ShiftingMatrixProfileLR()
        mplr.initialise(1, 4, 4)

        for diag in range(-3, 0):
            mplr.process_diagonal(
                diag, np.atleast_2d(dm[:, :4][diag_indices(4, 4, diag)]))
        for diag in range(1, 4):
            mplr.process_diagonal(
                diag, np.atleast_2d(dm[:, :4][diag_indices(4, 4, diag)]))

        npt.assert_equal(mplr.matrix_profile_left, [np.inf, 2, 2., 1])
        npt.assert_equal(mplr.profile_index_left, [-1, 0, 1, 0])
        npt.assert_equal(mplr.matrix_profile_right, [1., 3, 1., np.inf])
        npt.assert_equal(mplr.profile_index_right, [2, 2, 3, -1])
        npt.assert_equal(mplr.matrix_profile(), [1., 2., 1., 1.])
        npt.assert_equal(mplr.profile_index(), [2, 0, 3, 0])

        mplr.shift_series(1)
        mplr.process_diagonal(
            -1, np.atleast_2d(dm[:, 1:5][diag_indices(4, 4, -1)]))
        npt.assert_equal(mplr.matrix_profile_left, [1., 2., 1, np.inf])
        npt.assert_equal(mplr.profile_index_left, [1, 1, 0, -1])
        npt.assert_equal(mplr.matrix_profile_right, [3, 1., np.inf, np.inf])
        npt.assert_equal(mplr.profile_index_right, [2, 3, -1, -1])
        npt.assert_equal(mplr.matrix_profile(), [1., 1., 1., np.inf])
        npt.assert_equal(mplr.profile_index(), [1, 3, 0, -1])

        mplr.shift_series(1)
        npt.assert_equal(mplr.matrix_profile_left, [2., 1, np.inf, np.inf])
        npt.assert_equal(mplr.profile_index_left, [1, 0, -1, -1])
        npt.assert_equal(mplr.matrix_profile_right,
                         [1., np.inf, np.inf, np.inf])
        npt.assert_equal(mplr.profile_index_right, [3, -1, -1, -1])
        npt.assert_equal(mplr.matrix_profile(), [1., 1., np.inf, np.inf])
        npt.assert_equal(mplr.profile_index(), [3, 0, -1, -1])

        for diag in range(-1, 4):
            mplr.process_diagonal(
                diag, np.atleast_2d(dm[:, 2:][diag_indices(4, 4, diag)]))

        npt.assert_equal(mplr.matrix_profile_left, [2., 1, -4, -7])
        npt.assert_equal(mplr.profile_index_left, [1, 0, 3, 2])
        npt.assert_equal(mplr.matrix_profile_right,
                         [1., np.inf, np.inf, np.inf])
        npt.assert_equal(mplr.profile_index_right, [3, -1, -1, -1])
        npt.assert_equal(mplr.matrix_profile(), [1., 1., -4, -7])
        npt.assert_equal(mplr.profile_index(), [3, 0, 3, 2])
示例#3
0
    def test_calculate_diagonals_with_series_and_query_shifting(self):
        dm = np.array([[2., 2., 3., 1., nan, nan], [4., 1., 2., 4., nan, nan],
                       [1., 3., 4., 2., -1., -5.], [3., 4., 1., 3., -2., -6.],
                       [nan, nan, nan, -1., -3., -7.],
                       [nan, nan, nan, nan, -4., 0.]])

        mplr = ShiftingMatrixProfileLR()
        mplr.initialise(1, 4, 4)

        for diag in range(-3, 4):
            mplr.process_diagonal(
                diag, np.atleast_2d(dm[:, :4][diag_indices(4, 4, diag)]))

        npt.assert_equal(mplr.matrix_profile_left, [2., 1, 2., 1])
        npt.assert_equal(mplr.profile_index_left, [0, 1, 1, 0])
        npt.assert_equal(mplr.matrix_profile_right, [1., 3, 1., np.inf])
        npt.assert_equal(mplr.profile_index_right, [2, 2, 3, -1])
        npt.assert_equal(mplr.matrix_profile(), [1., 1., 1., 1.])
        npt.assert_equal(mplr.profile_index(), [2, 1, 3, 0])

        mplr.shift_query(2)
        mplr.shift_series(2)
        npt.assert_equal(mplr.matrix_profile_left, [2., 1, np.inf, np.inf])
        npt.assert_equal(mplr.profile_index_left, [1, 0, -1, -1])
        npt.assert_equal(mplr.matrix_profile_right,
                         [1., np.inf, np.inf, np.inf])
        npt.assert_equal(mplr.profile_index_right, [3, -1, -1, -1])
        npt.assert_equal(mplr.matrix_profile(), [1., 1., np.inf, np.inf])
        npt.assert_equal(mplr.profile_index(), [3, 0, -1, -1])

        for diag in range(-1, 4):
            mplr.process_diagonal(
                diag, np.atleast_2d(dm[2:, 2:][diag_indices(4, 4, diag)]))

        npt.assert_equal(mplr.matrix_profile_left, [2., 1, -3, -7])
        npt.assert_equal(mplr.profile_index_left, [1, 0, 4, 4])
        npt.assert_equal(mplr.matrix_profile_right, [1., -1, -4, np.inf])
        npt.assert_equal(mplr.profile_index_right, [3, 4, 5, -1])
        npt.assert_equal(mplr.matrix_profile(), [1., -1., -4, -7])
        npt.assert_equal(mplr.profile_index(), [3, 4, 5, 4])
示例#4
0
    def test_calculate_columns_with_series_and_query_shifting(self):
        dm = np.array([[2., 2., 3., 1., nan, nan], [4., 1., 2., 4., nan, nan],
                       [1., 3., 4., 2., -1., -5.], [3., 4., 1., 3., -2., -6.],
                       [nan, nan, nan, 8., -3., -7.],
                       [nan, nan, nan, 7., -4., 0.]])

        mplr = ShiftingMatrixProfileLR()
        mplr.initialise(1, 4, 4)

        for col in range(4):
            mplr.process_column(col, np.atleast_2d(dm[0:4, col]))

        npt.assert_equal(mplr.matrix_profile_left, [2., 1, 2., 1])
        npt.assert_equal(mplr.profile_index_left, [0, 1, 1, 0])
        npt.assert_equal(mplr.matrix_profile_right, [1., 3, 1., np.inf])
        npt.assert_equal(mplr.profile_index_right, [2, 2, 3, -1])
        npt.assert_equal(mplr.matrix_profile(), [1., 1., 1., 1.])
        npt.assert_equal(mplr.profile_index(), [2, 1, 3, 0])

        mplr.shift_query(2)
        mplr.shift_series(2)
        npt.assert_equal(mplr.matrix_profile_left, [2., 1, np.inf, np.inf])
        npt.assert_equal(mplr.profile_index_left, [1, 0, -1, -1])
        npt.assert_equal(mplr.matrix_profile_right,
                         [1., np.inf, np.inf, np.inf])
        npt.assert_equal(mplr.profile_index_right, [3, -1, -1, -1])
        npt.assert_equal(mplr.matrix_profile(), [1., 1., np.inf, np.inf])
        npt.assert_equal(mplr.profile_index(), [3, 0, -1, -1])

        mplr.process_column(1, np.atleast_2d(dm[2:6, 3]))
        mplr.process_column(2, np.atleast_2d(dm[2:6, 4]))
        mplr.process_column(3, np.atleast_2d(dm[2:6, 5]))

        npt.assert_equal(mplr.matrix_profile_left, [2., 1, -3, -7])
        npt.assert_equal(mplr.profile_index_left, [1, 0, 4, 4])
        npt.assert_equal(mplr.matrix_profile_right, [1., 7., -4, np.inf])
        npt.assert_equal(mplr.profile_index_right, [3, 5, 5, -1])
        npt.assert_equal(mplr.matrix_profile(), [1., 1., -4, -7])
        npt.assert_equal(mplr.profile_index(), [3, 0, 5, 4])