pyts.metrics.dtw_sakoechiba¶
-
pyts.metrics.dtw_sakoechiba(x, y, dist='square', window_size=0.1, return_cost=False, return_accumulated=False, return_path=False)[source]¶ Dynamic Time Warping (DTW) distance with Sakoe-Chiba band constraint.
Parameters: - x : array-like, shape = (n_timestamps,)
First array.
- y : array-like, shape = (n_timestamps,)
Second array
- dist : ‘square’, ‘absolute’ 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.
- window_size : int or float (default = 0.1)
The window above and below the diagonale. If float, it must be between 0 and 1, and the actual window size will be computed as
int(window_size * (n_timestamps - 1)). Each cell whose distance with the diagonale is lower than or equal to ‘window_size’ becomes a valid cell for the path.- 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 : array, shape = (n_timestamps, n_timestamps)
Cost matrix. Only returned if
return_cost=True.- acc_cost_mat : array, shape = (n_timestamps, n_timestamps)
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.
Examples
>>> from pyts.metrics import dtw_sakoechiba >>> x = [0, 1, 1] >>> y = [2, 0, 1] >>> dtw_sakoechiba(x, y, window_size=1) 2.0