Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_calculate_distance_profile(Q, T):
m = Q.shape[0]
left = np.linalg.norm(
core.z_norm(core.rolling_window(T, m), 1) - core.z_norm(Q), axis=1
)
QT = core.sliding_dot_product(Q, T)
μ_Q, σ_Q = core.compute_mean_std(Q, m)
M_T, Σ_T = core.compute_mean_std(T, m)
right = core.calculate_distance_profile(m, QT, μ_Q, σ_Q, M_T, Σ_T)
npt.assert_almost_equal(left, right)
def test_calculate_squared_distance_profile(Q, T):
m = Q.shape[0]
left = np.linalg.norm(
core.z_norm(core.rolling_window(T, m), 1) - core.z_norm(Q), axis=1
)
left = np.square(left)
M_T, Σ_T = core.compute_mean_std(T, m)
QT = core.sliding_dot_product(Q, T)
μ_Q, σ_Q = core.compute_mean_std(Q, m)
right = _calculate_squared_distance_profile(m, QT, μ_Q[0], σ_Q[0], M_T, Σ_T)
npt.assert_almost_equal(left, right)
of interest
m : int
Window size
Returns
-------
QT : ndarray
Given `start`, return the corresponding QT
QT_first : ndarray
QT for the first window
"""
QT = core.sliding_dot_product(T_B[start : start + m], T_A)
QT_first = core.sliding_dot_product(T_A[:m], T_B)
return QT, QT_first
core.check_nan(T_B)
core.check_window_size(m)
if ignore_trivial is False and core.are_arrays_equal(T_A, T_B): # pragma: no cover
logger.warning("Arrays T_A, T_B are equal, which implies a self-join.")
logger.warning("Try setting `ignore_trivial = True`.")
if ignore_trivial and core.are_arrays_equal(T_A, T_B) is False: # pragma: no cover
logger.warning("Arrays T_A, T_B are not equal, which implies an AB-join.")
logger.warning("Try setting `ignore_trivial = False`.")
n = T_B.shape[0]
l = n - m + 1
excl_zone = int(np.ceil(m / 4)) # See Definition 3 and Figure 3
M_T, Σ_T = core.compute_mean_std(T_A, m)
QT = core.sliding_dot_product(T_B[:m], T_A)
QT_first = core.sliding_dot_product(T_A[:m], T_B)
μ_Q, σ_Q = core.compute_mean_std(T_B, m)
out = np.empty((l, 4), dtype=object)
# Handle first subsequence, add exclusionary zone
if ignore_trivial:
P, I = stamp.mass(T_B[:m], T_A, M_T, Σ_T, 0, excl_zone)
PR, IR = stamp.mass(T_B[:m], T_A, M_T, Σ_T, 0, excl_zone, right=True)
else:
P, I = stamp.mass(T_B[:m], T_A, M_T, Σ_T)
IR = -1 # No left and right matrix profile available
out[0] = P, I, -1, IR
k = T_A.shape[0] - m + 1
-------
QT : ndarray
Given `start`, return the corresponding multi-dimensional QT
QT_first : ndarray
Multi-dimensional QT for the first window
"""
d = T.shape[0]
k = T.shape[1] - m + 1
QT = np.empty((d, k), dtype="float64")
QT_first = np.empty((d, k), dtype="float64")
for i in range(d):
QT[i] = core.sliding_dot_product(T[i, start : start + m], T[i])
QT_first[i] = core.sliding_dot_product(T[i, :m], T[i])
return QT, QT_first
core.check_window_size(m)
if ignore_trivial is False and core.are_arrays_equal(T_A, T_B): # pragma: no cover
logger.warning("Arrays T_A, T_B are equal, which implies a self-join.")
logger.warning("Try setting `ignore_trivial = True`.")
if ignore_trivial and core.are_arrays_equal(T_A, T_B) is False: # pragma: no cover
logger.warning("Arrays T_A, T_B are not equal, which implies an AB-join.")
logger.warning("Try setting `ignore_trivial = False`.")
n = T_B.shape[0]
l = n - m + 1
excl_zone = int(np.ceil(m / 4)) # See Definition 3 and Figure 3
M_T, Σ_T = core.compute_mean_std(T_A, m)
QT = core.sliding_dot_product(T_B[:m], T_A)
QT_first = core.sliding_dot_product(T_A[:m], T_B)
μ_Q, σ_Q = core.compute_mean_std(T_B, m)
out = np.empty((l, 4), dtype=object)
# Handle first subsequence, add exclusionary zone
if ignore_trivial:
P, I = stamp.mass(T_B[:m], T_A, M_T, Σ_T, 0, excl_zone)
PR, IR = stamp.mass(T_B[:m], T_A, M_T, Σ_T, 0, excl_zone, right=True)
else:
P, I = stamp.mass(T_B[:m], T_A, M_T, Σ_T)
IR = -1 # No left and right matrix profile available
out[0] = P, I, -1, IR
k = T_A.shape[0] - m + 1
for i in range(1, l):
The time series or sequence that contain your query subsequence
of interest
m : int
Window size
Returns
-------
QT : ndarray
Given `start`, return the corresponding QT
QT_first : ndarray
QT for the first window
"""
QT = core.sliding_dot_product(T_B[start : start + m], T_A)
QT_first = core.sliding_dot_product(T_A[:m], T_B)
return QT, QT_first