def test_apply_exclusion_zone(): T = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=float) left = np.empty(T.shape) right = np.empty(T.shape) exclusion_zone = 2 for i in range(T.shape[0]): left[:] = T[:] naive.apply_exclusion_zone(left, i, exclusion_zone) right[:] = T[:] core.apply_exclusion_zone(right, i, exclusion_zone) naive.replace_inf(left) naive.replace_inf(right) npt.assert_array_equal(left, right)
def test_apply_exclusion_zone(): T = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=float) ref = np.empty(T.shape) comp = np.empty(T.shape) exclusion_zone = 2 for i in range(T.shape[0]): ref[:] = T[:] naive.apply_exclusion_zone(ref, i, exclusion_zone) comp[:] = T[:] core.apply_exclusion_zone(comp, i, exclusion_zone) naive.replace_inf(ref) naive.replace_inf(comp) npt.assert_array_equal(ref, comp)
def test_apply_exclusion_zone_bool(): T = np.ones(10, dtype=bool) ref = np.empty(T.shape, dtype=bool) comp = np.empty(T.shape, dtype=bool) exclusion_zone = 2 for i in range(T.shape[0]): ref[:] = T[:] naive.apply_exclusion_zone(ref, i, exclusion_zone, False) comp[:] = T[:] core.apply_exclusion_zone(comp, i, exclusion_zone, False) naive.replace_inf(ref) naive.replace_inf(comp) npt.assert_array_equal(ref, comp)
def test_apply_exclusion_zone_multidimensional(): T = np.array( [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], dtype=np.float64, ) ref = np.empty(T.shape, dtype=np.float64) comp = np.empty(T.shape, dtype=np.float64) exclusion_zone = 2 for i in range(T.shape[1]): ref[:, :] = T[:, :] naive.apply_exclusion_zone(ref, i, exclusion_zone, np.inf) comp[:, :] = T[:, :] core.apply_exclusion_zone(comp, i, exclusion_zone, np.inf) naive.replace_inf(ref) naive.replace_inf(comp) npt.assert_array_equal(ref, comp)
def naive_prescraamp(T_A, m, T_B, s, exclusion_zone=None): distance_matrix = naive.aamp_distance_matrix(T_A, T_B, m) n_A = T_A.shape[0] l = n_A - m + 1 P = np.empty(l) I = np.empty(l, dtype=np.int64) P[:] = np.inf I[:] = -1 for i in np.random.permutation(range(0, l, s)): distance_profile = distance_matrix[i] if exclusion_zone is not None: naive.apply_exclusion_zone(distance_profile, i, exclusion_zone, np.inf) I[i] = np.argmin(distance_profile) P[i] = distance_profile[I[i]] if P[i] == np.inf: I[i] = -1 else: j = I[i] for k in range(1, min(s, l - max(i, j))): d = distance_matrix[i + k, j + k] if d < P[i + k]: P[i + k] = d I[i + k] = j + k if d < P[j + k]: P[j + k] = d I[j + k] = i + k for k in range(1, min(s, i + 1, j + 1)): d = distance_matrix[i - k, j - k] if d < P[i - k]: P[i - k] = d I[i - k] = j - k if d < P[j - k]: P[j - k] = d I[j - k] = i - k return P, I