dtw_cost_matrix

dtw_cost_matrix(x: ndarray, y: ndarray, window: float | None = None, itakura_max_slope: float | None = None) ndarray[source]

Compute the DTW cost matrix between two time series.

The cost matrix is the pairwise Euclidean distance between all points \(M_{i,j}=(x_i-x_j)^2\). It is used in the DTW path calculations.

Parameters:
xnp.ndarray

First time series, either univariate, shape (n_timepoints,), or multivariate, shape (n_channels, n_timepoints).

ynp.ndarray

Second time series, either univariate, shape (n_timepoints,), or multivariate, shape (n_channels, n_timepoints).

windowfloat, default=None

The window to use for the bounding matrix. If None, no bounding matrix is used. window is a percentage deviation, so if window = 0.1, 10% of the series length is the max warping allowed. is used.

itakura_max_slopefloat, default=None

Maximum slope as a proportion of the number of time points used to create Itakura parallelogram on the bounding matrix. Must be between 0. and 1.

Returns:
np.ndarray (n_timepoints, m_timepoints)

dtw cost matrix between x and y.

Raises:
ValueError

If x and y are not 1D or 2D arrays.

Examples

>>> import numpy as np
>>> from aeon.distances import dtw_cost_matrix
>>> x = np.array([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]])
>>> y = np.array([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]])
>>> dtw_cost_matrix(x, y)
array([[  0.,   1.,   5.,  14.,  30.,  55.,  91., 140., 204., 285.],
       [  1.,   0.,   1.,   5.,  14.,  30.,  55.,  91., 140., 204.],
       [  5.,   1.,   0.,   1.,   5.,  14.,  30.,  55.,  91., 140.],
       [ 14.,   5.,   1.,   0.,   1.,   5.,  14.,  30.,  55.,  91.],
       [ 30.,  14.,   5.,   1.,   0.,   1.,   5.,  14.,  30.,  55.],
       [ 55.,  30.,  14.,   5.,   1.,   0.,   1.,   5.,  14.,  30.],
       [ 91.,  55.,  30.,  14.,   5.,   1.,   0.,   1.,   5.,  14.],
       [140.,  91.,  55.,  30.,  14.,   5.,   1.,   0.,   1.,   5.],
       [204., 140.,  91.,  55.,  30.,  14.,   5.,   1.,   0.,   1.],
       [285., 204., 140.,  91.,  55.,  30.,  14.,   5.,   1.,   0.]])