|
Comprehensive implementation of Dynamic Time Warping algorithms in R. Supports arbitrary local (eg symmetric, asymmetric, slope-limited) and global (windowing) constraints, fast native code, several plot styles, and more.
The CRAN Package "dtw" provides the most complete, freely-available (GPL) implementation of Dynamic Time Warping-type algorithms up to date.
The DTW algorithm computes the time axis stretch which optimally maps one timeseries (query) onto another (template); it outputs the resulting cumulative distance between the two inputs, which is frequently used for classification and clustering. The R implementation is fairly comprehensive, allowing choice of:
Multivariate timeseries can be aligned with arbitrary local distance definitions, thanks to the {proxy}dist function. DTW itself registers as a distance function with the dist semantics. In addition to computing alignments, package provides:
## A noisy sine wave as query
idx<-seq(0,6.28,len=100);
query<-sin(idx)+runif(100)/10;
## A cosine is for template; sin and cos are offset by 25 samples
template<-cos(idx)
## Find the best match with the canonical recursion formula
library(dtw);
alignment<-dtw(query,template,keep=TRUE);
## Display the warping curve, i.e. the alignment curve
plot(alignment,type="threeway")
## Align and plot with the Rabiner-Juang type VI-c unsmoothed recursion
plot(
dtw(query,template,keep=TRUE,
step=rabinerJuangStepPattern(6,"c")),
type="twoway",offset=-2);
## See the recursion relation, as a figure and text
plot(rabinerJuangStepPattern(6,"c"))
rabinerJuangStepPattern(6,"c")
## And much more!
Go to a gallery of sample plots (straight out by the examples in the package documentation).
To install the latest stable build of the package (hosted at CRAN),
issue the following command in the R console (automated installs
require R version > 2.6):
> install.packages("dtw");
You are welcome to test the most recent version, hosted at R-forge:
> install.packages("dtw",repos="http://r-forge.r-project.org")
To get started, begin from the installed documentation:
> ?dtw
> ?plot.dtw
The project summary page you can find here.
Much effort has gone in developing this package and making
it public under the GPL license. If you use this software, in
publications or otherwise, you must cite it according
to citation("dtw").
This software is distributed under the terms of the GNU General Public License Version 2, June 1991. The terms of this license are in a file called COPYING which you should have received with this software and which can be displayed by RShowDoc("COPYING").