wdtw_distance(x: ndarray, y: ndarray, window: float | None = None, g: float = 0.05, itakura_max_slope: float | None = None) float[source]

Compute the WDTW distance between two time series.

First proposed in [1], weighted dynamic time warping (WDTW) uses DTW with a weighted pairwise distance matrix rather than a window. When creating the distance matrix :math:’M’, a weight penalty :math:’w_{|i-j|}’ for a warping distance of :math:’|i-j|’ is applied, so that for series \(a = <a_1, ..., a_m>\) and \(b=<b_1,...,b_m>\),

\[M_{i,j}= w(|i-j|) (a_i-b_j)^2.\]

A logistic weight function, proposed in [1] is used, so that a warping of \(x\) places imposes a weighting of


where \(w_{max}\) is an upper bound on the weight (set to 1), \(m\) is the series length and \(g\) is a parameter that controls the penalty level for larger warpings. The greater \(g\) is, the greater the penalty for warping. Once \(M\) is found, standard dynamic time warping is applied.

WDTW is set up so you can use it with a bounding box in addition to the weight function is so desired. This is for consistency with the other distance functions.


A collection of time series instances of shape (n_cases, n_timepoints) or (n_cases, n_channels, n_timepoints).

ynp.ndarray or None, default=None

A single series or a collection of time series of shape (m_timepoints,) or (m_cases, m_timepoints) or (m_cases, m_channels, m_timepoints). If None, then the wdtw pairwise distance between the instances of X is calculated.

windowfloat, default=None

The window to use for the bounding matrix. If None, no bounding matrix is used.

gfloat, default=0.05

Constant that controls the level of penalisation for the points with larger phase difference. Default is 0.05.

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.


WDTW distance between x and y.


If x and y are not 1D or 2D arrays.



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 aeon.distances import wdtw_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]])
>>> round(wdtw_distance(x, y),1)