shape_dtw_pairwise_distance

shape_dtw_pairwise_distance(X: ndarray | List[ndarray], y: ndarray | List[ndarray] | None = None, window: float | None = None, descriptor: str = 'identity', reach: int = 30, itakura_max_slope: float | None = None, transformation_precomputed: bool = False, transformed_x: ndarray | None = None, transformed_y: ndarray | None = None) ndarray[source]

Compute the ShapeDTW pairwise distance among a set of 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 shape-dtw pairwise distance between the instances of X is calculated.

windowfloat or None, 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 then 10% of the series length is the max warping allowed. is used.

descriptorstr, default=None (if None then identity is used).

Defines which transformation is applied on the sub-sequences. Valid descriptors are: [‘identity’]

Identity is simply a copying mechanism of the sub-sequence, no transformations are done. For now no other descriptors are implemented.

If not specified then identity is used.

reachint, default=30.

Length of the sub-sequences.

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.

transformation_precomputedbool, default = False

To choose if the transformation of the sub-sequences is pre-computed or not.

transformed_xnp.ndarray, default = None

The transformation of X, ignored if transformation_precomputed is False.

transformed_ynp.ndarray, default = None

The transformation of y, ignored if transformation_precomputed is False.

Returns:
np.ndarray

ShapeDTW pairwise matrix between the instances of X of shape (n_cases, n_cases) or between X and y of shape (n_cases, n_cases).

Raises:
ValueError

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

Examples

>>> import numpy as np
>>> from aeon.distances import shape_dtw_pairwise_distance
>>> # Distance between each time series in a collection of time series
>>> X = np.array([[[1, 2, 3]],[[4, 5, 6]], [[7, 8, 9]]])
>>> shape_dtw_pairwise_distance(X)
array([[  0.,  27., 108.],
       [ 27.,   0.,  27.],
       [108.,  27.,   0.]])
>>> # Distance between two collections of time series
>>> X = np.array([[[1, 2, 3]],[[4, 5, 6]], [[7, 8, 9]]])
>>> y = np.array([[[11, 12, 13]],[[14, 15, 16]], [[17, 18, 19]]])
>>> shape_dtw_pairwise_distance(X, y)
array([[300., 507., 768.],
       [147., 300., 507.],
       [ 48., 147., 300.]])
>>> X = np.array([[[1, 2, 3]],[[4, 5, 6]], [[7, 8, 9]]])
>>> y_univariate = np.array([11, 12, 13])
>>> shape_dtw_pairwise_distance(X, y_univariate)
array([[300.],
       [147.],
       [ 48.]])
>>> # 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])]
>>> shape_dtw_pairwise_distance(X)
array([[  0.,  43., 292.],
       [ 43.,   0.,  89.],
       [292.,  89.,   0.]])