Пример #1
0
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
Пример #2
0
def test_mass_distance_matrix(T_A, T_B):
    m = 3

    ref_distance_matrix = naive.distance_matrix(T_A, T_B, m)
    k = T_A.shape[0] - m + 1
    l = T_B.shape[0] - m + 1
    comp_distance_matrix = np.full((k, l), np.inf)
    core._mass_distance_matrix(T_A, T_B, m, comp_distance_matrix)

    npt.assert_almost_equal(ref_distance_matrix, comp_distance_matrix)
Пример #3
0
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_B - m + 1

    if exclusion_zone is not None:
        orders = np.random.permutation(range(exclusion_zone + 1, n_B - m + 1))
    else:
        orders = np.random.permutation(range(-(n_B - m + 1) + 1, n_A - m + 1))

    orders_ranges = naive_get_orders_ranges(1, m, n_A, n_B, orders, 0,
                                            percentage)
    orders_ranges_start = orders_ranges[0][0]
    orders_ranges_stop = orders_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 order_idx in range(orders_ranges_start, orders_ranges_stop):
        k = orders[order_idx]

        for i in range(n_B - m + 1):
            for j in range(n_A - 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
Пример #4
0
def naive_prescrump(T_A, m, T_B, s, exclusion_zone=None):
    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

    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)
        I[i] = np.argmin(distance_profile)
        P[i] = distance_profile[I[i]]
        if P[i] == np.inf:
            I[i] = -1

        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
Пример #5
0
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_B - m + 1

    if exclusion_zone is not None:
        orders = np.random.permutation(range(exclusion_zone + 1, n_B - m + 1))
    else:
        orders = np.random.permutation(range(-(n_B - m + 1) + 1, n_A - m + 1))

    orders_ranges = naive_get_orders_ranges(1, m, n_A, n_B, orders, 0, percentage)
    orders_ranges_start = orders_ranges[0][0]
    orders_ranges_stop = orders_ranges[0][1]

    out = np.full((l, 2), np.inf, dtype=object)
    out[:, 1] = -1

    for order_idx in range(orders_ranges_start, orders_ranges_stop):
        k = orders[order_idx]

        for i in range(n_B - m + 1):
            for j in range(n_A - 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

    return out