pyts.metrics.dtw_fast(x, y, dist='square', radius=0, return_cost=False, return_accumulated=False, return_path=False)[source]

Fast Dynamic Time Warping distance.

x : array-like, shape = (n_timestamps_1,)

First array.

y : array-like, shape = (n_timestamps_2,)

Second array.

dist : ‘square’, ‘absolute’, ‘precomputed’ or callable (default = ‘square’)

Distance used. If ‘square’, the squared difference is used. If ‘absolute’, the absolute difference is used. If ‘precomputed’, precomputed_cost must be the cost matrix. If callable, it must be a function with a numba.njit() decorator that takes as input two numbers (two arguments) and returns a number.

radius : int (default = 0)

The radius used to expand the constraint region. The optimal path computed at the resolution level is expanded with radius cells to the top, bottom, left and right of every cell belonging to the optimal path. It is computed at the resolution level.

return_cost : bool (default = False)

If True, the cost matrix is returned.

return_accumulated : bool (default = False)

If True, the accumulated cost matrix is returned.

return_path : bool (default = False)

If True, the optimal path is returned.

dtw_dist : float

The DTW distance between the two arrays.

cost_mat : ndarray, shape = (n_timestamps_1, n_timestamps_2)

Cost matrix. Only returned if return_cost=True.

acc_cost_mat : ndarray, shape = (n_timestamps_1, n_timestamps_2)

Accumulated cost matrix. Only returned if return_accumulated=True.

path : ndarray, shape = (2, path_length)

The optimal path along the cost matrix. The first row consists of the indices of the optimal path for x while the second row consists of the indices of the optimal path for y. Only returned if return_path=True.


[1]S. Salvador ans P. Chan, “FastDTW: Toward Accurate Dynamic Time Warping in Linear Time and Space”. KDD Workshop on Mining Temporal and Sequential Data, 70–80 (2004).


>>> from pyts.metrics import dtw_fast
>>> x = [0, 1, 1]
>>> y = [2, 0, 1]
>>> dtw_multiscale(x, y, resolution=2, radius=1)