stepPattern: Step patterns for DTW

Description Usage Arguments Details Note Author(s) References See Also Examples

View source: R/stepPattern.R

Description

A 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.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## S3 method for class 'stepPattern'
t(x)

## S3 method for class 'stepPattern'
plot(x, ...)

## S3 method for class 'stepPattern'
print(x, ...)

rabinerJuangStepPattern(type, slope.weighting = "d", smoothed = FALSE)

Arguments

x

a step pattern object

...

additional arguments to print().

type

path specification, integer 1..7 (see (Rabiner1993), table 4.5)

slope.weighting

slope weighting rule: character "a" to "d" (see (Rabiner1993), sec. 4.7.2.5)

smoothed

logical, whether to use smoothing (see (Rabiner1993), fig. 4.44)

Details

A step pattern characterizes the matching model and slope constraint specific of a DTW variant. They also known as local- or slope-constraints, transition types, production or recursion rules (GiorginoJSS).

Pre-defined step patterns

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
   ## Well-known step patterns
   symmetric1
   symmetric2
   asymmetric
   
   ## Step patterns classified according to Rabiner-Juang (Rabiner1993)
   rabinerJuangStepPattern(type,slope.weighting="d",smoothed=FALSE)
   
   ## Slope-constrained step patterns from Sakoe-Chiba (Sakoe1978)
   symmetricP0;  asymmetricP0
   symmetricP05; asymmetricP05
   symmetricP1;  asymmetricP1
   symmetricP2;  asymmetricP2
   
   ## Step patterns classified according to Rabiner-Myers (Myers1980)
   typeIa;   typeIb;   typeIc;   typeId;
   typeIas;  typeIbs;  typeIcs;  typeIds;  # smoothed
   typeIIa;  typeIIb;  typeIIc;  typeIId;
   typeIIIc; typeIVc;
   
   ## Miscellaneous
   mori2006;
   rigid;

A variety of classification schemes have been proposed for step patterns, including Sakoe-Chiba (Sakoe1978); Rabiner-Juang (Rabiner1993); and Rabiner-Myers (Myers1980). 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 (GiorginoJSS) for full details.

1. Well-known step patterns

Common DTW implementations are based on one of the following transition types.

symmetric2 is the 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). It is widely used and the default.

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).

symmetric1 (or White-Neely) is quasi-symmetric, no local constraint, non-normalizable. It is biased in favor of oblique steps.

2. The Rabiner-Juang set

A comprehensive table of step patterns is proposed in Rabiner-Juang's book (Rabiner1993), tab. 4.5. All of them can be constructed through the rabinerJuangStepPattern(type,slope.weighting,smoothed) function.

The classification foresees seven families, labelled with Roman numerals I-VII; here, they 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 either plain or smoothed (figure 4.44); smoothing is enabled setting the logical argument smoothed. (Not all combinations of arguments make sense.)

1
2
3
4
5
6
  Subtype | Rule       | Norm | Unbiased 
  --------|------------|------|---------
     a    | min step   |  --  |   NO 
     b    | max step   |  --  |   NO 
     c    | Di step    |   N  |  YES 
     d    | Di+Dj step | N+M  |  YES 

3. The Sakoe-Chiba set

Sakoe-Chiba (Sakoe1978) discuss a family of slope-constrained patterns; they are implemented as shown in page 47, table I. Here, they are called symmetricP<x> and asymmetricP<x>, where <x> corresponds to Sakoe's integer slope parameter P. Values available are accordingly: 0 (no constraint), 1, 05 (one half) and 2. See (Sakoe1978) for details.

4. The Rabiner-Myers set

The type<XX><y> step patterns follow the older Rabiner-Myers' classification proposed in (Myers1980) and (MRR1980). Note that this is a subset of the Rabiner-Juang set (Rabiner1993), and the latter should be preferred in order to avoid confusion. <XX> is a Roman numeral specifying the shape of the transitions; <y> is a letter in the range a-d specifying the weighting used per step, as above; typeIIx patterns also have a version ending in s, meaning the smoothing is used (which does not permit skipping points). The typeId, typeIId and typeIIds are unbiased and symmetric.

5. Others

The rigid pattern enforces a fixed unitary slope. It only makes sense in combination with open.begin=TRUE, open.end=TRUE to find gapless subsequences. It may be seen as the P->inf limiting case in Sakoe's classification.

mori2006 is Mori's asymmetric step-constrained pattern (Mori2006). It is normalized by the matched reference length.

mvmStepPattern() implements Latecki's Minimum Variance Matching algorithm, and it is described in its own page.

Methods

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.

Note

Constructing stepPattern objects is tricky and thus undocumented. For a commented example please see source code for symmetricP1.

Author(s)

Toni Giorgino

References

See Also

mvmStepPattern(), implementing Latecki's Minimal Variance Matching algorithm.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#########
##
## 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 [Myers1980] 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))

dtw documentation built on Oct. 23, 2020, 8:11 p.m.