def test_process_column_lr(self): l_dist_matrix = self.dist_matrix.copy() r_dist_matrix = self.dist_matrix.copy() mmp = MultidimensionalMatrixProfileLR() self.mock_initialise(mmp) for diag in range(-self.dist_matrix.shape[1] + 1, self.dist_matrix.shape[2]): diag_ind = diag_indices_of(self.dist_matrix[0], diag) if diag < 0: l_dist_matrix[:, diag_ind[0], diag_ind[1]] = np.inf else: r_dist_matrix[:, diag_ind[0], diag_ind[1]] = np.inf for column in range(self.dist_matrix.shape[2]): mmp.process_column(column, self.dist_matrix[:, :, column]) correct_lmp, correct_lindex, correct_ldims = self.bruteforce_mmp( l_dist_matrix) correct_rmp, correct_rindex, correct_rdims = self.bruteforce_mmp( r_dist_matrix) npt.assert_allclose(mmp.md_matrix_profile_left, correct_lmp) npt.assert_allclose(mmp.md_matrix_profile_right, correct_rmp) npt.assert_equal(mmp.md_profile_index_left, correct_lindex) npt.assert_equal(mmp.md_profile_index_right, correct_rindex) for i, dims in enumerate(correct_ldims): sorted_mmp_ldims = np.sort(mmp.md_profile_dimension_left[i], axis=0) sorted_mmp_rdims = np.sort(mmp.md_profile_dimension_right[i], axis=0) npt.assert_equal(sorted_mmp_ldims, correct_ldims[i]) npt.assert_equal(sorted_mmp_rdims, correct_rdims[i])
def test_process_column(self): mmp = MultidimensionalMatrixProfileLR() self.mock_initialise(mmp) for column in range(0, self.dist_matrix.shape[2]): mmp.process_column(column, self.dist_matrix[:, :, column]) correct_mp, correct_index, correct_dims = self.bruteforce_mmp( self.dist_matrix) npt.assert_allclose(mmp.md_matrix_profile(), correct_mp) npt.assert_equal(mmp.md_profile_index(), correct_index) for i, dims in enumerate(correct_dims): sorted_mmp_dims = np.sort(mmp.md_profile_dimensions()[i], axis=0) npt.assert_equal(sorted_mmp_dims, dims)
def test_process_column_partial_calculation(self): part_dist_matrix = np.full_like(self.dist_matrix, np.inf) mmp = MultidimensionalMatrixProfileLR() self.mock_initialise(mmp) for column in [0, 3, 4, 6, 9, 12, 13]: mmp.process_column(column, self.dist_matrix[:, :, column]) part_dist_matrix[:, :, column] = self.dist_matrix[:, :, column] correct_mp, correct_index, correct_dims = self.bruteforce_mmp( part_dist_matrix) npt.assert_allclose(mmp.md_matrix_profile(), correct_mp) npt.assert_equal(mmp.md_profile_index(), correct_index) for i, dims in enumerate(correct_dims): sorted_mmp_dims = np.sort(mmp.md_profile_dimensions()[i], axis=0) npt.assert_equal(sorted_mmp_dims, dims)
def test_process_diagonal(self): mmp = MultidimensionalMatrixProfileLR() self.mock_initialise(mmp) for diag in range(-self.dist_matrix.shape[1] + 1, self.dist_matrix.shape[2]): diag_ind = diag_indices_of(self.dist_matrix[0], diag) mmp.process_diagonal(diag, self.dist_matrix[:, diag_ind[0], diag_ind[1]]) correct_mp, correct_index, correct_dims = self.bruteforce_mmp( self.dist_matrix) npt.assert_allclose(mmp.md_matrix_profile(), correct_mp) npt.assert_equal(mmp.md_profile_index(), correct_index) for i, dims in enumerate(correct_dims): sorted_mmp_dims = np.sort(mmp.md_profile_dimensions()[i], axis=0) npt.assert_equal(sorted_mmp_dims, dims)
def test_streaming_process_diagonal(self): mmp = MultidimensionalMatrixProfileLR() mmp.initialise(3, 5, 7) available_data = np.full((3, 5, 7), np.inf) a = self.dist_matrix[:, 0:5, 0:7] available_data[diag3(available_data, 0)] = a[diag3(a, 0)] available_data[diag3(available_data, 4)] = a[diag3(a, 4)] available_data[diag3(available_data, -3)] = a[diag3(a, -3)] mmp.process_diagonal(0, a[diag3(a, 0)]) mmp.process_diagonal(4, a[diag3(a, 4)]) mmp.process_diagonal(-3, a[diag3(a, -3)]) correct_mp, correct_index, correct_dims = self.bruteforce_mmp( available_data) npt.assert_allclose(mmp.md_matrix_profile(), correct_mp) npt.assert_equal(mmp.md_profile_index(), correct_index) for i, dims in enumerate(correct_dims): sorted_mmp_dims = np.sort(mmp.md_profile_dimensions()[i], axis=0) npt.assert_equal(sorted_mmp_dims, dims) mmp.shift_series(3) mmp.shift_query(2) available_data = np.full((3, 7, 10), np.inf) a_win = available_data[:, 0:5, 0:7] a = self.dist_matrix[:, 0:5, 0:7] a_win[diag3(a_win, 0)] = a[diag3(a, 0)] a_win[diag3(a_win, 4)] = a[diag3(a, 4)] a_win[diag3(a_win, -3)] = a[diag3(a, -3)] correct_mp, correct_index, correct_dims = self.bruteforce_mmp( available_data) npt.assert_allclose(mmp.md_matrix_profile(), correct_mp[:, 3:]) npt.assert_equal(mmp.md_profile_index(), correct_index[:, 3:]) for i, dims in enumerate(correct_dims): sorted_mmp_dims = np.sort(mmp.md_profile_dimensions()[i], axis=0) npt.assert_equal(sorted_mmp_dims, dims[:, 3:]) a_win = available_data[:, 2:7, 3:10] a = self.dist_matrix[:, 2:7, 3:10] a_win[diag3(a_win, -1)] = a[diag3(a, -1)] # Old diag 0 a_win[diag3(a_win, 3)] = a[diag3(a, 3)] # Old diag 4 a_win[diag3(a_win, -4)] = a[diag3(a, -4)] # Old diag -3 a_win[diag3(a_win, 2)] = a[diag3(a, 2)] mmp.process_diagonal(-1, a[diag3(a, -1)]) mmp.process_diagonal(3, a[diag3(a, 3)]) mmp.process_diagonal(-4, a[diag3(a, -4)]) mmp.process_diagonal(2, a[diag3(a, 2)]) correct_mp, correct_index, correct_dims = self.bruteforce_mmp( available_data) npt.assert_allclose(mmp.md_matrix_profile(), correct_mp[:, 3:]) npt.assert_equal(mmp.md_profile_index(), correct_index[:, 3:]) for i, dims in enumerate(correct_dims): sorted_mmp_dims = np.sort(mmp.md_profile_dimensions()[i], axis=0) npt.assert_equal(sorted_mmp_dims, dims[:, 3:])
def test_streaming_process_column(self): mmp = MultidimensionalMatrixProfileLR() mmp.initialise(3, 5, 7) available_data = np.full((3, 5, 7), np.inf) available_data[:, 0:5, 0] = self.dist_matrix[:, 0:5, 0] available_data[:, 0:5, 4] = self.dist_matrix[:, 0:5, 4] available_data[:, 0:5, 5] = self.dist_matrix[:, 0:5, 5] mmp.process_column(0, self.dist_matrix[:, 0:5, 0]) mmp.process_column(4, self.dist_matrix[:, 0:5, 4]) mmp.process_column(5, self.dist_matrix[:, 0:5, 5]) correct_mp, correct_index, correct_dims = self.bruteforce_mmp( available_data) npt.assert_allclose(mmp.md_matrix_profile(), correct_mp) npt.assert_equal(mmp.md_profile_index(), correct_index) for i, dims in enumerate(correct_dims): sorted_mmp_dims = np.sort(mmp.md_profile_dimensions()[i], axis=0) npt.assert_equal(sorted_mmp_dims, dims) mmp.shift_series(2) mmp.shift_query(3) available_data = np.full((3, 8, 9), np.inf) available_data[:, 0:5, 4] = self.dist_matrix[:, 0:5, 4] available_data[:, 0:5, 5] = self.dist_matrix[:, 0:5, 5] correct_mp, correct_index, correct_dims = self.bruteforce_mmp( available_data) npt.assert_allclose(mmp.md_matrix_profile(), correct_mp[:, 2:]) npt.assert_equal(mmp.md_profile_index(), correct_index[:, 2:]) for i, dims in enumerate(correct_dims): sorted_mmp_dims = np.sort(mmp.md_profile_dimensions()[i], axis=0) npt.assert_equal(sorted_mmp_dims, dims[:, 2:]) mmp.process_column(0, self.dist_matrix[:, 3:8, 2]) mmp.process_column(2, self.dist_matrix[:, 3:8, 4]) mmp.process_column(3, self.dist_matrix[:, 3:8, 5]) mmp.process_column(5, self.dist_matrix[:, 3:8, 7]) available_data[:, 3:8, 2] = self.dist_matrix[:, 3:8, 2] available_data[:, 3:8, 4] = self.dist_matrix[:, 3:8, 4] available_data[:, 3:8, 5] = self.dist_matrix[:, 3:8, 5] available_data[:, 3:8, 7] = self.dist_matrix[:, 3:8, 7] correct_mp, correct_index, correct_dims = self.bruteforce_mmp( available_data) npt.assert_allclose(mmp.md_matrix_profile(), correct_mp[:, 2:]) npt.assert_equal(mmp.md_profile_index(), correct_index[:, 2:]) for i, dims in enumerate(correct_dims): sorted_mmp_dims = np.sort(mmp.md_profile_dimensions()[i], axis=0) npt.assert_equal(sorted_mmp_dims, dims[:, 2:])