Learn R Programming

dtw (version 1.4-3)

dtwDist: Compute a dissimilarity matrix

Description

Compute the dissimilarity matrix between a set of single-variate timeseries.

Usage

dtwDist(m,...)
# dist(m,y,method="DTW")

Arguments

m
numeric matrix, containing timeseries as rows
y
numeric matrix, containing timeseries as rows (for cross-distance)
...
arguments passed to the dtw call

Value

  • A square matrix in which element [i,j] holds the Dynamic Time Warp distance between row i (query) and j (template) of m, i.e. dtw(m[i,],m[j,])$distance.

Details

Compute a dissimilarity matrix, akin to dist, based on the Dynamic Time Warping definition of a distance between single-variate timeseries.

This function returns a square matrix, whereas the dist object is lower-triangular. This makes sense because in general the DTW "distance" is not symmetric (see e.g. asymmetric step patterns).

If a proper dist object is desired, a suitable conversion strategy has to be chosen (see examples).

See Also

Other "distance" functions are: dist, vegdist in package vegan, distance in package analogue, etc.

Examples

Run this code
## symmetric step pattern => symmetric dissimilarity matrix;
## no problem coercing it to a dist object:

m <- matrix(0,ncol=3,nrow=4)
m <- row(m)
dtwDist(m)
as.dist(dtwDist(m))

dist(m,method="DTW");


## asymmetric step pattern: we can either disregard part of the pairs
## (as.dist), or average with the transpose

mm <- matrix(runif(12),ncol=3)
dm <- dtwDist(mm,step=asymmetric)
as.dist(dm)
as.dist((dm+t(dm))/2)

## check definition
stopifnot(dm[2,1]==dtw(mm[2,],mm[1,],step=asymmetric)$distance)

Run the code above in your browser using DataLab