twe_distance#
- twe_distance(x: ndarray, y: ndarray, window: float = None, nu: float = 0.001, lmbda: float = 1.0) float [source]#
Compute the TWE distance between two time series.
The Time Warp Edit (TWE) distance is a distance measure for discrete time series matching with time ‘elasticity’. In comparison to other distance measures, (e.g. DTW (Dynamic Time Warping) or LCS (Longest Common Subsequence Problem)), TWE is a metric. Its computational time complexity is O(n^2), but can be drastically reduced in some specific situation by using a corridor to reduce the search space. Its memory space complexity can be reduced to O(n). It was first proposed in [1].
- 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:
- float
TWE distance between x and y.
- Raises:
- ValueError
If x and y are not 1D or 2D arrays.
References
[1]Marteau, P.; F. (2009). “Time Warp Edit Distance with Stiffness Adjustment
for Time Series Matching”. IEEE Transactions on Pattern Analysis and Machine Intelligence. 31 (2): 306–318.
Examples
>>> import numpy as np >>> from aeon.distances import twe_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]]) >>> dist = twe_distance(x, y)