twe_cost_matrix#
- twe_cost_matrix(x: ndarray, y: ndarray, window: float = None, nu: float = 0.001, lmbda: float = 1.0) ndarray [source]#
Compute the TWE cost matrix 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.
- window: int, defaults = None
Window size. If None, the window size is set to the length of the shortest time series.
- nu: float, defaults = 0.001
A non-negative constant which characterizes the stiffness of the elastic twe measure. Must be > 0.
- lmbda: float, defaults = 1.0
A constant penalty that punishes the editing efforts. Must be >= 1.0.
- 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. ]])