Learn R Programming

dtwclust (version 3.1.1)

dtw_basic: Basic DTW distance

Description

This is a custom implementation of the DTW algorithm without all the functionality included in dtw. Because of that, it should be slightly faster, while still supporting the most common options.

Usage

dtw_basic(x, y, window.size = NULL, norm = "L1", step.pattern = symmetric2, backtrack = FALSE, normalize = FALSE, ..., gcm = NULL, error.check = TRUE)

Arguments

x, y
Time series. Multivariate series must have time spanning the rows and variables spanning the columns.
window.size
Size for slanted band window. NULL means no constraint.
norm
Norm for the DTW calculation, "L1" for Manhattan or "L2" for Euclidean.
step.pattern
Step pattern for DTW. Only symmetric1 or symmetric2 supported here. See stepPattern.
backtrack
Also compute the warping path between series? See details.
normalize
Should the distance be normalized? Only supported for symmetric2.
...
Currently ignored.
gcm
Optionally, a matrix to use for the global cost matrix calculations. It should have NROW(y)+1 columns and NROW(x)+1 rows for backtrack = TRUE or 2 rows for backtrack = FALSE. Used internally for memory optimization. If provided, it will be modified in place by C code, except in the parallel version in proxy::dist which ignores it for thread-safe reasons.
error.check
Check data inconsistencies?

Value

The DTW distance. For backtrack = TRUE, a list with:
  • distance: The DTW distance.
  • index1: x indices for the matched elements in the warping path.
  • index2: y indices for the matched elements in the warping path.

Details

If backtrack is TRUE, the mapping of indices between series is returned in a list.

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.