Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stumpy/aamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ def aamp(T_A, m, T_B=None, ignore_trivial=True, p=2.0, k=1):
"""
if T_B is None:
T_B = T_A.copy()
core.check_self_join(ignore_trivial)
ignore_trivial = True

T_A, T_A_subseq_isfinite = core.preprocess_non_normalized(T_A, m)
Expand Down
1 change: 1 addition & 0 deletions stumpy/aamped.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ def aamped(client, T_A, m, T_B=None, ignore_trivial=True, p=2.0, k=1):
"""
if T_B is None:
T_B = T_A.copy()
core.check_self_join(ignore_trivial)
ignore_trivial = True

T_A, T_A_subseq_isfinite = core.preprocess_non_normalized(T_A, m)
Expand Down
44 changes: 40 additions & 4 deletions stumpy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3738,11 +3738,10 @@ def check_ignore_trivial(T_A, T_B, ignore_trivial):

T_B : numpy.ndarray
The time series or sequence that will be used to annotate T_A. For every
subsequence in T_A, its nearest neighbor in T_B will be recorded. Default is
`None` which corresponds to a self-join.
subsequence in T_A, its nearest neighbor in T_B will be recorded.

ignore_trivial : bool
Set to `True` if this is a self-join. Otherwise, for AB-join, set this
Set to `True` if this is a self-join. Otherwise, for an AB-join, set this
to `False`.

Returns
Expand All @@ -3752,7 +3751,7 @@ def check_ignore_trivial(T_A, T_B, ignore_trivial):

Notes
-----
These warnings may be supressed by using a context manager
These warnings may be suppressed by using a context manager
```
import stumpy
import numpy as np
Expand Down Expand Up @@ -4509,3 +4508,40 @@ def _update_incremental_PI(D, P, I, excl_zone, n_appended=0):
_shift_insert_at_index(I[-1], idx, i + n_appended)

return


def check_self_join(ignore_trivial):
"""
A simple function to check whether `ignore_trivial` is `True` for a self-join

Otherwise, warn the user.

Parameters
----------
ignore_trivial : bool
Set to True if this is a self-join. Otherwise, for AB-join, set this to False.

Returns
-------
None

Notes
-----
These warnings may be suppressed by using a context manager
```
import stumpy
import numpy as np
import warnings

T = np.random.rand(10_000)
m = 50
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="`ignore_trivial` cannot be `False`")
for _ in range(5):
stumpy.stump(T, m, ignore_trivial=False)
```
"""
if ignore_trivial is False:
msg = "`ignore_trivial` cannot be `False` for a self-join and "
msg += "has been automatically overridden and set to `True`."
warnings.warn(msg)
1 change: 1 addition & 0 deletions stumpy/gpu_aamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ def gpu_aamp(T_A, m, T_B=None, ignore_trivial=True, device_id=0, p=2.0, k=1):
"""
if T_B is None: # Self join!
T_B = T_A
core.check_self_join(ignore_trivial)
ignore_trivial = True

T_A, T_A_subseq_isfinite = core.preprocess_non_normalized(T_A, m)
Expand Down
8 changes: 6 additions & 2 deletions stumpy/gpu_stump.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,11 @@ def gpu_stump(
Default is ``None`` which corresponds to a self-join.
ignore_trivial : bool, default True
Set to ``True`` if this is a self-join. Otherwise, for AB-join, set this
to ``False``.
Set to ``True`` if this is a self-join (i.e., for a single time series
``T_A`` without ``T_B``). This ensures that an exclusion zone is applied
to each subsequence in ``T_A`` and all trivial/self-matches are ignored.
Otherwise, for an AB-join (i.e., between two times series, ``T_A`` and
``T_B``), set this to ``False``.
device_id : int or list, default 0
The (GPU) device number to use. The default value is ``0``. A list of
Expand Down Expand Up @@ -644,6 +647,7 @@ def gpu_stump(
"""
if T_B is None: # Self join!
T_B = T_A
core.check_self_join(ignore_trivial)
ignore_trivial = True
T_B_subseq_isconstant = T_A_subseq_isconstant

Expand Down
1 change: 1 addition & 0 deletions stumpy/scraamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ def __init__(

if T_B is None:
T_B = T_A
core.check_self_join(self._ignore_trivial)
self._ignore_trivial = True

self._m = m
Expand Down
8 changes: 6 additions & 2 deletions stumpy/scrump.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,8 +810,11 @@ def __init__(
subsequence in T_A, its nearest neighbor in T_B will be recorded.
ignore_trivial : bool, default True
Set to `True` if this is a self-join. Otherwise, for AB-join, set this to
`False`. Default is `True`.
Set to ``True`` if this is a self-join (i.e., for a single time series
``T_A`` without ``T_B``). This ensures that an exclusion zone is applied
to each subsequence in ``T_A`` and all trivial/self-matches are ignored.
Otherwise, for an AB-join (i.e., between two times series, ``T_A`` and
``T_B``), set this to ``False``.
percentage : float, default 0.01
Approximate percentage completed. The value is between 0.0 and 1.0.
Expand Down Expand Up @@ -867,6 +870,7 @@ def __init__(

if T_B is None:
T_B = T_A
core.check_self_join(self._ignore_trivial)
self._ignore_trivial = True
T_B_subseq_isconstant = T_A_subseq_isconstant

Expand Down
1 change: 1 addition & 0 deletions stumpy/stomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def _stomp(T_A, m, T_B=None, ignore_trivial=True):

if T_B is None:
T_B = T_A
core.check_self_join(ignore_trivial)
ignore_trivial = True

T_A, μ_Q, σ_Q, Q_subseq_isconstant = core.preprocess(T_A, m)
Expand Down
8 changes: 6 additions & 2 deletions stumpy/stump.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,11 @@ def stump(
Default is ``None`` which corresponds to a self-join.
ignore_trivial : bool, default True
Set to ``True`` if this is a self-join. Otherwise, for AB-join, set this
to ``False``.
Set to ``True`` if this is a self-join (i.e., for a single time series
``T_A`` without ``T_B``). This ensures that an exclusion zone is applied
to each subsequence in ``T_A`` and all trivial/self-matches are ignored.
Otherwise, for an AB-join (i.e., between two times series, ``T_A`` and
``T_B``), set this to ``False``.
normalize : bool, default True
When set to ``True``, this z-normalizes subsequences prior to computing
Expand Down Expand Up @@ -677,6 +680,7 @@ def stump(
mparray([4, 3, 0, 1, 0])
"""
if T_B is None:
core.check_self_join(ignore_trivial)
ignore_trivial = True
T_B = T_A
T_B_subseq_isconstant = T_A_subseq_isconstant
Expand Down
8 changes: 6 additions & 2 deletions stumpy/stumped.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,11 @@ def stumped(
Default is ``None`` which corresponds to a self-join.
ignore_trivial : bool, default True
Set to ``True`` if this is a self-join. Otherwise, for AB-join, set this
to ``False``.
Set to ``True`` if this is a self-join (i.e., for a single time series
``T_A`` without ``T_B``). This ensures that an exclusion zone is applied
to each subsequence in ``T_A`` and all trivial/self-matches are ignored.
Otherwise, for an AB-join (i.e., between two times series, ``T_A`` and
``T_B``), set this to ``False``.
normalize : bool, default True
When set to ``True``, this z-normalizes subsequences prior to computing
Expand Down Expand Up @@ -585,6 +588,7 @@ def stumped(
"""
if T_B is None:
T_B = T_A
core.check_self_join(ignore_trivial)
ignore_trivial = True
T_B_subseq_isconstant = T_A_subseq_isconstant

Expand Down
6 changes: 6 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1963,3 +1963,9 @@ def test_update_incremental_PI_egressTrue_MemoryCheck():

npt.assert_almost_equal(P_ref, P_comp)
npt.assert_almost_equal(I_ref, I_comp)


def test_check_self_join():
with pytest.warns(UserWarning):
ignore_trivial = False
core.check_self_join(ignore_trivial)