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])
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])