cost_matrix#
- cost_matrix(x: ndarray, y: ndarray, metric: str, **kwargs: Any) ndarray [source]#
Compute the alignment path and 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. The value must be one of the following strings: ‘dtw’, ‘ddtw’, ‘wdtw’, ‘wddtw’, ‘lcss’, ‘edr’, ‘erp’, ‘msm’
- kwargs: Any
Arguments for metric. Refer to each metrics documentation for a list of possible arguments.
- Returns:
- np.ndarray (n_timepoints, m_timepoints)
cost matrix between x and y.
- Raises:
- ValueError
If x and y are not 1D, or 2D arrays. If metric is not one of the supported strings or a callable.
Examples
>>> import numpy as np >>> from aeon.distances import 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]]) >>> cost_matrix(x, y, metric="dtw") 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.]])