Skip to content

Commit 33ca9dd

Browse files
authored
Fixed #930 Improve ignore_trivial Docstring and Warnings (#1110)
* Fixed #930 Improve `ignore_trivial` Docstring and Warnings * Added note to docstring * Fixed spelling * Removed reference to default value * Switched if condition to check `is False`
1 parent 8f261c1 commit 33ca9dd

File tree

11 files changed

+75
-12
lines changed

11 files changed

+75
-12
lines changed

stumpy/aamp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ def aamp(T_A, m, T_B=None, ignore_trivial=True, p=2.0, k=1):
396396
"""
397397
if T_B is None:
398398
T_B = T_A.copy()
399+
core.check_self_join(ignore_trivial)
399400
ignore_trivial = True
400401

401402
T_A, T_A_subseq_isfinite = core.preprocess_non_normalized(T_A, m)

stumpy/aamped.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ def aamped(client, T_A, m, T_B=None, ignore_trivial=True, p=2.0, k=1):
375375
"""
376376
if T_B is None:
377377
T_B = T_A.copy()
378+
core.check_self_join(ignore_trivial)
378379
ignore_trivial = True
379380

380381
T_A, T_A_subseq_isfinite = core.preprocess_non_normalized(T_A, m)

stumpy/core.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3738,11 +3738,10 @@ def check_ignore_trivial(T_A, T_B, ignore_trivial):
37383738
37393739
T_B : numpy.ndarray
37403740
The time series or sequence that will be used to annotate T_A. For every
3741-
subsequence in T_A, its nearest neighbor in T_B will be recorded. Default is
3742-
`None` which corresponds to a self-join.
3741+
subsequence in T_A, its nearest neighbor in T_B will be recorded.
37433742
37443743
ignore_trivial : bool
3745-
Set to `True` if this is a self-join. Otherwise, for AB-join, set this
3744+
Set to `True` if this is a self-join. Otherwise, for an AB-join, set this
37463745
to `False`.
37473746
37483747
Returns
@@ -3752,7 +3751,7 @@ def check_ignore_trivial(T_A, T_B, ignore_trivial):
37523751
37533752
Notes
37543753
-----
3755-
These warnings may be supressed by using a context manager
3754+
These warnings may be suppressed by using a context manager
37563755
```
37573756
import stumpy
37583757
import numpy as np
@@ -4509,3 +4508,40 @@ def _update_incremental_PI(D, P, I, excl_zone, n_appended=0):
45094508
_shift_insert_at_index(I[-1], idx, i + n_appended)
45104509

45114510
return
4511+
4512+
4513+
def check_self_join(ignore_trivial):
4514+
"""
4515+
A simple function to check whether `ignore_trivial` is `True` for a self-join
4516+
4517+
Otherwise, warn the user.
4518+
4519+
Parameters
4520+
----------
4521+
ignore_trivial : bool
4522+
Set to True if this is a self-join. Otherwise, for AB-join, set this to False.
4523+
4524+
Returns
4525+
-------
4526+
None
4527+
4528+
Notes
4529+
-----
4530+
These warnings may be suppressed by using a context manager
4531+
```
4532+
import stumpy
4533+
import numpy as np
4534+
import warnings
4535+
4536+
T = np.random.rand(10_000)
4537+
m = 50
4538+
with warnings.catch_warnings():
4539+
warnings.filterwarnings("ignore", message="`ignore_trivial` cannot be `False`")
4540+
for _ in range(5):
4541+
stumpy.stump(T, m, ignore_trivial=False)
4542+
```
4543+
"""
4544+
if ignore_trivial is False:
4545+
msg = "`ignore_trivial` cannot be `False` for a self-join and "
4546+
msg += "has been automatically overridden and set to `True`."
4547+
warnings.warn(msg)

stumpy/gpu_aamp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ def gpu_aamp(T_A, m, T_B=None, ignore_trivial=True, device_id=0, p=2.0, k=1):
519519
"""
520520
if T_B is None: # Self join!
521521
T_B = T_A
522+
core.check_self_join(ignore_trivial)
522523
ignore_trivial = True
523524

524525
T_A, T_A_subseq_isfinite = core.preprocess_non_normalized(T_A, m)

stumpy/gpu_stump.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,11 @@ def gpu_stump(
515515
Default is ``None`` which corresponds to a self-join.
516516
517517
ignore_trivial : bool, default True
518-
Set to ``True`` if this is a self-join. Otherwise, for AB-join, set this
519-
to ``False``.
518+
Set to ``True`` if this is a self-join (i.e., for a single time series
519+
``T_A`` without ``T_B``). This ensures that an exclusion zone is applied
520+
to each subsequence in ``T_A`` and all trivial/self-matches are ignored.
521+
Otherwise, for an AB-join (i.e., between two times series, ``T_A`` and
522+
``T_B``), set this to ``False``.
520523
521524
device_id : int or list, default 0
522525
The (GPU) device number to use. The default value is ``0``. A list of
@@ -644,6 +647,7 @@ def gpu_stump(
644647
"""
645648
if T_B is None: # Self join!
646649
T_B = T_A
650+
core.check_self_join(ignore_trivial)
647651
ignore_trivial = True
648652
T_B_subseq_isconstant = T_A_subseq_isconstant
649653

stumpy/scraamp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ def __init__(
621621

622622
if T_B is None:
623623
T_B = T_A
624+
core.check_self_join(self._ignore_trivial)
624625
self._ignore_trivial = True
625626

626627
self._m = m

stumpy/scrump.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,11 @@ def __init__(
810810
subsequence in T_A, its nearest neighbor in T_B will be recorded.
811811
812812
ignore_trivial : bool, default True
813-
Set to `True` if this is a self-join. Otherwise, for AB-join, set this to
814-
`False`. Default is `True`.
813+
Set to ``True`` if this is a self-join (i.e., for a single time series
814+
``T_A`` without ``T_B``). This ensures that an exclusion zone is applied
815+
to each subsequence in ``T_A`` and all trivial/self-matches are ignored.
816+
Otherwise, for an AB-join (i.e., between two times series, ``T_A`` and
817+
``T_B``), set this to ``False``.
815818
816819
percentage : float, default 0.01
817820
Approximate percentage completed. The value is between 0.0 and 1.0.
@@ -867,6 +870,7 @@ def __init__(
867870

868871
if T_B is None:
869872
T_B = T_A
873+
core.check_self_join(self._ignore_trivial)
870874
self._ignore_trivial = True
871875
T_B_subseq_isconstant = T_A_subseq_isconstant
872876

stumpy/stomp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def _stomp(T_A, m, T_B=None, ignore_trivial=True):
7070

7171
if T_B is None:
7272
T_B = T_A
73+
core.check_self_join(ignore_trivial)
7374
ignore_trivial = True
7475

7576
T_A, μ_Q, σ_Q, Q_subseq_isconstant = core.preprocess(T_A, m)

stumpy/stump.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,11 @@ def stump(
542542
Default is ``None`` which corresponds to a self-join.
543543
544544
ignore_trivial : bool, default True
545-
Set to ``True`` if this is a self-join. Otherwise, for AB-join, set this
546-
to ``False``.
545+
Set to ``True`` if this is a self-join (i.e., for a single time series
546+
``T_A`` without ``T_B``). This ensures that an exclusion zone is applied
547+
to each subsequence in ``T_A`` and all trivial/self-matches are ignored.
548+
Otherwise, for an AB-join (i.e., between two times series, ``T_A`` and
549+
``T_B``), set this to ``False``.
547550
548551
normalize : bool, default True
549552
When set to ``True``, this z-normalizes subsequences prior to computing
@@ -677,6 +680,7 @@ def stump(
677680
mparray([4, 3, 0, 1, 0])
678681
"""
679682
if T_B is None:
683+
core.check_self_join(ignore_trivial)
680684
ignore_trivial = True
681685
T_B = T_A
682686
T_B_subseq_isconstant = T_A_subseq_isconstant

stumpy/stumped.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,11 @@ def stumped(
429429
Default is ``None`` which corresponds to a self-join.
430430
431431
ignore_trivial : bool, default True
432-
Set to ``True`` if this is a self-join. Otherwise, for AB-join, set this
433-
to ``False``.
432+
Set to ``True`` if this is a self-join (i.e., for a single time series
433+
``T_A`` without ``T_B``). This ensures that an exclusion zone is applied
434+
to each subsequence in ``T_A`` and all trivial/self-matches are ignored.
435+
Otherwise, for an AB-join (i.e., between two times series, ``T_A`` and
436+
``T_B``), set this to ``False``.
434437
435438
normalize : bool, default True
436439
When set to ``True``, this z-normalizes subsequences prior to computing
@@ -585,6 +588,7 @@ def stumped(
585588
"""
586589
if T_B is None:
587590
T_B = T_A
591+
core.check_self_join(ignore_trivial)
588592
ignore_trivial = True
589593
T_B_subseq_isconstant = T_A_subseq_isconstant
590594

0 commit comments

Comments
 (0)