pyts.metrics.dtw_itakura

pyts.metrics.dtw_itakura(x=None, y=None, dist='square', max_slope=2.0, precomputed_cost=None, return_cost=False, return_accumulated=False, return_path=False)[source]

Dynamic Time Warping distance with Itakura parallelogram constraint.

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

First array. Ignored if dist == 'precomputed'.

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

Second array. Ignored if dist == 'precomputed'.

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.

max_slope : float (default = 2.)

Maximum slope for the parallelogram.

precomputed_cost : array-like, shape = (n_timestamps_1, n_timestamps_2) (default = None).

Precomputed cost matrix between the time series. Ignored if dist != 'precomputed'.

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]F. Itakura, “Minimum prediction residual principle applied to speech recognition”. IEEE Transactions on Acoustics, Speech, and Signal Processing, 23(1), 67–72 (1975).

Examples

>>> from pyts.metrics import dtw_itakura
>>> x = [0, 1, 1]
>>> y = [2, 0, 1]
>>> dtw_itakura(x, y, max_slope=1.5)
2.23...