def __init__(self, key, window_sizes, series_window, results_folder): self.key = key self.dates = [] self.window_sizes = window_sizes self.series_window = series_window self.results_folder = results_folder self.number_of_values = 0 self.streamingCalculators = {} for m in window_sizes: calculator = StreamingCalculator(m, series_window) generator = calculator.add_generator(0, ZNormEuclidean(noise_std=0.)) consumer = calculator.add_consumer([0], ShiftingMatrixProfileLR()) self.streamingCalculators[m] = { 'calculator': calculator, 'consumer': consumer, 'resultsFile': results_folder + '/' + str(m) + '.txt' } self.openFiles()
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])
def test_calculate_columns_with_query_shifting(self): dm = np.array([[2., 1.], [0., 2.], [1., 3.], [3., 4.], [4., 0.], [2., 9.]]) mplr = ShiftingMatrixProfileLR() mplr.initialise(1, 4, 2) mplr.process_column(0, np.atleast_2d(dm[0:4, 0])) mplr.process_column(1, np.atleast_2d(dm[0:4, 1])) npt.assert_equal(mplr.matrix_profile_left, [2., 1.]) npt.assert_equal(mplr.profile_index_left, [0, 0]) npt.assert_equal(mplr.matrix_profile_right, [0., 3.]) npt.assert_equal(mplr.profile_index_right, [1, 2]) npt.assert_equal(mplr.matrix_profile(), [0., 1.]) npt.assert_equal(mplr.profile_index(), [1, 0]) mplr.shift_query(1) npt.assert_equal(mplr.matrix_profile_left, [2., 1.]) npt.assert_equal(mplr.profile_index_left, [0, 0]) npt.assert_equal(mplr.matrix_profile_right, [0., 3.]) npt.assert_equal(mplr.profile_index_right, [1, 2]) npt.assert_equal(mplr.matrix_profile(), [0., 1.]) npt.assert_equal(mplr.profile_index(), [1, 0]) mplr.process_column(0, np.atleast_2d(dm[1:5, 0])) mplr.process_column(1, np.atleast_2d(dm[1:5, 1])) npt.assert_equal(mplr.matrix_profile_left, [2., 1.]) npt.assert_equal(mplr.profile_index_left, [0, 0]) npt.assert_equal(mplr.matrix_profile_right, [0., 0.]) npt.assert_equal(mplr.profile_index_right, [1, 4]) npt.assert_equal(mplr.matrix_profile(), [0., 0.]) npt.assert_equal(mplr.profile_index(), [1, 4]) mplr.shift_query(1) mplr.process_column(0, np.atleast_2d(dm[2:6, 0])) mplr.process_column(1, np.atleast_2d(dm[2:6, 1])) npt.assert_equal(mplr.matrix_profile_left, [2., 1.]) npt.assert_equal(mplr.profile_index_left, [0, 0]) npt.assert_equal(mplr.matrix_profile_right, [0., 0.]) npt.assert_equal(mplr.profile_index_right, [1, 4]) npt.assert_equal(mplr.matrix_profile(), [0., 0.]) npt.assert_equal(mplr.profile_index(), [1, 4])
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])
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])
def setUp(self): # Needed to run all tests in TestMatrixProfileLR super().setUp() self.mplr = ShiftingMatrixProfileLR() self.mplr.initialise(1, self.dm.shape[0], self.dm.shape[1])
class TestShiftingMatrixProfileLR(TestMatrixProfileLR): def setUp(self): # Needed to run all tests in TestMatrixProfileLR super().setUp() self.mplr = ShiftingMatrixProfileLR() self.mplr.initialise(1, self.dm.shape[0], self.dm.shape[1]) 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]) 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]) def test_calculate_columns_with_query_shifting(self): dm = np.array([[2., 1.], [0., 2.], [1., 3.], [3., 4.], [4., 0.], [2., 9.]]) mplr = ShiftingMatrixProfileLR() mplr.initialise(1, 4, 2) mplr.process_column(0, np.atleast_2d(dm[0:4, 0])) mplr.process_column(1, np.atleast_2d(dm[0:4, 1])) npt.assert_equal(mplr.matrix_profile_left, [2., 1.]) npt.assert_equal(mplr.profile_index_left, [0, 0]) npt.assert_equal(mplr.matrix_profile_right, [0., 3.]) npt.assert_equal(mplr.profile_index_right, [1, 2]) npt.assert_equal(mplr.matrix_profile(), [0., 1.]) npt.assert_equal(mplr.profile_index(), [1, 0]) mplr.shift_query(1) npt.assert_equal(mplr.matrix_profile_left, [2., 1.]) npt.assert_equal(mplr.profile_index_left, [0, 0]) npt.assert_equal(mplr.matrix_profile_right, [0., 3.]) npt.assert_equal(mplr.profile_index_right, [1, 2]) npt.assert_equal(mplr.matrix_profile(), [0., 1.]) npt.assert_equal(mplr.profile_index(), [1, 0]) mplr.process_column(0, np.atleast_2d(dm[1:5, 0])) mplr.process_column(1, np.atleast_2d(dm[1:5, 1])) npt.assert_equal(mplr.matrix_profile_left, [2., 1.]) npt.assert_equal(mplr.profile_index_left, [0, 0]) npt.assert_equal(mplr.matrix_profile_right, [0., 0.]) npt.assert_equal(mplr.profile_index_right, [1, 4]) npt.assert_equal(mplr.matrix_profile(), [0., 0.]) npt.assert_equal(mplr.profile_index(), [1, 4]) mplr.shift_query(1) mplr.process_column(0, np.atleast_2d(dm[2:6, 0])) mplr.process_column(1, np.atleast_2d(dm[2:6, 1])) npt.assert_equal(mplr.matrix_profile_left, [2., 1.]) npt.assert_equal(mplr.profile_index_left, [0, 0]) npt.assert_equal(mplr.matrix_profile_right, [0., 0.]) npt.assert_equal(mplr.profile_index_right, [1, 4]) npt.assert_equal(mplr.matrix_profile(), [0., 0.]) npt.assert_equal(mplr.profile_index(), [1, 4]) 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])