MCPcopy
hub / github.com/stumpy-dev/stumpy / scraamp

Function scraamp

tests/naive.py:2049–2112  ·  view source on GitHub ↗
(T_A, m, T_B, percentage, exclusion_zone, pre_scraamp, s, p=2.0, k=1)

Source from the content-addressed store, hash-verified

2047
2048
2049def scraamp(T_A, m, T_B, percentage, exclusion_zone, pre_scraamp, s, p=2.0, k=1):
2050 distance_matrix = aamp_distance_matrix(T_A, T_B, m, p)
2051
2052 n_A = T_A.shape[0]
2053 n_B = T_B.shape[0]
2054 l = n_A - m + 1
2055
2056 if exclusion_zone is not None:
2057 diags = np.random.permutation(range(exclusion_zone + 1, n_A - m + 1)).astype(
2058 np.int64
2059 )
2060 else:
2061 diags = np.random.permutation(range(-(n_A - m + 1) + 1, n_B - m + 1)).astype(
2062 np.int64
2063 )
2064
2065 n_chunks = int(np.ceil(1.0 / percentage))
2066 ndist_counts = core._count_diagonal_ndist(diags, m, n_A, n_B)
2067 diags_ranges = core._get_array_ranges(ndist_counts, n_chunks, False)
2068 diags_ranges_start = diags_ranges[0, 0]
2069 diags_ranges_stop = diags_ranges[0, 1]
2070
2071 P = np.full((l, k), np.inf, dtype=np.float64) # Topk
2072 PL = np.full(l, np.inf, dtype=np.float64)
2073 PR = np.full(l, np.inf, dtype=np.float64)
2074
2075 I = np.full((l, k), -1, dtype=np.int64)
2076 IL = np.full(l, -1, dtype=np.int64)
2077 IR = np.full(l, -1, dtype=np.int64)
2078
2079 for diag_idx in range(diags_ranges_start, diags_ranges_stop):
2080 g = diags[diag_idx]
2081
2082 for i in range(n_A - m + 1):
2083 for j in range(n_B - m + 1):
2084 if j - i == g:
2085 d = distance_matrix[i, j]
2086 if d < P[i, -1]:
2087 idx = searchsorted_right(P[i], d)
2088 if (i + g) not in I[i]:
2089 P[i] = np.insert(P[i], idx, d)[:-1]
2090 I[i] = np.insert(I[i], idx, i + g)[:-1]
2091
2092 if exclusion_zone is not None and d < P[i + g, -1]:
2093 idx = searchsorted_right(P[i + g], d)
2094 if i not in I[i + g]:
2095 P[i + g] = np.insert(P[i + g], idx, d)[:-1]
2096 I[i + g] = np.insert(I[i + g], idx, i)[:-1]
2097
2098 # left matrix profile and left matrix profile indices
2099 if exclusion_zone is not None and i < i + g and d < PL[i + g]:
2100 PL[i + g] = d
2101 IL[i + g] = i
2102
2103 # right matrix profile and right matrix profile indices
2104 if exclusion_zone is not None and i + g > i and d < PR[i]:
2105 PR[i] = d
2106 IR[i] = i + g

Callers

nothing calls this directly

Calls 2

aamp_distance_matrixFunction · 0.85
searchsorted_rightFunction · 0.85

Tested by

no test coverage detected