Learn R Programming

dtw (version 0.4-2)

plot.dtw: Plotting of dynamic time warp results

Description

Methods for plotting dynamic time warp alignment objects returned by dtw.

Usage

## S3 method for class 'dtw':
plot(x, type="alignment", ...)

# an alias for dtw.plot dtwPlot(x, type="alignment", ...)

dtwPlotAlignment(d, xlab="Query index", ylab="Template index", ...) dtwPlotDensity(d, normalize="no", xlab="Query index", ylab="Template index", ...)

Arguments

x,d
dtw object, usually result of call to dtw
xlab
label for the query axis
ylab
label for the template axis
type
alignment plot style
normalize
show per-step average cost instead of cumulative cost
...
additional arguments, passed to plotting functions

code

N+M

emph

average

concept

Dynamic Time Warp

Details

dtwPlot displays alignment contained in dtw objects.

Various plotting styles are available, passing strings to the type argument (may be abbreviated):

  • alignment
{simple plot of the warping path} threeway{vis-a-vis visual inspection of the original timeseries and their alignment } density{show the cumulative cost matrix with the warping path overimposed}

See Also

dtwPlotThreeWay for details on three-way plotting function.

Examples

Run this code
## Same example as in dtw

idx<-seq(0,6.28,len=100);
query<-sin(idx)+runif(100)/10;
template<-cos(idx)

alignment<-dtw(query,template,keep=TRUE);


## A profile of the cumulative distance matrix
## Contour plot of the global cost

dtwPlotDensity(alignment, main="Sine/cosine: symmetric  alignment, no constraints")



######

## A study of the "itakura" parallelogram


## A widely held misconception is that the "Itakura parallelogram" 
## (as described in the original article) is a global constraint.
## Instead, it arises from local slope restrictions. Anyway, an "itakuraWindow",
## is provided in this package. A comparison between the two follows.


## The local constraint: three sides of the parallelogram are seen
dtw(query,template,keep=TRUE,step=asymmetricItakura)->ita;
dtwPlot(ita,type="density",main="Slope-limited asymmetric step (Itakura)")

## Symmetric step with global parallelogram-shaped constraint
## Note how long (>2 steps) horizontal stretches are allowed within the window.
dtw(query,template,keep=TRUE,window=itakuraWindow)->ita;
dtwPlot(ita,type="density",main="Symmetric step with Itakura parallelogram window")

Run the code above in your browser using DataLab