shape_dtw_distance¶
- shape_dtw_distance(x: ndarray, y: ndarray, window: float | None = None, descriptor: str = 'identity', reach: int = 15, itakura_max_slope: float | None = None, transformation_precomputed: bool = False, transformed_x: ndarray | None = None, transformed_y: ndarray | None = None) float [source]¶
Compute the ShapeDTW distance function between two series x and y.
The ShapeDTW distance method was proposed in [1] and used for time series averaging in [2] as well.
- 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 or None, default=None
The window to use for the bounding matrix. If None, no bounding matrix is used. window is a percentage deviation, so if
window = 0.1
then 10% of the series length is the max warping allowed. is used.- descriptorstr, default=None (if None then identity is used).
Defines which transformation is applied on the sub-sequences. Valid descriptors are: [‘identity’]
Identity is simply a copying mechanism of the sub-sequence, no transformations are done. For now no other descriptors are implemented.
If not specified then identity is used.
- reachint, default=15.
Length of the sub-sequences to consider.
- 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.
- transformation_precomputedbool, default = False
To choose if the transformation of the sub-sequences is pre-computed or not.
- transformed_xnp.ndarray, default = None
The transformation of x, ignored if transformation_precomputed is False.
- transformed_ynp.ndarray, default = None
The transformation of y, ignored if transformation_precomputed is False.
- Returns:
- float
ShapeDTW distance between x and y, minimum value 0.
- Raises:
- ValueError
If x and y are not 1D or 2D arrays.
References
- [1] Zhao, Jiaping, and Laurent Itti. “shapedtw: Shape dynamic time warping.”
Pattern Recognition 74 (2018): 171-184.
- [2] Ali Ismail-Fawaz, Hassan Ismail Fawaz, François Petitjean, Maxime Devanne,
Jonathan Weber, Stefano Berretti, Geoffrey I. Webb and Germain Forestier. “ShapeDBA: Generating Effective Time Series Prototypes using ShapeDTW Barycenter Averaging” ECML/PKDD Workshop on Advanced Analytics and Learning on Temporal Data, Turin, Italy, 2023.