dtw2: DTW distance with L2 norm

View source: R/DISTANCES-dtw2.R

dtw2R Documentation

DTW distance with L2 norm


Wrapper for the dtw::dtw() function using L2 norm for both the local cost matrix (LCM) creation as well as the final cost aggregation step.


dtw2(x, y, ...)


x, y

A time series. A multivariate series should have time spanning the rows and variables spanning the columns.


Further arguments for dtw::dtw().


The L-norms are used in two different steps by the DTW algorithm. First when creating the LCM, where the element (i,j) of the matrix is computed as the L-norm of x^v_i - y^v_j for all variables v. Note that this means that, in case of multivariate series, they must have the same number of variables, and that univariate series will produce the same LCM regardless of the L-norm used. After the warping path is found by DTW, the final distance is calculated as the L-norm of all (i,j) elements of the LCM that fall on the warping path.

The dtw::dtw() function allows changing the norm by means of its dist.method parameter, but it only uses it when creating the LCM, and not when calculating the final aggregated cost, i.e. the DTW distance.

This wrapper simply returns the appropriate DTW distance using L2 norm (Euclidean norm). A proxy::dist() version is also registered.

The windowing constraint uses a centered window. The calculations expect a value in window.size that represents the distance between the point considered and one of the edges of the window. Therefore, if, for example, window.size = 10, the warping for an observation x_i considers the points between x_{i-10} and x_{i+10}, resulting in 10(2) + 1 = 21 observations falling within the window.


An object of class dtw.

dtwclust documentation built on March 7, 2023, 7:49 p.m.