msm_cost_matrix¶
- msm_cost_matrix(x: ndarray, y: ndarray, window: float | None = None, independent: bool = True, c: float = 1.0, itakura_max_slope: float | None = None) ndarray [source]¶
Compute the MSM cost matrix between two time series.
By default, this takes a collection of \(n\) time series \(X\) and returns a matrix \(D\) where \(D_{i,j}\) is the MSM distance between the \(i^{th}\) and the \(j^{th}\) series in \(X\). If \(X\) is 2-dimensional, it is assumed to be a collection of univariate series with shape
(n_cases, n_timepoints)
. If it is 3-dimensional, it is assumed to be shape(n_cases, n_channels, n_timepoints)
.This function has an optional argument, \(y\), to allow calculation of the distance matrix between \(X\) and one or more series stored in \(y\). If \(y\) is 1-dimensional, we assume it is a single univariate series and the distance matrix returned is shape
(n_cases,1)
. If it is 2D, we assume it is a collection of univariate series with shape(m_cases, m_timepoints)
and the distance(n_cases,m_cases)
. If it is 3-dimensional, it is assumed to be shape(m_cases, m_channels, m_timepoints)
.- Parameters:
- xnp.ndarray
First time series, either univariate, shape
(n_timepoints,)
, or multivariate, shape(n_channels, n_timepoints)
.- ynp.ndarray
Second time series, either univariate, shape
(n_timepoints,)
, or multivariate, shape(n_channels, n_timepoints)
.- windowfloat, default=None
The window size to use for the bounding matrix. If None, the bounding matrix is not used.
- independentbool, default=True
Whether to use the independent or dependent MSM distance. The default is True (to use independent).
- cfloat, default=1.
Cost for split or merge operation. Default is 1.
- 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_timepoints_x, n_timepoints_y)
MSM cost matrix between x and y.
- Raises:
- ValueError
If x and y are not 1D or 2D arrays.
Examples
>>> import numpy as np >>> from aeon.distances import msm_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]]) >>> msm_cost_matrix(x, y) array([[ 0., 2., 4., 6., 8., 10., 12., 14., 16., 18.], [ 2., 0., 2., 4., 6., 8., 10., 12., 14., 16.], [ 4., 2., 0., 2., 4., 6., 8., 10., 12., 14.], [ 6., 4., 2., 0., 2., 4., 6., 8., 10., 12.], [ 8., 6., 4., 2., 0., 2., 4., 6., 8., 10.], [10., 8., 6., 4., 2., 0., 2., 4., 6., 8.], [12., 10., 8., 6., 4., 2., 0., 2., 4., 6.], [14., 12., 10., 8., 6., 4., 2., 0., 2., 4.], [16., 14., 12., 10., 8., 6., 4., 2., 0., 2.], [18., 16., 14., 12., 10., 8., 6., 4., 2., 0.]])