dtaidistance.subsequence.subsequencesearch

(requires version 2.3.0 or higher)

DTW-based subsequence matching.

author:

Wannes Meert

copyright:

Copyright 2021-2023 KU Leuven, DTAI Research Group.

license:

Apache License, Version 2.0, see LICENSE for details.

class dtaidistance.subsequence.subsequencesearch.SSMatch(kidx, ss)

Found match by SubsequenceSearch.

The match is identified by the idx property, which is the index of the matched series in the original list of series. The distance property returns the DTW distance between the query and the series at index idx.

property distance

DTW distance.

property idx
property value

Normalized DTW distance.

class dtaidistance.subsequence.subsequencesearch.SSMatches(ss, k=None)

Iterator over matches.

Parameters:
  • ss – The SubsequenceSearch object

  • k – Optional a k. This overrules the ss.k value. Useful if a smaller k is asked to iterate over than has been stored.

class dtaidistance.subsequence.subsequencesearch.SubsequenceSearch(query, s, dists_options=None, use_lb=True, keep_all_distances=False, max_dist=None, max_value=None, use_c=None, use_ndim=None)

Search the best matching (subsequence) time series compared to a given time series.

Parameters:
  • query – Time series to search for

  • s – Iterator over time series to perform search on. This can be for example windows over a long time series.

  • dists_options – Options passed on to dtw.distance

  • use_lb – Use lowerbounds to early abandon options

  • max_dist – Ignore DTW distances larger than this value if max_dist is also given in dists_options, then the one in dists_options is ignored if both max_dist and max_value are given, the smallest is used

  • max_value – Ignore normalized DTW distances larger than this value

align(k=None)
align_fast(k=None)
best_match()
best_match_fast()
get_ith_value(i)

Return the i-th value from the k-best values.

Parameters:

i – Return i-th best value (i < k)

Returns:

(distance, index)

kbest_matches(k=1)

Return the k best matches.

It is recommended to set k to a value, and not None. If k is set to None, all comparisons are kept and returned. Also, no early stopping is applied in case k is None.

Parameters:

k – Number of best matches to return (default is 1)

Returns:

List of SSMatch objects

kbest_matches_fast(k=1)
reset()

See SubsequenceSearch.

Parameters:
  • query – Time series to search for

  • series – Iterator over time series to perform search on. This can be for example windows over a long time series.

  • dists_options – Options passed on to dtw.distance

  • use_lb – Use lowerbounds to early abandon options

  • max_dist – Ignore DTW distances larger than this value

  • max_value – Ignore normalized DTW distances larger than this value

  • use_c – Use fast C implementation if available

Returns:

SubsequenceSearch object