stepPattern object lists the transitions
allowed while searching for the minimum-distance path. DTW variants
are implemented by passing one of the objects described in this page
to the stepPattern argument of the dtw call.## Well-known step patterns
symmetric1
symmetric2
asymmetric## Step patterns classified according to Rabiner-Juang [3]
rabinerJuangStepPattern(type,slope.weighting="d",smoothed=FALSE)
## Slope-constrained step patterns from Sakoe-Chiba [1]
symmetricP0; asymmetricP0
symmetricP05; asymmetricP05
symmetricP1; asymmetricP1
symmetricP2; asymmetricP2
## Step patterns classified according to Rabiner-Myers [4]
typeIa; typeIb; typeIc; typeId;
typeIas; typeIbs; typeIcs; typeIds; # smoothed
typeIIa; typeIIb; typeIIc; typeIId;
typeIIIc; typeIVc;
## Miscellaneous
mori2006;
## S3 method for class 'stepPattern':
print(x,...)
## S3 method for class 'stepPattern':
plot(x,...)
## S3 method for class 'stepPattern':
t(x)
stepPattern(v,norm=NA)
is.stepPattern(x)
"a"
to "d" (see [3], sec. 4.7.2.5)print. print.stepPattern prints an user-readable
description of the recurrence equation defined by the given pattern.
plot.stepPattern graphically displays the step patterns
productions which can lead to element (0,0). Weights are
shown along the step leading to the corresponding element.
t.stepPattern transposes the productions and normalization hint
so that roles of query and reference become reversed.
A variety of classifications have been proposed for step patterns,
including Sakoe-Chiba [1]; Rabiner-Juang [3]; and Rabiner-Myers [4].
The dtw package implements all of the transition types found in
those papers, with the exception of Itakura's and Velichko-Zagoruyko's
steps which require subtly different algorithms (this may be rectified
in the future). Itakura recursion is almost, but not quite, equivalent
to typeIIIc.
For convenience, we shall review pre-defined step patterns grouped by
classification. Note that the same pattern may be listed under
different names. Refer to paper [7] for full details.
1. Well-known step patterns
These common transition types are used in quite a lot of implementations.
symmetric1 (or White-Neely) is the commonly used
quasi-symmetric, no local constraint, non-normalizable. It is biased
in favor of oblique steps.
symmetric2 is normalizable, symmetric, with no local slope
constraints. Since one diagonal step costs as much as the two
equivalent steps along the sides, it can be normalized dividing by
N+M (query+reference lengths).
asymmetric is asymmetric, slope constrained between 0 and
2. Matches each element of the query time series exactly once, so
the warping path index2~index1 is guaranteed to
be single-valued. Normalized by N (length of query).
2. The Rabiner-Juang set
A comprehensive table of step patterns is proposed by Rabiner-Juang
[3], tab. 4.5. All of them can be recovered by the
rabinerJuangStepPattern(type,slope.weighting,smoothed)
function.
Seven families, labelled with Roman numerals I-VII, are
selected through the integer argument type. Each family has
four slope weighting sub-types, named in sec. 4.7.2.5 as "Type (a)" to
"Type (d)"; they are selected passing a character argument
slope.weighting, as in the table below. Furthermore, each
subtype can be plain or smoothed (figure 4.44); smoothing is enabled
setting the logical argument smoothed. (Not all combinations
of arguments make sense.)
3. The Sakoe-Chiba set
symmetricPx is the family of Sakoe's symmetric steps, slope
contraint x; asymmetricPx are Sakoe's asymmetric, slope
contraint x. These slope-constrained patterns are discussed in
Sakoe-Chiba [1], and implemented as shown in page 47, table I. Values
available for P (x) are accordingly: 0 (no
constraint), 1, 05 (one half) and 2. See
reference for details.
4. The Rabiner-Myers set
The typeXXx step patterns follow the older Rabiner-Myers'
classification given in [4-5]. Note that they are a subset of the
Rabiner-Juang set [3], which should be preferred to avoid
confusion. XX is a roman numeral specifying the shape of the
transitions; x is a letter in the range a-d according
the type of weighting used per step, as above; typeIIx patterns
also have a version ending in s meaning the path smoothing is
used (which does not permit skipping points). The typeId,
typeIId and typeIIds are unbiased and symmetric.
5. Other
Mori's [6] asymmetric step-constrained pattern is called
mori2006. It is normalized in the reference length.
[2] Itakura, F., Minimum prediction residual principle applied
to speech recognition, Acoustics, Speech, and Signal Processing [see
also IEEE Transactions on Signal Processing], IEEE Transactions on ,
vol.23, no.1, pp. 67-72, Feb 1975. URL:
[3] Rabiner, L. R., & Juang, B.-H. (1993). Fundamentals of speech recognition. Englewood Cliffs, NJ: Prentice Hall.
[4] Myers, C. S. A Comparative Study Of Several Dynamic Time
Warping Algorithms For Speech Recognition, MS and BS thesis, MIT Jun
20 1980,
[5] Myers, C.; Rabiner, L. & Rosenberg, A. Performance tradeoffs in dynamic time warping algorithms for isolated word recognition, IEEE Trans. Acoust., Speech, Signal Process., 1980, 28, 623-635
[6] Mori, A.; Uchida, S.; Kurazume, R.; Taniguchi, R.; Hasegawa, T. &
Sakoe, H. Early Recognition and Prediction of Gestures Proc. 18th
International Conference on Pattern Recognition ICPR 2006, 2006, 3,
560-563
[7] Toni Giorgino. Computing and Visualizing Dynamic Time Warping
Alignments in R: The dtw Package. Journal of Statistical
Software, 31(7), 1-24.
#########
##
## The usual (normalizable) symmetric step pattern
## Step pattern recursion, defined as:
## g[i,j] = min(
## g[i,j-1] + d[i,j] ,
## g[i-1,j-1] + 2 * d[i,j] ,
## g[i-1,j] + d[i,j] ,
## )
print(symmetric2) # or just "symmetric2"
#########
##
## The well-known plotting style for step patterns
plot(symmetricP2,main="Sakoe's Symmetric P=2 recursion")
#########
##
## Same example seen in ?dtw , now with asymmetric step pattern
idx<-seq(0,6.28,len=100);
query<-sin(idx)+runif(100)/10;
reference<-cos(idx);
## Do the computation
asy<-dtw(query,reference,keep=TRUE,step=asymmetric);
dtwPlot(asy,type="density",main="Sine and cosine, asymmetric step")
#########
##
## Hand-checkable example given in [4] p 61
##
`tm` <-
structure(c(1, 3, 4, 4, 5, 2, 2, 3, 3, 4, 3, 1, 1, 1, 3, 4, 2,
3, 3, 2, 5, 3, 4, 4, 1), .Dim = c(5L, 5L))Run the code above in your browser using DataLab