Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def naive_mass(Q, T, m, trivial_idx=None, excl_zone=0, ignore_trivial=False):
D = np.linalg.norm(
core.z_norm(core.rolling_window(T, m), 1) - core.z_norm(Q), axis=1
)
if ignore_trivial:
start = max(0, trivial_idx - excl_zone)
stop = min(T.shape[0] - Q.shape[0] + 1, trivial_idx + excl_zone)
D[start:stop] = np.inf
I = np.argmin(D)
P = D[I]
if P == np.inf:
I = -1
# Get left and right matrix profiles for self-joins
if ignore_trivial and trivial_idx > 0:
PL = np.inf
IL = -1
for i in range(trivial_idx):
def naive_mass(Q, T, m, trivial_idx=None, excl_zone=0, ignore_trivial=False):
D = np.linalg.norm(
core.z_norm(core.rolling_window(T, m), 1) - core.z_norm(Q), axis=1
)
if ignore_trivial:
start = max(0, trivial_idx - excl_zone)
stop = min(T.shape[0] - Q.shape[0] + 1, trivial_idx + excl_zone)
D[start:stop] = np.inf
I = np.argmin(D)
P = D[I]
if P == np.inf:
I = -1
# Get left and right matrix profiles for self-joins
if ignore_trivial and trivial_idx > 0:
PL = np.inf
IL = -1
for i in range(trivial_idx):
def naive_mass(Q, T, m, trivial_idx=None, excl_zone=0, ignore_trivial=False):
D = np.linalg.norm(
core.z_norm(core.rolling_window(T, m), 1) - core.z_norm(Q), axis=1
)
if ignore_trivial:
start = max(0, trivial_idx - excl_zone)
stop = min(T.shape[0] - Q.shape[0] + 1, trivial_idx + excl_zone)
D[start:stop] = np.inf
I = np.argmin(D)
P = D[I]
if P == np.inf:
I = -1
if ignore_trivial and trivial_idx > 0:
PL = np.inf
IL = -1
for i in range(trivial_idx):
if D[i] < PL:
def naive_mass(Q, T, m, trivial_idx, excl_zone):
D = np.linalg.norm(
core.z_norm(core.rolling_window(T, m), 1) - core.z_norm(Q), axis=1
)
start = max(0, trivial_idx - excl_zone)
stop = min(T.shape[0] - Q.shape[0] + 1, trivial_idx + excl_zone)
D[start:stop] = np.inf
return D
def naive_mass(Q, T, m, trivial_idx=None, excl_zone=0, ignore_trivial=False):
D = np.linalg.norm(
core.z_norm(core.rolling_window(T, m), 1) - core.z_norm(Q), axis=1
)
if ignore_trivial:
start = max(0, trivial_idx - excl_zone)
stop = min(T.shape[0] - Q.shape[0] + 1, trivial_idx + excl_zone)
D[start:stop] = np.inf
I = np.argmin(D)
P = D[I]
if P == np.inf:
I = -1
# Get left and right matrix profiles for self-joins
if ignore_trivial and trivial_idx > 0:
PL = np.inf
IL = -1
def naive_mstump(T, m):
zone = int(np.ceil(m / 4))
Q = core.rolling_window(T, m)
D = np.empty((Q.shape[0], Q.shape[1]))
P = np.full((Q.shape[0], Q.shape[1]), np.inf)
I = np.ones((Q.shape[0], Q.shape[1]), dtype="int64") * -1
# Left
for i in range(Q.shape[1]):
D[:] = 0.0
for dim in range(T.shape[0]):
D[dim] = naive_mass(Q[dim, i], T[dim], m, i, zone)
P_i, I_i = naive_PI(D, i)
for dim in range(T.shape[0]):
col_mask = P[dim] > P_i[dim]
P[dim, col_mask] = P_i[dim, col_mask]
I[dim, col_mask] = I_i[dim, col_mask]
old_data = np.asarray(old_data)
add_data = np.asarray(add_data)
concat_data = np.concatenate((old_data, add_data))
# Disable the bidirectional matrix profile indices and left indices
mp_out[:, 1] = -1
mp_out[:, 2] = -1
# Update matrix profile distance to be right mp distance and not bidirectional.
# Use right indices to perform direct distance calculations
# Note that any -1 indices must have a np.inf matrix profile value
right_indices = [np.arange(IR, IR + m) for IR in mp_out[:, 3].tolist()]
right_nn[:] = old_data[np.array(right_indices)]
mp_out[:, 0] = np.linalg.norm(
core.z_norm(core.rolling_window(old_data, m), 1) - core.z_norm(right_nn, 1),
axis=1,
)
inf_indices = np.argwhere(mp_out[:, 3] < 0).flatten()
mp_out[inf_indices, 0] = np.inf
mp_out[inf_indices, 3] = inf_indices
rolling_Qs = core.rolling_window(concat_data[k:], m)
rolling_Ts = core.rolling_window(concat_data[1:], n)
M_T = np.zeros(n - m + 1)
Σ_T = np.zeros(n - m + 1)
D = np.zeros(n - m + 1)
excl_zone = int(np.ceil(m / 4))
# Note that the start of the exclusion zone is relative to
# the unchanging length of the matrix profile index
zone_start = max(0, k - excl_zone)