dtaidistance.dtw¶
Dynamic Time Warping (DTW)
author:  Wannes Meert 

copyright:  Copyright 20172018 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()
.Note: the series are expected to be arrays of the type
double
. Thusnumpy.array([1,2,3], dtype=numpy.double)
orarray.array('d', [1,2,3])

dtaidistance.dtw.
distance_matrix
(s, max_dist=None, max_length_diff=None, window=None, max_step=None, penalty=None, psi=None, block=None, compact=False, 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.
 compact – Return the distance matrix as an array representing the upper triangular matrix.
 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.
distances_array_to_matrix
(dists, nb_series, block=None)¶ Transform a distances array to a full matrix representation.
The upper triangular matrix will contain all the distances.

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_amount
(path)¶ Returns the number of compressions and expansions performed to obtain the best path. Can be used as a metric for the amount of warping.
Parameters: path – path to be tested :returns number of compressions or expansions

dtaidistance.dtw.
warping_path
(from_s, to_s, **kwargs)¶ Compute warping path between two sequences.

dtaidistance.dtw.
warping_path_penalty
(s1, s2, penalty_post=0, **kwargs)¶ Dynamic Time Warping.
This function supports two different penalties. The traditional DTW penalty penalty is used in the matrix during calculation of the warping path (see
distance()
).The second penalty penalty_post measures the amount of warping. This penalty doesn’t affect the warping path and is added to the DTW distance after the warping for every compression or expansion.
Same options as
warping_paths()
Parameters:  s1 – First sequence
 s2 – Second sequence
 penalty_post – Penalty to be added after path calculation, for compression/extension
:returns [DTW distance, best path, DTW distance between 2 path elements, DTW matrix]

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:  s1 – First sequence
 s2 – Second sequence
 window – see
distance()
 max_dist – see
distance()
 max_step – see
distance()
 max_length_diff – see
distance()
 penalty – see
distance()
 psi – see
distance()
Returns: (DTW distance, DTW matrix)

dtaidistance.dtw.
warping_paths_fast
(s1, s2, window=None, max_dist=None, max_step=None, max_length_diff=None, penalty=None, psi=None)¶ Fast C version of
distance()
.