ddtw_pairwise_distance

ddtw_pairwise_distance(X: ndarray | list[ndarray], y: ndarray | list[ndarray] | None = None, window: float | None = None, itakura_max_slope: float | None = None) ndarray[source]

Compute the DDTW pairwise distance between a set of time series.

Parameters:
Xnp.ndarray or List of np.ndarray

A collection of time series instances of shape (n_cases, n_timepoints) or (n_cases, n_channels, n_timepoints).

ynp.ndarray or List of np.ndarray or None, default=None

A single series or a collection of time series of shape (m_timepoints,) or (m_cases, m_timepoints) or (m_cases, m_channels, m_timepoints). If None, then the ddtw pairwise distance between the instances of X is calculated.

windowfloat, default=None

The window to use for the bounding matrix. If None, no bounding matrix 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_cases, n_cases)

ddtw pairwise matrix between the instances of X.

Raises:
ValueError

If X is not 2D or 3D array when only passing X. If X and y are not 1D, 2D or 3D arrays when passing both X and y. If n_timepoints is less than 2.

Examples

>>> import numpy as np
>>> from aeon.distances import ddtw_pairwise_distance
>>> # Distance between each time series in a collection of time series
>>> X = np.array([[[1, 2, 3]],[[49, 58, 61]], [[73, 82, 99]]])
>>> ddtw_pairwise_distance(X)
array([[  0.  ,  42.25, 100.  ],
       [ 42.25,   0.  ,  12.25],
       [100.  ,  12.25,   0.  ]])
>>> # Distance between two collections of time series
>>> X = np.array([[[19, 12, 39]],[[40, 51, 69]], [[79, 28, 91]]])
>>> y = np.array([[[110, 15, 123]],[[14, 150, 116]], [[9917, 118, 29]]])
>>> ddtw_pairwise_distance(X, y)
array([[2.09306250e+03, 8.46400000e+03, 5.43611290e+07],
       [3.24900000e+03, 6.52056250e+03, 5.45271481e+07],
       [4.73062500e+02, 1.34560000e+04, 5.40078010e+07]])
>>> X = np.array([[[10, 22, 399]],[[41, 500, 1316]], [[117, 18, 9]]])
>>> y_univariate = np.array([100, 11, 199])
>>> ddtw_pairwise_distance(X, y_univariate)
array([[ 15129.    ],
       [322624.    ],
       [  3220.5625]])
>>> # Distance between each TS in a collection of unequal-length time series
>>> X = [np.array([1, 2, 3]), np.array([4, 5, 6, 7]), np.array([8, 9, 10, 11, 12])]
>>> ddtw_pairwise_distance(X)
array([[0., 0., 0.],
       [0., 0., 0.],
       [0., 0., 0.]])