distance#

distance(x: ndarray, y: ndarray, metric: Union[str, Callable[[ndarray, ndarray, Any], float]], **kwargs: Any) float[source]#

Compute the distance between two time series.

Parameters:
x: np.ndarray, of shape (n_channels, n_timepoints) or (n_timepoints,)

First time series.

y: np.ndarray, of shape (m_channels, m_timepoints) or (m_timepoints,)

Second time series.

metric: str or Callable

The distance metric to use. If a string is given, the value must be one of the following strings: ‘euclidean’, ‘squared’, ‘dtw’, ‘ddtw’, ‘wdtw’, ‘wddtw’, ‘lcss’, ‘edr’, ‘erp’, ‘msm’ If a callable is given, the value must be a function that accepts two numpy arrays and **kwargs returns a float.

kwargs: Any

Arguments for metric. Refer to each metrics documentation for a list of possible arguments.

Returns:
float

Distance between the x and y.

Raises:
ValueError

If x and y are not 1D, or 2D arrays. If metric is not a valid string or callable.

Examples

>>> import numpy as np
>>> from aeon.distances import distance
>>> x = np.array([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]])
>>> y = np.array([[11, 12, 13, 14, 15, 16, 17, 18, 19, 20]])
>>> distance(x, y, metric="dtw")
768.0