Skip to content

Commit 548e1e4

Browse files
committed
Fixed #499 Added atol parameter
1 parent a4e8a66 commit 548e1e4

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

stumpy/aamp_motifs.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def _aamp_motifs(
2222
cutoff,
2323
max_matches,
2424
max_motifs,
25+
atol=1e-8,
2526
):
2627
"""
2728
Find the top non-normalized motifs (i.e., without z-normalization) for time series
@@ -72,6 +73,10 @@ def _aamp_motifs(
7273
max_motifs : int
7374
The maximum number of motifs to return.
7475
76+
atol : float, default 1e-8
77+
The absolute tolerance parameter. This value will be added to `max_distance`
78+
when comparing distances between subsequences.
79+
7580
Return
7681
------
7782
motif_distances : numpy.ndarray
@@ -112,6 +117,7 @@ def _aamp_motifs(
112117
T,
113118
max_matches=None,
114119
max_distance=max_distance,
120+
atol=atol,
115121
)
116122

117123
if len(query_matches) > min_neighbors:
@@ -141,6 +147,7 @@ def aamp_motifs(
141147
cutoff=None,
142148
max_matches=10,
143149
max_motifs=1,
150+
atol=1e-8,
144151
):
145152
"""
146153
Discover the top non-normalized motifs (i.e., without z-normalization) for time
@@ -208,6 +215,10 @@ def aamp_motifs(
208215
max_motifs : int, default 1
209216
The maximum number of motifs to return.
210217
218+
atol : float, default 1e-8
219+
The absolute tolerance parameter. This value will be added to `max_distance`
220+
when comparing distances between subsequences.
221+
211222
Return
212223
------
213224
motif_distances : numpy.ndarray
@@ -267,6 +278,7 @@ def aamp_motifs(
267278
cutoff,
268279
max_matches,
269280
max_motifs,
281+
atol=atol,
270282
)
271283

272284
return motif_distances, motif_indices
@@ -279,6 +291,7 @@ def aamp_match(
279291
T_squared=None,
280292
max_distance=None,
281293
max_matches=None,
294+
atol=1e-8,
282295
):
283296
"""
284297
Find all matches of a query `Q` in a time series `T`, i.e. the indices
@@ -309,6 +322,10 @@ def aamp_match(
309322
indices of the most similar `10` subsequences is returned. If `None`, then all
310323
occurrences are returned.
311324
325+
atol : float, default 1e-8
326+
The absolute tolerance parameter. This value will be added to `max_distance`
327+
when comparing distances between subsequences.
328+
312329
Returns
313330
-------
314331
out : numpy.ndarray
@@ -356,7 +373,7 @@ def max_distance(D):
356373
matches = []
357374

358375
candidate_idx = np.argmin(D)
359-
while D[candidate_idx] <= max_distance and len(matches) < max_matches:
376+
while D[candidate_idx] <= atol + max_distance and len(matches) < max_matches:
360377
matches.append([D[candidate_idx], candidate_idx])
361378
core.apply_exclusion_zone(D, candidate_idx, excl_zone)
362379
candidate_idx = np.argmin(D)

stumpy/motifs.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def _motifs(
2323
cutoff,
2424
max_matches,
2525
max_motifs,
26+
atol=1e-8,
2627
):
2728
"""
2829
Find the top motifs for time series `T`.
@@ -71,10 +72,9 @@ def _motifs(
7172
max_motifs : int
7273
The maximum number of motifs to return.
7374
74-
normalize : bool
75-
When set to `True`, this z-normalizes subsequences prior to computing distances.
76-
Otherwise, this function gets re-routed to its complementary non-normalized
77-
equivalent set in the `@core.non_normalized` function decorator.
75+
atol : float, default 1e-8
76+
The absolute tolerance parameter. This value will be added to `max_distance`
77+
when comparing distances between subsequences.
7878
7979
Return
8080
------
@@ -118,6 +118,7 @@ def _motifs(
118118
Σ_T=Σ_T,
119119
max_matches=None,
120120
max_distance=max_distance,
121+
atol=atol,
121122
)
122123

123124
if len(query_matches) > min_neighbors:
@@ -148,6 +149,7 @@ def motifs(
148149
cutoff=None,
149150
max_matches=10,
150151
max_motifs=1,
152+
atol=1e-8,
151153
normalize=True,
152154
):
153155
"""
@@ -306,6 +308,7 @@ def match(
306308
Σ_T=None,
307309
max_distance=None,
308310
max_matches=None,
311+
atol=1e-8,
309312
normalize=True,
310313
):
311314
"""
@@ -344,6 +347,10 @@ def match(
344347
indices of the most similar `10` subsequences is returned. If `None`, then all
345348
occurrences are returned.
346349
350+
atol : float, default 1e-8
351+
The absolute tolerance parameter. This value will be added to `max_distance`
352+
when comparing distances between subsequences.
353+
347354
normalize : bool, default True
348355
When set to `True`, this z-normalizes subsequences prior to computing distances.
349356
Otherwise, this function gets re-routed to its complementary non-normalized
@@ -407,7 +414,7 @@ def max_distance(D):
407414
matches = []
408415

409416
candidate_idx = np.argmin(D)
410-
while D[candidate_idx] <= max_distance and len(matches) < max_matches:
417+
while D[candidate_idx] <= atol + max_distance and len(matches) < max_matches:
411418
matches.append([D[candidate_idx], candidate_idx])
412419
core.apply_exclusion_zone(D, candidate_idx, excl_zone)
413420
candidate_idx = np.argmin(D)

0 commit comments

Comments
 (0)