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_check_window_size():
for m in range(-1, 3):
with pytest.raises(ValueError):
core.check_window_size(m)
`DOI: 10.1109/ICDM.2017.66 \
`__
See mSTAMP Algorithm
"""
T = np.asarray(core.transpose_dataframe(T))
if T.ndim <= 1: # pragma: no cover
err = f"T is {T.ndim}-dimensional and must be greater than 1-dimensional"
raise ValueError(f"{err}")
core.check_dtype(T)
core.check_nan(T)
core.check_window_size(m)
d = T.shape[0]
n = T.shape[1]
k = n - m + 1
excl_zone = int(np.ceil(m / 4)) # See Definition 3 and Figure 3
M_T, Σ_T = _multi_compute_mean_std(T, m)
μ_Q, σ_Q = _multi_compute_mean_std(T, m)
P = np.full((d, k), np.inf, dtype="float64")
D = np.zeros((d, k), dtype="float64")
D_prime = np.zeros(k, dtype="float64")
I = np.ones((d, k), dtype="int64") * -1
start = 0
stop = k
See Table III
Timeseries, T_B, will be annotated with the distance location
(or index) of all its subsequences in another times series, T_A.
For every subsequence, Q, in T_B, you will get a distance and index for
the closest subsequence in T_A. Thus, the array returned will have length
T_B.shape[0]-m+1
"""
core.check_dtype(T_A)
core.check_nan(T_A)
core.check_dtype(T_B)
core.check_nan(T_B)
core.check_window_size(m)
subseq_T_B = core.rolling_window(T_B, m)
excl_zone = int(np.ceil(m / 2))
M_T, Σ_T = core.compute_mean_std(T_A, m)
# Add exclusionary zone
if ignore_trivial:
out = [
mass(subseq, T_A, M_T, Σ_T, i, excl_zone)
for i, subseq in enumerate(subseq_T_B)
]
else:
out = [mass(subseq, T_A, M_T, Σ_T) for subseq in subseq_T_B]
out = np.array(out, dtype=object)
return out
See mSTAMP Algorithm
"""
hosts = list(dask_client.ncores().keys())
nworkers = len(hosts)
T = np.asarray(core.transpose_dataframe(T))
if T.ndim <= 1: # pragma: no cover
err = f"T is {T.ndim}-dimensional and must be greater than 1-dimensional"
raise ValueError(f"{err}")
core.check_dtype(T)
core.check_nan(T)
core.check_window_size(m)
d = T.shape[0]
n = T.shape[1]
k = n - m + 1
excl_zone = int(np.ceil(m / 4)) # See Definition 3 and Figure 3
M_T, Σ_T = _multi_compute_mean_std(T, m)
μ_Q, σ_Q = _multi_compute_mean_std(T, m)
P = np.empty((nworkers, d, k), dtype="float64")
D = np.zeros((nworkers, d, k), dtype="float64")
D_prime = np.zeros((nworkers, k), dtype="float64")
I = np.ones((nworkers, d, k), dtype="int64") * -1
# Scatter data to Dask cluster
T_future = dask_client.scatter(T, broadcast=True)
T_B = np.asarray(T_B)
if T_A.ndim != 1: # pragma: no cover
raise ValueError(
f"T_A is {T_A.ndim}-dimensional and must be 1-dimensional. "
"For multidimensional STUMP use `stumpy.mstump` or `stumpy.mstumped`"
)
if T_B.ndim != 1: # pragma: no cover
raise ValueError(
f"T_B is {T_B.ndim}-dimensional and must be 1-dimensional. "
"For multidimensional STUMP use `stumpy.mstump` or `stumpy.mstumped`"
)
core.check_dtype(T_B)
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`.")
# Swap T_A and T_B for GPU implementation
# This keeps the API identical to and compatible with `stumpy.stump`
tmp_T = T_A
T_A = T_B
T_B = tmp_T
n = T_B.shape[0]
k = T_A.shape[0] - m + 1
T_B = np.asarray(T_B)
if T_A.ndim != 1: # pragma: no cover
raise ValueError(
f"T_A is {T_A.ndim}-dimensional and must be 1-dimensional. "
"For multidimensional STUMP use `stumpy.mstump` or `stumpy.mstumped`"
)
if T_B.ndim != 1: # pragma: no cover
raise ValueError(
f"T_B is {T_B.ndim}-dimensional and must be 1-dimensional. "
"For multidimensional STUMP use `stumpy.mstump` or `stumpy.mstumped`"
)
core.check_dtype(T_B)
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]
k = T_A.shape[0] - m + 1
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)
μ_Q, σ_Q = core.compute_mean_std(T_B, m)
Additionally, unlike STAMP where the exclusion zone is m/2, the default
exclusion zone for STOMP is m/4 (See Definition 3 and Figure 3).
For self-joins, set `ignore_trivial = True` in order to avoid the
trivial match.
Note that left and right matrix profiles are only available for self-joins.
"""
core.check_dtype(T_A)
core.check_nan(T_A)
if T_B is None:
T_B = T_A
core.check_dtype(T_B)
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)