def naive_idx_to_mp(I, T, m, normalize=True): I = I.astype(np.int64) T = T.copy() T_isfinite = np.isfinite(T) T_subseqs_isfinite = np.all(core.rolling_window(T_isfinite, m), axis=1) T[~T_isfinite] = 0.0 T_subseqs = core.rolling_window(T, m) nn_subseqs = T_subseqs[I] if normalize: P = naive.distance(naive.z_norm(T_subseqs, axis=1), naive.z_norm(nn_subseqs, axis=1), axis=1) else: P = naive.distance(T_subseqs, nn_subseqs, axis=1) P[~T_subseqs_isfinite] = np.inf P[I < 0] = np.inf return P
def test_stumpi_profile_index_match(): T_full = np.random.rand(64) m = 3 T_full_subseq = core.rolling_window(T_full, m) warm_start = 8 T_stream = T_full[:warm_start].copy() stream = stumpi(T_stream, m, egress=True) P = np.full(stream.P_.shape, np.inf) left_P = np.full(stream.left_P_.shape, np.inf) n = 0 for i in range(len(T_stream), len(T_full)): t = T_full[i] stream.update(t) P[:] = np.inf idx = np.argwhere(stream.I_ >= 0).flatten() P[idx] = naive.distance( naive.z_norm(T_full_subseq[idx + n + 1], axis=1), naive.z_norm(T_full_subseq[stream.I_[idx]], axis=1), axis=1, ) left_P[:] = np.inf idx = np.argwhere(stream.left_I_ >= 0).flatten() left_P[idx] = naive.distance( naive.z_norm(T_full_subseq[idx + n + 1], axis=1), naive.z_norm(T_full_subseq[stream.left_I_[idx]], axis=1), axis=1, ) npt.assert_almost_equal(stream.P_, P) npt.assert_almost_equal(stream.left_P_, left_P) n += 1