def test_get_array_ranges(): x = np.array([3, 9, 2, 1, 5, 4, 7, 7, 8, 6]) for n_chunks in range(2, 5): left = naive.get_array_ranges(x, n_chunks) right = core._get_array_ranges(x, n_chunks) npt.assert_almost_equal(left, right)
def test_get_array_ranges(): x = np.array([3, 9, 2, 1, 5, 4, 7, 7, 8, 6]) for n_chunks in range(2, 5): ref = naive.get_array_ranges(x, n_chunks) comp = core._get_array_ranges(x, n_chunks) npt.assert_almost_equal(ref, comp)
def test_get_array_ranges(): x = np.array([3, 9, 2, 1, 5, 4, 7, 7, 8, 6], dtype=np.int64) for n_chunks in range(2, 5): ref = naive.get_array_ranges(x, n_chunks, False) cmp = core._get_array_ranges(x, n_chunks, False) npt.assert_almost_equal(ref, cmp)
def naive_scrump(T_A, m, T_B, percentage, exclusion_zone, pre_scrump, s): distance_matrix = naive.distance_matrix(T_A, T_B, m) n_A = T_A.shape[0] n_B = T_B.shape[0] l = n_A - m + 1 if exclusion_zone is not None: diags = np.random.permutation(range(exclusion_zone + 1, n_A - m + 1)) else: diags = np.random.permutation(range(-(n_A - m + 1) + 1, n_B - m + 1)) n_chunks = int(np.ceil(1.0 / percentage)) ndist_counts = core._count_diagonal_ndist(diags, m, n_A, n_B) diags_ranges = core._get_array_ranges(ndist_counts, n_chunks) diags_ranges_start = diags_ranges[0, 0] diags_ranges_stop = diags_ranges[0, 1] out = np.full((l, 4), np.inf, dtype=object) out[:, 1:] = -1 left_P = np.full(l, np.inf, dtype=np.float64) right_P = np.full(l, np.inf, dtype=np.float64) for diag_idx in range(diags_ranges_start, diags_ranges_stop): k = diags[diag_idx] for i in range(n_A - m + 1): for j in range(n_B - m + 1): if j - i == k: if distance_matrix[i, j] < out[i, 0]: out[i, 0] = distance_matrix[i, j] out[i, 1] = i + k if ( exclusion_zone is not None and distance_matrix[i, j] < out[i + k, 0] ): out[i + k, 0] = distance_matrix[i, j] out[i + k, 1] = i # left matrix profile and left matrix profile indices if ( exclusion_zone is not None and i < i + k and distance_matrix[i, j] < left_P[i + k] ): left_P[i + k] = distance_matrix[i, j] out[i + k, 2] = i # right matrix profile and right matrix profile indices if ( exclusion_zone is not None and i + k > i and distance_matrix[i, j] < right_P[i] ): right_P[i] = distance_matrix[i, j] out[i, 3] = i + k return out
def test_get_array_ranges_exhausted_truncated(): x = np.array([3, 3, 3, 11, 11, 11]) n_chunks = 6 left = naive.get_array_ranges(x, n_chunks, truncate=True) right = core._get_array_ranges(x, n_chunks, truncate=True) npt.assert_almost_equal(left, right)
def test_get_array_ranges_exhausted_truncated(): x = np.array([3, 3, 3, 11, 11, 11]) n_chunks = 6 ref = naive.get_array_ranges(x, n_chunks, truncate=True) comp = core._get_array_ranges(x, n_chunks, truncate=True) npt.assert_almost_equal(ref, comp)
def test_get_array_ranges_empty_array(): x = np.array([], dtype=np.int64) n_chunks = 6 ref = naive.get_array_ranges(x, n_chunks, False) comp = core._get_array_ranges(x, n_chunks, False) npt.assert_almost_equal(ref, comp)
def test_get_array_ranges_exhausted(): x = np.array([3, 3, 3, 11, 11, 11]) n_chunks = 6 left = utils.get_naive_array_ranges(x, n_chunks) right = core._get_array_ranges(x, n_chunks) npt.assert_almost_equal(left, right)
def test_get_array_ranges_exhausted(): x = np.array([3, 3, 3, 11, 11, 11], dtype=np.int64) n_chunks = 6 ref = naive.get_array_ranges(x, n_chunks, False) cmp = core._get_array_ranges(x, n_chunks, False) npt.assert_almost_equal(ref, cmp)