dtwDist {dtw} | R Documentation |
Compute the dissimilarity matrix between a set of single-variate timeseries.
dtwDist(m,...) # dist(m,y,method="DTW",...)
m |
numeric matrix, containing timeseries as rows |
y |
numeric matrix, containing timeseries as rows (for cross-distance) |
... |
arguments passed to the dtw call |
The dtwDist
command is obsolete and has been superseded by the
dist
function of package proxy; the DTW
distance is registered as method="DTW"
(see examples below).
For asymmetric variants, make a crossdist
object with the
two-arguments version of dist
.
dtwDist
computes a dissimilarity matrix, akin to
dist
, based on the Dynamic Time Warping definition of a
distance between single-variate timeseries.
The 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).
A square matrix whose 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
.
Toni Giorgino
Other "distance" functions are: dist
,
vegdist
in package vegan
,
distance
in package analogue
, etc.
## Symmetric step pattern => symmetric dissimilarity matrix; ## no problem coercing it to a dist object: m <- matrix(0,ncol=3,nrow=4) m <- row(m) dist(m,method="DTW"); # Old-fashioned call style would be: # dtwDist(m) # as.dist(dtwDist(m)) ## 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 <- dist(mm,mm,method="DTW",step="asymmetric"); # a crossdist object # Old-fashioned call style would be: # dm <- dtwDist(mm,step=asymmetric) # as.dist(dm) ## Symmetrize by averaging: (dm+t(dm))/2 ## check definition stopifnot(dm[2,1]==dtw(mm[2,],mm[1,],step=asymmetric)$distance)