wddtw_distance(x: ndarray, y: ndarray, window: float | None = None, itakura_max_slope: float | None = None, bounding_matrix: ndarray | None = None, compute_derivative=None, g: float = 0.0, **kwargs: Any) float[source]#

Compute the weighted derivative dynamic time warping (WDDTW) distance.

WDDTW was first proposed in [1] as an extension of DDTW. By adding a weight to the derivative it means the alignment isn’t only considering the shape of the time series, but also the phase.

Formally the derivative is calculated as:

\[D_{x}[q] = \frac{{}(q_{i} - q_{i-1} + ((q_{i+1} - q_{i-1}/2)}{2}\]

Therefore a weighted derivative can be calculated using D (the derivative) as:

\[d_{w}(x_{i}, y_{j}) = ||w_{|i-j|}(D_{x_{i}} - D_{y_{j}})||\]
x: np.ndarray (1d or 2d array)

First time series.

y: np.ndarray (1d or 2d array)

Second time series.

window: float, defaults = None

Float that is the radius of the sakoe chiba window (if using Sakoe-Chiba lower bounding). Value must be between 0. and 1.

itakura_max_slope: float, defaults = None

Gradient of the slope for itakura parallelogram (if using Itakura Parallelogram lower bounding). Value must be between 0. and 1.

bounding_matrix: np.ndarray (2d of size mxn where m is len(x) and n is len(y)),

defaults = None

Custom bounding matrix to use. If defined then other lower_bounding params are ignored. The matrix should be structure so that indexes considered in bound should be the value 0. and indexes outside the bounding matrix should be infinity.

compute_derivative: Callable[[np.ndarray], np.ndarray],

defaults = average slope difference

Callable that computes the derivative. If none is provided the average of the slope between two points used.

g: float, defaults = 0.

Constant that controls the curvature (slope) of the function; that is, g controls the level of penalisation for the points with larger phase difference.

kwargs: Any

Extra kwargs.


Wddtw distance between x and y.


If the sakoe_chiba_window_radius is not float. If the itakura_max_slope is not a float. If the value of x or y provided is not a numpy array. If the value of x or y has more than 2 dimensions. If a metric string provided, and is not a defined valid string. If a metric object (instance of class) is provided and doesn’t inherit from NumbaDistance. If the metric type cannot be determined If the compute derivative callable is not no_python compiled. If the value of g is not a float If both window and itakura_max_slope are set



Young-Seon Jeong, Myong K. Jeong, Olufemi A. Omitaomu, Weighted dynamic time

warping for time series classification, Pattern Recognition, Volume 44, Issue 9, 2011, Pages 2231-2240, ISSN 0031-3203, https://doi.org/10.1016/j.patcog.2010.09.022.


>>> import numpy as np
>>> from sktime.distances import wddtw_distance
>>> x_1d = np.array([1, 2, 3, 4])  # 1d array
>>> y_1d = np.array([5, 6, 7, 8])  # 1d array
>>> wddtw_distance(x_1d, y_1d) 
>>> x_2d = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])  # 2d array
>>> y_2d = np.array([[9, 10, 11, 12], [13, 14, 15, 16]])  # 2d array
>>> wddtw_distance(x_2d, y_2d)