sbd_pairwise_distance

sbd_pairwise_distance(X: ndarray | List[ndarray], y: ndarray | List[ndarray] | None = None, standardize: bool = True) ndarray[source]

Compute the shape-based distance (SBD) between all pairs of time series.

For multivariate time series, SBD is computed independently for each channel and then averaged. Both time series must have the same number of channels! This is not checked in code for performance reasons. If the number of channels is different, the minimum number of channels is used.

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 SBD is calculated between pairwise instances of x.

standardizebool, default=True

Apply z-score to both input time series for standardization before computing the distance. This makes SBD scaling invariant. Default is True.

Returns:
np.ndarray (n_cases, n_cases)

SBD matrix between the instances of x (and y).

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.

See also

sbd_distance

Compute the shape-based distance between two time series.

Examples

>>> import numpy as np
>>> from aeon.distances import sbd_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]]])
>>> sbd_pairwise_distance(X)
array([[0., 0., 0.],
       [0., 0., 0.],
       [0., 0., 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]]])
>>> sbd_pairwise_distance(X, y)
array([[0., 0., 0.],
       [0., 0., 0.],
       [0., 0., 0.]])
>>> X = np.array([[[1, 2, 3]],[[4, 5, 6]], [[7, 8, 9]]])
>>> y_univariate = np.array([11, 12, 13])
>>> sbd_pairwise_distance(X, y_univariate)
array([[0.],
       [0.],
       [0.]])
>>> # 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])]
>>> sbd_pairwise_distance(X)
array([[0.        , 0.36754447, 0.5527864 ],
       [0.36754447, 0.        , 0.29289322],
       [0.5527864 , 0.29289322, 0.        ]])