twe_cost_matrix

twe_cost_matrix(x: ndarray, y: ndarray, window: float | None = None, nu: float = 0.001, lmbda: float = 1.0, itakura_max_slope: float | None = None) ndarray[source]

Compute the TWE cost matrix between two time series.

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).

window: int, default=None

Window size. If None, the window size is set to the length of the shortest time series.

nufloat, default=0.001

A non-negative constant which characterizes the stiffness of the elastic twe measure. Must be > 0.

lmbdafloat, default=1.0

A constant penalty that punishes the editing efforts. Must be >= 1.0.

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)

TWE 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 twe_cost_matrix
>>> x = np.array([[1, 2, 3, 4, 5, 6, 7, 8]])
>>> y = np.array([[1, 2, 3, 4, 5, 6, 7, 8]])
>>> twe_cost_matrix(x, y)
array([[ 0.   ,  2.001,  4.002,  6.003,  8.004, 10.005, 12.006, 14.007],
       [ 2.001,  0.   ,  2.001,  4.002,  6.003,  8.004, 10.005, 12.006],
       [ 4.002,  2.001,  0.   ,  2.001,  4.002,  6.003,  8.004, 10.005],
       [ 6.003,  4.002,  2.001,  0.   ,  2.001,  4.002,  6.003,  8.004],
       [ 8.004,  6.003,  4.002,  2.001,  0.   ,  2.001,  4.002,  6.003],
       [10.005,  8.004,  6.003,  4.002,  2.001,  0.   ,  2.001,  4.002],
       [12.006, 10.005,  8.004,  6.003,  4.002,  2.001,  0.   ,  2.001],
       [14.007, 12.006, 10.005,  8.004,  6.003,  4.002,  2.001,  0.   ]])