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

Function stump

tests/naive.py:225–344  ·  view source on GitHub ↗

Traverse distance matrix diagonally and update the top-k matrix profile and matrix profile indices if the parameter `row_wise` is set to `False`. If the parameter `row_wise` is set to `True`, it is a row-wise traversal.

(
    T_A,
    m,
    T_B=None,
    exclusion_zone=None,
    row_wise=False,
    k=1,
    T_A_subseq_isconstant=None,
    T_B_subseq_isconstant=None,
)

Source from the content-addressed store, hash-verified

223
224
225def stump(
226 T_A,
227 m,
228 T_B=None,
229 exclusion_zone=None,
230 row_wise=False,
231 k=1,
232 T_A_subseq_isconstant=None,
233 T_B_subseq_isconstant=None,
234):
235 """
236 Traverse distance matrix diagonally and update the top-k matrix profile and
237 matrix profile indices if the parameter `row_wise` is set to `False`. If the
238 parameter `row_wise` is set to `True`, it is a row-wise traversal.
239 """
240 if T_B is None: # self-join:
241 ignore_trivial = True
242 distance_matrix = np.array(
243 [distance_profile(Q, T_A, m) for Q in core.rolling_window(T_A, m)]
244 )
245 T_B = T_A.copy()
246 T_B_subseq_isconstant = T_A_subseq_isconstant
247 else:
248 ignore_trivial = False
249 distance_matrix = np.array(
250 [distance_profile(Q, T_B, m) for Q in core.rolling_window(T_A, m)]
251 )
252
253 T_A_subseq_isconstant = rolling_isconstant(T_A, m, T_A_subseq_isconstant)
254 T_B_subseq_isconstant = rolling_isconstant(T_B, m, T_B_subseq_isconstant)
255
256 distance_matrix[np.isnan(distance_matrix)] = np.inf
257 for i in range(distance_matrix.shape[0]):
258 for j in range(distance_matrix.shape[1]):
259 if np.isfinite(distance_matrix[i, j]):
260 if T_A_subseq_isconstant[i] and T_B_subseq_isconstant[j]:
261 distance_matrix[i, j] = 0.0
262 elif T_A_subseq_isconstant[i] or T_B_subseq_isconstant[j]:
263 distance_matrix[i, j] = np.sqrt(m)
264 else: # pragma: no cover
265 pass
266
267 n_A = T_A.shape[0]
268 n_B = T_B.shape[0]
269 l = n_A - m + 1
270 if exclusion_zone is None:
271 exclusion_zone = int(np.ceil(m / config.STUMPY_EXCL_ZONE_DENOM))
272
273 P = np.full((l, k + 2), np.inf, dtype=np.float64)
274 I = np.full((l, k + 2), -1, dtype=np.int64) # two more columns are to store
275 # ... left and right top-1 matrix profile indices
276
277 if row_wise: # row-wise traversal in distance matrix
278 if ignore_trivial: # self-join
279 for i in range(l):
280 apply_exclusion_zone(distance_matrix[i], i, exclusion_zone, np.inf)
281
282 for i, D in enumerate(distance_matrix): # D: distance profile

Callers 4

__init__Method · 0.70
consensus_searchFunction · 0.70
mpdist_vectFunction · 0.70
mpdistFunction · 0.70

Calls 4

distance_profileFunction · 0.85
searchsorted_rightFunction · 0.85
rolling_isconstantFunction · 0.70
apply_exclusion_zoneFunction · 0.70

Tested by

no test coverage detected