dtaidistance.dtw

Dynamic Time Warping (DTW)

author:Wannes Meert
copyright:Copyright 2017-2018 KU Leuven, DTAI Research Group.
license:Apache License, Version 2.0, see LICENSE for details.
dtaidistance.dtw.best_path(paths)

Compute the optimal path from the nxm warping paths matrix.

dtaidistance.dtw.best_path2(paths)

Compute the optimal path from the nxm warping paths matrix.

dtaidistance.dtw.distance(s1, s2, window=None, max_dist=None, max_step=None, max_length_diff=None, penalty=None, psi=None, use_c=False)

Dynamic Time Warping.

This function keeps a compact matrix, not the full warping paths matrix.

Parameters:
  • s1 – First sequence
  • s2 – Second sequence
  • window – Only allow for maximal shifts from the two diagonals smaller than this number. It includes the diagonal, meaning that an Euclidean distance is obtained by setting weight=1.
  • max_dist – Stop if the returned values will be larger than this value
  • max_step – Do not allow steps larger than this value
  • max_length_diff – Return infinity if length of two series is larger
  • penalty – Penalty to add if compression or expansion is applied
  • psi – Psi relaxation parameter (ignore start and end of matching). Useful for cyclical series.
  • use_c – Use fast pure c compiled functions

Returns: DTW distance

dtaidistance.dtw.distance_fast(s1, s2, window=None, max_dist=None, max_step=None, max_length_diff=None, penalty=None, psi=None)

Fast C version of distance().

dtaidistance.dtw.distance_matrix(s, max_dist=None, max_length_diff=None, window=None, max_step=None, penalty=None, psi=None, block=None, parallel=False, use_c=False, use_nogil=False, show_progress=False)

Distance matrix for all sequences in s.

Parameters:
  • s – Iterable of series
  • window – see distance()
  • max_dist – see distance()
  • max_step – see distance()
  • max_length_diff – see distance()
  • penalty – see distance()
  • psi – see distance()
  • block – Only compute block in matrix. Expects tuple with begin and end, e.g. ((0,10),(20,25)) will only compare rows 0:10 with rows 20:25.
  • parallel – Use parallel operations
  • use_c – Use c compiled Python functions (it is recommended to use use_nogil)
  • use_nogil – Use pure c functions
  • show_progress – Show progress using the tqdm library
dtaidistance.dtw.distance_matrix_fast(s, max_dist=None, max_length_diff=None, window=None, max_step=None, penalty=None, psi=None, block=None, parallel=True, show_progress=False)

Fast C version of distance_matrix().

dtaidistance.dtw.lb_keogh(s1, s2, window=None, max_dist=None, max_step=None, max_length_diff=None)

Lowerbound LB_KEOGH

dtaidistance.dtw.warp(from_s, to_s, **kwargs)

Warp a function to optimally match a second function.

Same options as warping_paths().

dtaidistance.dtw.warping_path(from_s, to_s, **kwargs)

Compute warping path between two sequences.

dtaidistance.dtw.warping_paths(s1, s2, window=None, max_dist=None, max_step=None, max_length_diff=None, penalty=None, psi=None)

Dynamic Time Warping.

The full matrix of all warping paths is build.

Parameters:
Returns:

(DTW distance, DTW matrix)