pyts.metrics.dtw_multiscale

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

Multiscale Dynamic Time Warping distance.

Parameters:
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 callable, it must be a function with a numba.njit() decorator that takes as input two numbers (two arguments) and returns a number.

resolution : int (default = 2)

The resolution level.

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.

Returns:
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 : array, 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.

References

[1]M. Müller, H. Mattes and F. Kurth, “An efficient multiscale approach to audio synchronization”. International Conference on Music Information Retrieval, 6(1), 192-197 (2006).

Examples

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