Skip to content

Commit 795af28

Browse files
committed
Fixed #930 Improve ignore_trivial Docstring and Warnings
1 parent 8f261c1 commit 795af28

File tree

11 files changed

+56
-8
lines changed

11 files changed

+56
-8
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4509,3 +4509,24 @@ def _update_incremental_PI(D, P, I, excl_zone, n_appended=0):
45094509
_shift_insert_at_index(I[-1], idx, i + n_appended)
45104510

45114511
return
4512+
4513+
4514+
def check_self_join(ignore_trivial):
4515+
"""
4516+
A simple function to check whether `ignore_trivial` is `True` for a self-join
4517+
4518+
Otherwise, warn the user.
4519+
4520+
Parameters
4521+
----------
4522+
ignore_trivial : bool
4523+
Set to True if this is a self-join. Otherwise, for AB-join, set this to False.
4524+
4525+
Returns
4526+
-------
4527+
None
4528+
"""
4529+
if not ignore_trivial:
4530+
msg = "`ignore_trivial` cannot be `False` for a self-join and "
4531+
msg += "has been automatically overridden and set to `True`."
4532+
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)