The dtw Package - NexTag Supports Open Source Initiatives
The dtw Package - NexTag Supports Open Source Initiatives
The dtw Package - NexTag Supports Open Source Initiatives
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Type <strong>Package</strong><br />
Title Dynamic Time Warping algorithms<br />
Version 1.5-3<br />
Date 2008-1-8<br />
Depends proxy<br />
Enhances proxy<br />
<strong>The</strong> <strong>dtw</strong> <strong>Package</strong><br />
February 22, 2008<br />
Author Toni Giorgino , Paolo Tormene <br />
Maintainer Toni Giorgino <br />
Description Comprehensive implementation of Dynamic Time Warping algorithms in R. DTW finds<br />
the optimal (least cumulative distance) mapping between two time series. This package<br />
implements all common DTW variants, including local and global constraints, arbitrary<br />
timeseries lenghts, distance definitions, etc. Methods provides cumulative distance, warping<br />
functions, plots, etc.<br />
License GPL (>=2)<br />
URL http://<strong>dtw</strong>.r-forge.r-project.org/<br />
R topics documented:<br />
aami . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2<br />
<strong>dtw</strong>-internal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3<br />
<strong>dtw</strong>-package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3<br />
<strong>dtw</strong> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4<br />
<strong>dtw</strong>Dist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8<br />
<strong>dtw</strong>Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10<br />
<strong>dtw</strong>PlotThreeWay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12<br />
<strong>dtw</strong>PlotTwoWay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14<br />
<strong>dtw</strong>WindowingFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />
stepPattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17<br />
warp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21<br />
warpArea . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22<br />
1
2 aami<br />
Index 24<br />
aami<br />
ANSI/AAMI EC13 Test Waveforms, 3a and 3b<br />
Description<br />
Usage<br />
Format<br />
Details<br />
Note<br />
<strong>Source</strong><br />
ANSI/AAMI EC13 Test Waveforms 3a and 3b, as obtained from the PhysioBank database.<br />
data(aami3a);<br />
data(aami3b);<br />
> str(aami3a) Time-Series [1:43081] from 0 to 59.8: 0.185 0.185 0.169 0.185 0.185 0.185 0.185<br />
0.185 0.185 0.2 ...<br />
> str(aami3b) Time-Series [1:43142] from 0 to 59.9: 0.192 0.192 0.192 0.192 0.192 0.2 0.2 0.192<br />
0.2 0.2 ...<br />
<strong>The</strong> following text is reproduced (abridged) from PhysioBank, page http://www.physionet.<br />
org/physiobank/database/aami-ec13/. Other recordings belong to the dataset and can<br />
be obtained from the same page.<br />
<strong>The</strong> files in this set can be used for testing a variety of devices that monitor the electrocardiogram.<br />
<strong>The</strong> recordings include both synthetic and real waveforms. For details on these test waveforms and<br />
how to use them, please refer to section 5.1.2.1, paragraphs (e) and (g) in the reference below. Each<br />
recording contains one ECG signal sampled at 720 Hz with 12-bit resolution.<br />
Timestamps in the datasets have been re-created at the indicated frequency of 720 Hz, whereas the<br />
original timestamps in ms (at least in text format) only had three decimal digits’ precision, and were<br />
therefore affected by substantial jittering.<br />
Cardiac monitors, heart rate meters, and alarms [American National Standard (ANSI/AAMI EC13:2002)].<br />
Arlington, VA: Association for the Advancement of Medical Instrumentation, 2002<br />
References<br />
Goldberger AL, Amaral LAN, Glass L, Hausdorff JM, Ivanov PCh, Mark RG, Mietus JE, Moody<br />
GB, Peng CK, Stanley HE. PhysioBank, PhysioToolkit, and PhysioNet: Components of a New<br />
Research Resource for Complex Physiologic Signals. Circulation 101(23):e215-e220 [Circulation<br />
Electronic Pages; http://circ.ahajournals.org/cgi/content/full/101/23/e215];<br />
2000 (June 13).
<strong>dtw</strong>-package 3<br />
Examples<br />
data(aami3a);<br />
data(aami3b);<br />
## Plot both as a multivariate TS object<br />
## only extract the first 10 seconds<br />
plot( main="ECG (mV)",<br />
window(<br />
cbind(aami3a,aami3b)<br />
)<br />
,end=10)<br />
<strong>dtw</strong>-internal<br />
Internal <strong>dtw</strong> Functions<br />
Description<br />
Internal <strong>dtw</strong> functions<br />
Details<br />
<strong>The</strong>se are not to be called by the user. Frontend to the DTW package is the <strong>dtw</strong> function.<br />
<strong>dtw</strong>-package<br />
Dynamic Time Warp algorithms in R<br />
Description<br />
Details<br />
Dynamic Time Warp: find the optimal alignment between two time series.<br />
<strong>Package</strong>: <strong>dtw</strong><br />
Type: <strong>Package</strong><br />
Version: 1.0<br />
Date: 2007-12-10<br />
License: GPL-2<br />
Comprehensive implementation of Dynamic Time Warping (DTW) algorithms in R.<br />
DTW finds the optimal (least cumulative distance) mapping between a given query into a given<br />
template time series.
4 <strong>dtw</strong><br />
Most variants of the algorithm are supported: symmetric, asymmetric and custom step patterns,<br />
with weighting (see stepPattern). <strong>Supports</strong> windowing: none, "Itakura" parallelogram, Sakoe-<br />
Chiba band, custom (see <strong>dtw</strong>WindowingFunctions). Handles query and template of arbitrary<br />
lengths. Multivariate matching and arbitrary definition for a distance function are supported via<br />
user-supplied local distance matrix.<br />
<strong>Package</strong> provides minimum cumulative distance, warping function, plots, etc. A fast, compiled<br />
version of the algorithm is normally used. Should it not be available, a slower pure-R equivalent is<br />
automatically used as a fall-back.<br />
Please see documentation for function <strong>dtw</strong>, which is the main entry point to the package.<br />
If you use this software, please cite it according to citation("<strong>dtw</strong>"). <strong>The</strong> package home page<br />
is at http://<strong>dtw</strong>.r-forge.r-project.org.<br />
To get the latest stable version from CRAN, use install.packages("<strong>dtw</strong>"). To get the development<br />
version (possibly unstable), use install.packages("<strong>dtw</strong>",repos="http://rforge.r-project.org").<br />
Author(s)<br />
Toni Giorgino, Copyright (c) 2007<br />
Maintainer: toni.giorgino@unipv.it<br />
References<br />
TODO<br />
See Also<br />
<strong>dtw</strong> for the main entry point to the package; <strong>dtw</strong>WindowingFunctions for global constraints;<br />
stepPattern for local constraints; distance, outer for building a local cost matrix with<br />
multivariate timeseries and custom distance functions.<br />
Examples<br />
library(<strong>dtw</strong>);<br />
## demo(<strong>dtw</strong>);<br />
<strong>dtw</strong><br />
Dynamic Time Warp<br />
Description<br />
Compute Dynamic Time Warp and find optimal alignment between two time series.
<strong>dtw</strong> 5<br />
Usage<br />
<strong>dtw</strong>(x, y=NULL,<br />
dist.method="Euclidean",<br />
step.pattern="s",<br />
window.type="none",<br />
keep.internals=FALSE,<br />
distance.only=FALSE,<br />
... )<br />
is.<strong>dtw</strong>(d)<br />
Arguments<br />
x<br />
y<br />
dist.method<br />
query vector or local cost matrix<br />
template vector, unused if x given as cost matrix<br />
pointwise (local) distance function. See dist in package proxy<br />
step.pattern step pattern. Character "s" (symmetric1), "a" (asymmetric), or a stepPattern object<br />
describing the local warping steps allowed with their cost (see stepPattern)<br />
window.type windowing function. Character: "none", "itakura", "sakoechiba", "slantedband",<br />
or a function (see details).<br />
keep.internals<br />
don’t discard the cumulative cost matrix and other internal structures<br />
distance.only<br />
only compute distance (no backtrack, faster)<br />
d<br />
Details<br />
an arbitrary R object<br />
... additional arguments, passed to window.type<br />
<strong>The</strong> function performs Dynamic Time Warp (DTW) and computes the optimal alignment between<br />
two time series x and y, given as numeric vectors. <strong>The</strong> “optimal” alignment minimizes the sum of<br />
distances between aligned elements. Lengths of x and y may differ.<br />
<strong>The</strong> (local) distance between elements of x (query) and y (template) is computed passing x and y<br />
to the dist function in package proxy with the method dist.method.<br />
Multivariate time series and arbitrary distance metrics can be handled by supplying a local-distance<br />
matrix. Element [i,j] of the local-distance matrix is understood as the distance between element<br />
x[i] and y[j]. <strong>The</strong> distance matrix has therefore n=length(x) rows and m=length(y)<br />
columns (see note below).<br />
Several common variants of DTW are supported via the step.pattern argument, which defaults<br />
to symmetric1 (White-Neely). Most common step patterns are pre-defined, plus the user can<br />
write their own. See stepPattern for details.<br />
Windowing is supported by supplying a name into the window.type argument (abbreviations<br />
allowed) between the built-in types:<br />
"none" No windowing (default)
6 <strong>dtw</strong><br />
"sakoechiba" A band around main diagonal<br />
"slantedband" A band around slanted diagonal<br />
"itakura" So-called Itakura parallelogram<br />
Value<br />
Note<br />
window.type can also be an user-defined windowing function. See <strong>dtw</strong>WindowingFunctions<br />
for all available windowing functions, details on user-defined windowing, and a discussion of the<br />
(mis)naming of the "Itakura" parallelogram as a global constraint.<br />
Some windowing functions may require parameters, such as the window.size argument.<br />
A native (fast, compiled) version of the function is normally available. If it is not, an interpreted<br />
equivalent will be used as a fall-back, with a warning.<br />
is.<strong>dtw</strong> tests whether the argument is of class <strong>dtw</strong>.<br />
An object of class <strong>dtw</strong> with the following items:<br />
distance<br />
N,M<br />
call<br />
index1<br />
index2<br />
the computed distance not normalized. Normalization depends on the chosen<br />
step pattern.<br />
query and template length<br />
the function call that created the object<br />
matched elements: indices in x<br />
corresponding mapped indices in y<br />
stepPatterns the stepPattern object used for the computation<br />
costMatrix if keep.internals=TRUE, the cumulative cost matrix<br />
directionMatrix<br />
if keep.internals=TRUE, the directions of steps that would be taken at<br />
each alignment pair (integers indexing step patterns)<br />
Cost matrices (both input and output) have query elements row-wise (first index), and template<br />
elements column-wise (second index). <strong>The</strong>y print according to the usual convention, with indexes<br />
increasing down- and rightwards. Many DTW papers and tutorials show matrices according to<br />
plot-like conventions, i.e. template index growing upwards. This may be confusing.<br />
Author(s)<br />
Toni Giorgino<br />
References<br />
Sakoe, H.; Chiba, S., Dynamic programming algorithm optimization for spoken word recognition,<br />
Acoustics, Speech, and Signal Processing [see also IEEE Transactions on Signal Processing], IEEE<br />
Transactions on , vol.26, no.1, pp. 43-49, Feb 1978 URL: http://ieeexplore.ieee.org/<br />
xpls/abs_all.jsp?arnumber=1163055
<strong>dtw</strong> 7<br />
See Also<br />
<strong>dtw</strong>Dist, for iterating <strong>dtw</strong> over a set of timeseries; <strong>dtw</strong>WindowingFunctions, for windowing<br />
and global constraints; stepPattern, step patterns and local constraints; plot.<strong>dtw</strong>, plot<br />
methods for DTW objects. To generate a local distance matrix, the functions dist in package<br />
proxy, distance in package analogue, outer may come handy.<br />
Examples<br />
## A noisy sine wave as query<br />
idx
8 <strong>dtw</strong>Dist<br />
## keep = TRUE so we can look into the cost matrix<br />
alignment
<strong>dtw</strong>Dist 9<br />
Details<br />
Value<br />
<strong>The</strong> <strong>dtw</strong>Dist command is obsolete and has been superseded by the dist function of package<br />
proxy; the DTW distance is registered as method="DTW" (see examples below).<br />
For asymmetric variants, make a crossdist object with the two-arguments version of dist.<br />
<strong>dtw</strong>Dist computes a dissimilarity matrix, akin to dist, based on the Dynamic Time Warping<br />
definition of a distance between single-variate timeseries.<br />
<strong>The</strong> function returns a square matrix, whereas the dist object is lower-triangular. This makes<br />
sense because in general the DTW "distance" is not symmetric (see e.g. asymmetric step patterns).<br />
If a proper dist object is desired, a suitable conversion strategy has to be chosen (see examples).<br />
A square matrix whose element [i,j] holds the Dynamic Time Warp distance between row i<br />
(query) and j (template) of m, i.e. <strong>dtw</strong>(m[i,],m[j,])$distance.<br />
Author(s)<br />
See Also<br />
Toni Giorgino<br />
Other "distance" functions are: dist, vegdist in package vegan, distance in package<br />
analogue, etc.<br />
Examples<br />
## Symmetric step pattern => symmetric dissimilarity matrix;<br />
## no problem coercing it to a dist object:<br />
m
10 <strong>dtw</strong>Plot<br />
(dm+t(dm))/2<br />
## check definition<br />
stopifnot(dm[2,1]==<strong>dtw</strong>(mm[2,],mm[1,],step=asymmetric)$distance)<br />
<strong>dtw</strong>Plot<br />
Plotting of dynamic time warp results<br />
Description<br />
Usage<br />
Methods for plotting dynamic time warp alignment objects returned by <strong>dtw</strong>.<br />
## S3 method for class '<strong>dtw</strong>':<br />
plot(x, type="alignment", ...)<br />
# an alias for <strong>dtw</strong>.plot<br />
<strong>dtw</strong>Plot(x, type="alignment", ...)<br />
<strong>dtw</strong>PlotAlignment(d, xlab="Query index", ylab="Template index", ...)<br />
<strong>dtw</strong>PlotDensity(d, normalize="no",<br />
xlab="Query index", ylab="Template index",<br />
...)<br />
Arguments<br />
x,d<br />
Details<br />
xlab<br />
ylab<br />
type<br />
normalize<br />
<strong>dtw</strong> object, usually result of call to <strong>dtw</strong><br />
label for the query axis<br />
label for the template axis<br />
alignment plot style<br />
show per-step average cost instead of cumulative cost<br />
... additional arguments, passed to plotting functions<br />
<strong>dtw</strong>Plot displays alignment contained in <strong>dtw</strong> objects.<br />
Various plotting styles are available, passing strings to the type argument (may be abbreviated):<br />
alignment plot of the warping curve (may be multi-valued unless the asymmetric-like step pattern is<br />
used)<br />
twoway Point-by-point comparison with matching lines
<strong>dtw</strong>Plot 11<br />
threeway vis-a-vis visual inspection of the original timeseries and their alignment<br />
density show the cumulative cost landscape with the warping path overimposed<br />
For two-way plotting, see documentation for function <strong>dtw</strong>PlotTwoWay.<br />
For three-way plotting, see documentation for function <strong>dtw</strong>PlotThreeWay.<br />
normalize can be one of "N" of "N+M". If set, average cost per step is plotted instead of the<br />
cumulative one. Step averaging depends on the step pattern chosen. N is suitable for asymmetric<br />
patterns and divides the distance by the index in query; N+M is for (normalizable) symmetric<br />
patterns, and divides by the Manhattan distance from the origin.<br />
Additional parameters are carried on to the plotting functions: use with care.<br />
Warning<br />
Note<br />
<strong>The</strong>se functions are incompatible with mechanisms for arranging plots on a device: par(mfrow),<br />
layout and split.screen.<br />
<strong>The</strong> density plot is more colorful than useful.<br />
Author(s)<br />
See Also<br />
Toni Giorgino<br />
<strong>dtw</strong>PlotTwoWay for details on two-way plotting function. <strong>dtw</strong>PlotThreeWay for details on<br />
three-way plotting function.<br />
Examples<br />
## Same example as in <strong>dtw</strong><br />
idx
12 <strong>dtw</strong>PlotThreeWay<br />
## A widely held misconception is that the "Itakura parallelogram" (as<br />
## described in the original article) is a global constraint. Instead,<br />
## it arises from local slope restrictions. Anyway, an "itakuraWindow",<br />
## is provided in this package. A comparison between the two follows.<br />
## <strong>The</strong> local constraint: three sides of the parallelogram are seen<br />
<strong>dtw</strong>(query,template,keep=TRUE,step=asymmetricItakura)->ita;<br />
<strong>dtw</strong>Plot(ita,type="density",<br />
main="Slope-limited asymmetric step (Itakura)")<br />
## Symmetric step with global parallelogram-shaped constraint. Note how<br />
## long (>2 steps) horizontal stretches are allowed within the window.<br />
<strong>dtw</strong>(query,template,keep=TRUE,window=itakuraWindow)->ita;<br />
<strong>dtw</strong>Plot(ita,type="density",<br />
main="Symmetric step with Itakura parallelogram window")<br />
<strong>dtw</strong>PlotThreeWay<br />
Plotting of dynamic time warp results: annotated warping function<br />
Description<br />
Usage<br />
Plot a DTW results for visual inspection.<br />
<strong>dtw</strong>PlotThreeWay(d,xts=NULL,yts=NULL,type.align="p",type.ts="l",<br />
margin=4, inner.margin=0.2, title.margin=1.5,<br />
xlab="Query index",ylab="Template index",main="Timeseries alignment"<br />
... )<br />
Arguments<br />
d<br />
xts<br />
yts<br />
xlab<br />
ylab<br />
main<br />
type.align<br />
type.ts<br />
margin<br />
an alignment result, object of class <strong>dtw</strong><br />
query vector<br />
template vector<br />
label for the query axis<br />
label for the template axis<br />
main title<br />
line style for alignment path plot<br />
line style for timeseries plot<br />
outer figure margin
<strong>dtw</strong>PlotThreeWay 13<br />
inner.margin inner figure margin<br />
title.margin space on the top of figure<br />
... additional arguments, passed to plotting functions<br />
Details<br />
Display the query and template time series and their alignment, arranged so that alignment can be<br />
visually inspected.<br />
Only single-variate time series are supported, and they must be passed to the xts and yts arguments<br />
(query and template are not stored in the <strong>dtw</strong> object).<br />
Warning<br />
<strong>The</strong>se functions are incompatible with mechanisms for arranging plots on a device: par(mfrow),<br />
layout and split.screen.<br />
Note<br />
<strong>The</strong> value axis for the template time series grows rightwards. This may be counter-intuitive.<br />
Author(s)<br />
Toni Giorgino<br />
Examples<br />
## A noisy sine wave as query<br />
## A cosine is for template; sin and cos are offset by 25 samples<br />
idx
14 <strong>dtw</strong>PlotTwoWay<br />
<strong>dtw</strong>PlotTwoWay<br />
Plotting of dynamic time warp results: pointwise comparison<br />
Description<br />
Plot a DTW results for visual inspection.<br />
Usage<br />
<strong>dtw</strong>PlotTwoWay(d,xts=NULL,yts=NULL, offset=0,<br />
type="o",pch=21,<br />
xlab="Index", ylab="Query value",<br />
match.col="gray70",<br />
... )<br />
Arguments<br />
d<br />
xts<br />
yts<br />
Details<br />
xlab,ylab<br />
offset<br />
match.col<br />
type,pch<br />
an alignment result, object of class <strong>dtw</strong><br />
query vector<br />
template vector<br />
axis labels<br />
displacement between the timeseries, summed to template<br />
color of the match lines<br />
graphical parameters for timeseries plotting, passed to matplot<br />
... additional arguments, passed to matplot<br />
Display the query and template time series and their alignment, arranged so that alignment can be<br />
visually inspected.<br />
<strong>The</strong> two vectors are displayed via the matplot functions, and their appearance can be customized<br />
via type and pch arguments (constants or vectors of two elements). If offset is set, the template<br />
is offset by the given amount; this will be reflected by the right-hand axis.<br />
Only single-variate time series can be plotted this way.<br />
Warning<br />
<strong>The</strong>se functions are incompatible with mechanisms for arranging plots on a device: par(mfrow),<br />
layout and split.screen.<br />
Note<br />
Values on the left axis do not reflect the template if offset is set.
<strong>dtw</strong>WindowingFunctions 15<br />
Author(s)<br />
Toni Giorgino<br />
See Also<br />
<strong>dtw</strong>Plot for other <strong>dtw</strong> plotting functions, matplot for graphical parameters.<br />
Examples<br />
## A noisy sine wave as query<br />
## A cosine is for template; sin and cos are offset by 25 samples<br />
idx
16 <strong>dtw</strong>WindowingFunctions<br />
Arguments<br />
iw<br />
jw<br />
index in the query (row) – automatically set<br />
index in the template (column) – automatically set<br />
query.size size of the query time series – automatically set<br />
template.size<br />
size of the template time series – automatically set<br />
window.size<br />
fun<br />
Details<br />
Value<br />
Note<br />
window size, used by some windowing functions – must be set<br />
a windowing function<br />
... additional arguments passed to windowing functions<br />
Windowing functions can be passed to the window.type argument in <strong>dtw</strong> to put a global constraint<br />
to the warping paths allowed. <strong>The</strong>y take two integer arguments (plus optional parameters)<br />
and must return a boolean value TRUE if the coordinates fall within the allowed region for warping<br />
paths, FALSE otherwise.<br />
User-defined functions can read variables template.size, query.size and window.size;<br />
these are pre-set upon invocation. Some functions require additional parameters which must be set<br />
(e.g. window.size). User-defined functions are free to implement any window shape, as long as<br />
at least one path is allowed between the initial and final alignment points, i.e., they are compatible<br />
with the DTW constraints.<br />
<strong>The</strong> sakoeChibaWindow function implements the Sakoe-Chiba band, i.e. window.size elements<br />
around the main diagonal. If the window size is too small, i.e. if template.size −<br />
query.size > window.size, warping becomes impossible.<br />
An itakuraWindow global constraint is still provided with this package. See example below for<br />
a demonstration of the difference between a local the two.<br />
<strong>The</strong> slantedBandWindow (package-specific) is a band centered around the (jagged) line segment<br />
which joins element [1,1] to element [query.size,template.size], and will be<br />
window.size columns wide. In other words, the "diagonal" goes from one corner to the other of<br />
the possibly rectangular cost matrix, therefore having a slope of M/N, not 1.<br />
<strong>dtw</strong>Window.plot visualizes a windowing function. By default it plots a 200 x 220 rectangular<br />
region, which can be changed via template.size and query.size arguments.<br />
Windowing functions return TRUE if the coordinates passed as arguments fall within the chosen<br />
warping window, FALSE otherwise. User-defined functions should do the same.<br />
Although <strong>dtw</strong>Window.plot resembles object-oriented notation, there is not a such a <strong>dtw</strong>Window<br />
class currently.<br />
A widely held misconception is that the "Itakura parallelogram" (as described in reference [2]) is a<br />
global constraint, i.e. a window. To the author’s knowledge, it instead arises from the local slope restrictions<br />
imposed to the warping path, such as the one implemented by the asymmetricItakura<br />
step pattern.
stepPattern 17<br />
Author(s)<br />
Toni Giorgino<br />
References<br />
[1] Sakoe, H.; Chiba, S., Dynamic programming algorithm optimization for spoken word recognition,<br />
Acoustics, Speech, and Signal Processing [see also IEEE Transactions on Signal Processing],<br />
IEEE Transactions on , vol.26, no.1, pp. 43-49, Feb 1978 URL: http://ieeexplore.ieee.<br />
org/xpls/abs_all.jsp?arnumber=1163055<br />
[2] Itakura, F., Minimum prediction residual principle applied to speech recognition, Acoustics,<br />
Speech, and Signal Processing [see also IEEE Transactions on Signal Processing], IEEE Transactions<br />
on , vol.23, no.1, pp. 67-72, Feb 1975. URL: http://ieeexplore.ieee.org/xpls/<br />
abs_all.jsp?arnumber=1162641<br />
Examples<br />
## Display some windowing functions<br />
<strong>dtw</strong>Window.plot(itakuraWindow, main="So-called Itakura parallelogram window")<br />
<strong>dtw</strong>Window.plot(slantedBandWindow, window.size=2,<br />
template=13, query=17, main="<strong>The</strong> slantedBandWindow at window.size=2")<br />
## Asymmetric step with Sakoe-Chiba band<br />
idx
18 stepPattern<br />
Usage<br />
## Well-known step patterns<br />
symmetric1<br />
symmetric2<br />
asymmetric<br />
asymmetricItakura<br />
## Slope-constrained step patterns from Sakoe-Chiba<br />
symmetricP0; asymmetricP0<br />
symmetricP05; asymmetricP05<br />
symmetricP1; asymmetricP1<br />
symmetricP2; asymmetricP2<br />
## Step patterns classified as per Rabiner-Myers<br />
typeIa; typeIb; typeIc; typeId;<br />
typeIas; typeIbs; typeIcs; typeIds; # smoothed<br />
typeIIa; typeIIb; typeIIc; typeIId;<br />
typeIIIc; typeIVc;<br />
## S3 method for class 'stepPattern':<br />
print(x,...)<br />
## S3 method for class 'stepPattern':<br />
plot(x,...)<br />
stepPattern(v)<br />
is.stepPattern(x)<br />
Arguments<br />
x<br />
v<br />
Details<br />
a step pattern object<br />
a vector defining the stepPattern structure (see below)<br />
... additional arguments to print.<br />
A step pattern characterizes the matching model and/or slope constraint specific of a DTW variant.<br />
print.stepPattern prints an user-readable description of the recurrence equation defined by<br />
the given pattern.<br />
plot.stepPattern graphically displays the step patterns productions which can lead to element<br />
(0,0). (Weights are not currently shown.)<br />
Several step patterns are pre-defined with the package:<br />
symmetric1 quasi-symmetric, no slope constraint (favours oblique steps);<br />
symmetric2 properly symmetric, no slope constraint: one diagonal step costs as much as the sum of the<br />
equivalent steps along the sides;
stepPattern 19<br />
asymmetric asymmetric, slope constrained between 0 and 2. Matches each element of the query time<br />
series exactly once, so the warping path index2~index1 is guaranteed to be single-valued;<br />
asymmetricItakura asymmetric, slope contrained 0.5 – 2 from reference [2]. This is the recursive definition that<br />
generates the Itakura parallelogram;<br />
symmetricPx Sakoe’s symmetric, slope contraint x;<br />
asymmetricPx Sakoe’s asymmetric, slope contraint x.<br />
typeNNw Rabiner-Myers classification (see details).<br />
<strong>The</strong> symmetricPx and asymmetricPx slope-constrained patterns are discussed in Sakoe-<br />
Chiba [1], and reproduced as shown in page 47, table I. Values available for P (x) are accordingly:<br />
0 (no constraint), 1, 05 (one half) and 2. See [1] for details.<br />
<strong>The</strong> typeNNw steps follow Rabiner and Myers’ classification given in [3-4]. NN is a roman numeral<br />
specifying the shape of the transitions; w is a letter in the range a-d according the type of<br />
weighting used per step (see table below for meaning); type2 patterns also have a version ending<br />
in s meaning the path smoothing is used (which does not permit skipping points). <strong>The</strong> type1d,<br />
type2d and type2ds are unbiased and symmetric.<br />
rule norm unbiased<br />
--------------------------------<br />
a min step ~N NO<br />
b max step ~N NO<br />
c x step N YES<br />
d x+y step N+M YES<br />
<strong>The</strong> stepPattern constructor is currently not well documented. Please see the example below,<br />
implementing Sakoe’s P=1, Symmetric algorithm.<br />
symmetricP1
20 stepPattern<br />
References<br />
[1] Sakoe, H.; Chiba, S., Dynamic programming algorithm optimization for spoken word recognition,<br />
Acoustics, Speech, and Signal Processing [see also IEEE Transactions on Signal Processing],<br />
IEEE Transactions on , vol.26, no.1, pp. 43-49, Feb 1978 URL: http://ieeexplore.ieee.<br />
org/xpls/abs_all.jsp?arnumber=1163055<br />
[2] Itakura, F., Minimum prediction residual principle applied to speech recognition, Acoustics,<br />
Speech, and Signal Processing [see also IEEE Transactions on Signal Processing], IEEE Transactions<br />
on , vol.23, no.1, pp. 67-72, Feb 1975. URL: http://ieeexplore.ieee.org/xpls/<br />
abs_all.jsp?arnumber=1162641<br />
[3] Rabiner, L. R., & Juang, B.-H. (1993). Fundamentals of speech recognition. Englewood Cliffs,<br />
NJ: Prentice Hall.<br />
[4] Myers, C. S. A Comparative Study Of Several Dynamic Time Warping Algorithms For Speech<br />
Recognition, MS and BS thesis, MIT Jun 20 1980, dspace.mit.edu/bitstream/1721.1/<br />
27909/1/07888629.pdf<br />
Examples<br />
#########<br />
##<br />
## <strong>The</strong> usual (normalizable) symmetric step pattern<br />
## Step pattern recursion, defined as:<br />
## g[i,j] = min(<br />
## g[i,j-1] + d[i,j] ,<br />
## g[i-1,j-1] + 2 * d[i,j] ,<br />
## g[i-1,j] + d[i,j] ,<br />
## )<br />
print.stepPattern(symmetric2)<br />
# or just "symmetric2"<br />
#########<br />
##<br />
## <strong>The</strong> well-known plotting style for step patterns<br />
plot.stepPattern(symmetricP2,main="Sakoe's Symmetric P=2 recursion")<br />
# or just "plot(symmetricP2)"<br />
#########<br />
##<br />
## Same example seen in ?<strong>dtw</strong> , now with asymmetric step pattern<br />
idx
warp 21<br />
<strong>dtw</strong>Plot(asy,type="density",main="Sine and cosine, asymmetric step")<br />
#########<br />
##<br />
## Hand-checkable example given in [4] p 61<br />
##<br />
`tm`
22 warpArea<br />
See Also<br />
Examples in <strong>dtw</strong> show how to graphically apply the warping via parametric plots.<br />
Examples<br />
idx
warpArea 23<br />
Usage<br />
warpArea(d)<br />
Arguments<br />
d<br />
an object of class <strong>dtw</strong><br />
Details<br />
Value<br />
Note<br />
Above- and below- diagonal unit areas all count plus one (they do not cancel with each other).<br />
<strong>The</strong> "diagonal" goes from one corner to the other of the possibly rectangular cost matrix, therefore<br />
having a slope of M/N, not 1, as in slantedBandWindow.<br />
<strong>The</strong> computation is approximate: points having multiple correspondences are averaged, and points<br />
without a match are interpolated. <strong>The</strong>refore, the area can be fractionary.<br />
<strong>The</strong> area, not normalized by path length or else.<br />
<strong>The</strong>re could be alternative definitions to the area, including considering the envelope of the path.<br />
Author(s)<br />
Toni Giorgino<br />
Examples<br />
ds
Index<br />
∗Topic data<br />
aami, 2<br />
∗Topic hplot<br />
<strong>dtw</strong>Plot, 10<br />
<strong>dtw</strong>PlotThreeWay, 12<br />
<strong>dtw</strong>PlotTwoWay, 14<br />
∗Topic internal<br />
<strong>dtw</strong>-internal, 3<br />
∗Topic optimize<br />
<strong>dtw</strong>, 4<br />
∗Topic package<br />
<strong>dtw</strong>-package, 3<br />
∗Topic ts<br />
<strong>dtw</strong>, 4<br />
<strong>dtw</strong>-package, 3<br />
<strong>dtw</strong>Dist, 8<br />
<strong>dtw</strong>Plot, 10<br />
<strong>dtw</strong>WindowingFunctions, 15<br />
stepPattern, 17<br />
warp, 21<br />
warpArea, 22<br />
aami, 2<br />
aami3a (aami), 2<br />
aami3b (aami), 2<br />
asymmetric (stepPattern), 17<br />
asymmetricItakura, 16<br />
asymmetricItakura (stepPattern),<br />
17<br />
asymmetricP0 (stepPattern), 17<br />
asymmetricP05 (stepPattern), 17<br />
asymmetricP1 (stepPattern), 17<br />
asymmetricP2 (stepPattern), 17<br />
backtrack (<strong>dtw</strong>-internal), 3<br />
dist, 5, 7, 9<br />
distance, 4, 7, 9<br />
<strong>dtw</strong>, 3, 4, 4, 8, 10, 15–17, 22<br />
<strong>dtw</strong>-internal, 3<br />
<strong>dtw</strong>-package, 3<br />
<strong>dtw</strong>Dist, 7, 8<br />
<strong>dtw</strong>pairdist (<strong>dtw</strong>-internal), 3<br />
<strong>dtw</strong>Plot, 10, 15<br />
<strong>dtw</strong>PlotAlignment (<strong>dtw</strong>Plot), 10<br />
<strong>dtw</strong>PlotDensity (<strong>dtw</strong>Plot), 10<br />
<strong>dtw</strong>PlotThreeWay, 11, 12<br />
<strong>dtw</strong>PlotTwoWay, 11, 14<br />
<strong>dtw</strong>Window.plot<br />
(<strong>dtw</strong>WindowingFunctions), 15<br />
<strong>dtw</strong>WindowingFunctions, 4, 6, 7, 15<br />
globalCostMatrix (<strong>dtw</strong>-internal), 3<br />
is.<strong>dtw</strong> (<strong>dtw</strong>), 4<br />
is.stepPattern (stepPattern), 17<br />
itakuraWindow<br />
(<strong>dtw</strong>WindowingFunctions), 15<br />
matplot, 14, 15<br />
noWindow (<strong>dtw</strong>WindowingFunctions),<br />
15<br />
outer, 4, 7<br />
plot.<strong>dtw</strong>, 7<br />
plot.<strong>dtw</strong> (<strong>dtw</strong>Plot), 10<br />
plot.stepPattern (stepPattern), 17<br />
print, 18<br />
print.stepPattern (stepPattern),<br />
17<br />
sakoeChibaWindow<br />
(<strong>dtw</strong>WindowingFunctions), 15<br />
slantedBandWindow, 23<br />
slantedBandWindow<br />
(<strong>dtw</strong>WindowingFunctions), 15<br />
stepPattern, 4, 5, 7, 17<br />
symmetric1 (stepPattern), 17<br />
symmetric2 (stepPattern), 17<br />
24
INDEX 25<br />
symmetricP0 (stepPattern), 17<br />
symmetricP05 (stepPattern), 17<br />
symmetricP1 (stepPattern), 17<br />
symmetricP2 (stepPattern), 17<br />
typeIa (stepPattern), 17<br />
typeIas (stepPattern), 17<br />
typeIb (stepPattern), 17<br />
typeIbs (stepPattern), 17<br />
typeIc (stepPattern), 17<br />
typeIcs (stepPattern), 17<br />
typeId (stepPattern), 17<br />
typeIds (stepPattern), 17<br />
typeIIa (stepPattern), 17<br />
typeIIb (stepPattern), 17<br />
typeIIc (stepPattern), 17<br />
typeIId (stepPattern), 17<br />
typeIIIc (stepPattern), 17<br />
typeIVc (stepPattern), 17<br />
vegdist, 9<br />
warp, 21<br />
warpArea, 22