DeepAI
Log In Sign Up

shapeDTW: shape Dynamic Time Warping

Dynamic Time Warping (DTW) is an algorithm to align temporal sequences with possible local non-linear distortions, and has been widely applied to audio, video and graphics data alignments. DTW is essentially a point-to-point matching method under some boundary and temporal consistency constraints. Although DTW obtains a global optimal solution, it does not necessarily achieve locally sensible matchings. Concretely, two temporal points with entirely dissimilar local structures may be matched by DTW. To address this problem, we propose an improved alignment algorithm, named shape Dynamic Time Warping (shapeDTW), which enhances DTW by taking point-wise local structural information into consideration. shapeDTW is inherently a DTW algorithm, but additionally attempts to pair locally similar structures and to avoid matching points with distinct neighborhood structures. We apply shapeDTW to align audio signal pairs having ground-truth alignments, as well as artificially simulated pairs of aligned sequences, and obtain quantitatively much lower alignment errors than DTW and its two variants. When shapeDTW is used as a distance measure in a nearest neighbor classifier (NN-shapeDTW) to classify time series, it beats DTW on 64 out of 84 UCR time series datasets, with significantly improved classification accuracies. By using a properly designed local structure descriptor, shapeDTW improves accuracies by more than 10 datasets. To the best of our knowledge, shapeDTW is the first distance measure under the nearest neighbor classifier scheme to significantly outperform DTW, which had been widely recognized as the best distance measure to date. Our code is publicly accessible at: https://github.com/jiapingz/shapeDTW.

READ FULL TEXT VIEW PDF

page 1

page 2

page 6

page 7

page 10

page 12

page 14

03/04/2019

Making the Dynamic Time Warping Distance Warping-Invariant

The literature postulates that the dynamic time warping (dtw) distance c...
01/24/2023

Parameterizing the cost function of Dynamic Time Warping with application to time series classification

Dynamic Time Warping (DTW) is a popular time series distance measure tha...
11/20/2017

Self-Similarity Based Time Warping

In this work, we explore the problem of aligning two time-ordered point ...
01/15/2021

TC-DTW: Accelerating Multivariate Dynamic Time Warping Through Triangle Inequality and Point Clustering

Dynamic time warping (DTW) plays an important role in analytics on time ...
01/26/2019

Discovery of Important Subsequences in Electrocardiogram Beats Using the Nearest Neighbour Algorithm

The classification of time series data is a well-studied problem with nu...
08/26/2021

Drop-DTW: Aligning Common Signal Between Sequences While Dropping Outliers

In this work, we consider the problem of sequence-to-sequence alignment ...

Code Repositories

SmartSheetMusic

Repository for Niko and Alexis to share stuff


view repo

1 Introduction

Fig. 1: Motivation to incorporate temporal neighborhood structural information into the sequence alignment process. (a) an image matching example: two corresponding points from the image pairs are boxed out and their local patches are shown in the middle. Local patches encode image structures around spatial neighborhoods, and therefore are discriminative for points, while it is hard to match two points solely by their pixel values. (b) two time series with several similar local structures, highlighted as bold segments. (c) DTW alignment: DTW fails to align similar local structures. (d) shapeDTW alignment: we achieve a more interpretable alignment, with similarly-shaped local structures matched.
Fig. 2: Pipeline of shapeDTW. shapeDTW consists of two major steps: encode local structures by shape descriptors and align descriptor sequences by DTW. Concretely, we sample a subsequence from each temporal point, and further encode it by some shape descriptor. As a result, the original time series is converted into a descriptor sequence of the same length. Then we align two descriptor sequences by DTW and transfer the found warping path to the original time series.

Dynamic time warping (DTW) is an algorithm to align temporal sequences, which has been widely used in speech recognition [29], human motion animation [15], human activity recognition [22] and time series classification [6]. DTW allows temporal sequences to be locally shifted, contracted and stretched, and under some boundary and monotonicity constraints, it searches for a global optimal alignment path. DTW is essentially a point-to-point matching algorithm, but it additionally enforces temporal consistencies among matched point pairs. If we distill the matching component from DTW, the matching is executed by checking the similarity of two points based on their Euclidean distance. Yet, matching points based solely on their coordinate values is unreliable and prone to error, therefore, DTW may generate perceptually nonsensible alignments, which wrongly pair points with distinct local structures (see Fig.1 (c)). This partially explains why the nearest neighbor classifier under the DTW distance measure is less interpretable than the shapelet classifier [35]: although DTW does achieve a global minimal score, the alignment process itself takes no local structural information into account, possibly resulting in an alignment with little semantic meaning. In this paper, we propose a novel alignment algorithm, named shape Dynamic Time Warping (shapeDTW), which enhances DTW by incorporating point-wise local structures into the matching process. As a result, we obtain perceptually interpretable alignments: similarly-shaped structures are preferentially matched based on their degree of similarity. We further quantitatively evaluate alignment paths against the ground-truth alignments, and shapeDTW achieves much lower alignment errors than DTW on both simulated and real sequence pairs. An alignment example by shapeDTW is shown in Fig.1 (d).

Point matching is a well studied problem in the computer vision community, widely known as image matching. In order to search corresponding points from two distinct images taken from the same scene, a quite naive way is to compare their pixel values. But pixel values at a point lacks spatial neighborhood context, making it less discriminative for that point; e.g., a tree leaf pixel from one image may have exactly the same RGB values as a grass pixel from the other image, but these two pixels are not corresponding pixels and should not be matched. Therefore, a routine for image matching is to describe points by their surrounding image patches, and then compare the similarities of point descriptors. Since point descriptors designed in this way encode image structures around local neighborhoods, they are more distinctive and discriminative than single pixel values. In early days, raw image patches were used as point descriptors

[1], and now more powerful descriptors like SIFT [27] are widely adopted since they capture local image structures very well and are invariant to image scale and rotation.

Intuitively, local neighborhood patches make points more discriminative from other points, while matching based on RGB pixel values is brittle and results in high false positives. However, the matching component in the traditional DTW bears the same weakness as image matching based on single pixel values, since similarities between temporal points are measured by their coordinates, instead of by their local neighborhoods. An analogous remedy for temporal matching hence is: first encode each temporal point by some descriptor, which captures local subsequence structural information around that point, and then match temporal points based on the similarity of their descriptors. If we further enforce temporal consistencies among matchings, then comes the algorithm proposed in the paper: shapeDTW.

shapeDTW is a temporal alignment algorithm, which consists of two sequential steps: (1) represent each temporal point by some shape descriptor, which encodes structural information of local subsequences around that point; in this way, the original time series is converted into a sequence of descriptors. (2) use DTW to align two sequences of descriptors. Since the first step takes linear time while the second step is a typical DTW, which takes quadratic time, the total time complexity is quadratic, indicating that shapeDTW has the same computational complexity as DTW. However, compared with DTW and its variants (derivative Dynamic Time Warping (dDTW) [19] and weighted Dynamic Time Warping (wDTW)[17]), it has two clear advantages: (1) shapeDTW obtains lower alignment errors than DTW/dDTW/wDTW on both artificially simulated aligned sequence pairs and real audio signals; (2) the nearest neighbor classifier under the shapeDTW distance measure (NN-shapeDTW) significantly beats NN-DTW on 64 out of 84 UCR time series datasets [6]. NN-shapeDTW outperforms NN-dDTW/NN-wDTW significantly as well. Our shapeDTW time series alignment procedure is shown in Fig. 2.

Extensive empirical experiments have shown that a nearest neighbor classifier with the DTW distance measure (NN-DTW) is the best choice to date for most time series classification problems, since no alternative distance measures outperforms DTW significantly [34, 30, 28]. However, in this paper, the proposed temporal alignment algorithm, shapeDTW, if used as a distance measure under the nearest neighbor classifier scheme, significantly beats DTW. To the best of our knowledge, shapeDTW is the first distance measure that outperforms DTW significantly.

Our contributions are several fold: (1) we propose a temporal alignment algorithm, shapeDTW, which is as efficient as DTW (dDTW, wDTW) but achieves quantitatively better alignments than DTW (dDTW, wDTW); (2) Working under the nearest neighbor classifier as a distance measure to classify 84 UCR time series datasets, shapeDTW, under all tested shape descriptors, outperforms DTW significantly; (3) shapeDTW provides a quite generic alignment framework, and users can design new shape descriptors adapted to their domain data characteristics and then feed them into shapeDTW for alignments.

2 Related work

Since shapeDTW is developed for sequence alignment, here we first review research work related to sequence alignment. DTW is a typical sequence alignment algorithm, and there are many ways to improve DTW to obtain better alignments. Traditionally, we could enforce global warping path constraints to prevent pathological warpings [29], and several typical such global warping constraints include Sakoe-Chiba band and Itakura Parallelogram. Similarly, we could choose to use different step patterns in different applications: apart from the widely used step pattern - “symmetric1”, there are other popular steps patterns like “symmetric2”, “asymmetric” and “RabinerJuangStepPattern” [13]. However, how to choose an appropriate warping band constraint and a suitable step pattern depends on our prior knowledge on the application domains.

There are several recent works to improve DTW alignment. In [19], to get the intuitively correct “feature to feature” alignment between two sequences, the authors introduced derivative dynamic time warping (dDTW), which computes first-order derivatives of time series sequences, and then aligns two derivative sequences by DTW. In [17], the authors developed weighted DTW (wDTW), which is a penalty-based DTW. wDTW takes the phase difference between two points into account when computing their distances. Batista et al [3] proposed a complexity-invariant distance measure, which essentially rectifies an existing distance measure (e.g., Euclidean, DTW) by multiplying a complexity correction factor. Although they achieve improved results on some datasets by rectifying the DTW measure, they do not modify the original DTW algorithm. In [23], the authors proposed to learn a distance metric, and then align temporal sequences by DTW under this new metric. One major drawback is the requirement of ground truth alignments for metric learning, because in reality true alignments are usually unavailable. In [5], the authors proposed to utilize time series local structure information to constrain the search of the warping path. They introduce a SIFT-like feature point detector and descriptor to detect and match salient feature points from two sequences first, and then use matched point pairs to regularize the search scope of the warping path. Their major initiative is to improve the computational efficiency of dynamic time warping by enforcing band constraints on the potential warping paths, such that they do not have to compute the full accumulative distance matrix between the two sequences. Our method is sufficiently different from theirs in following aspects: first, we have no notion of feature points, while feature points are key to their algorithm, since feature points help to regularize downstream DTW; second, our algorithm aims to achieve better alignments, while their algorithm attempts to improve the computational efficiency of the traditional DTW. In [28], the authors focus on improving the efficiency of the nearest neighbor classifier under the DTW distance measure, but they keep the traditional DTW algorithm unchanged.

Our algorithm, shapeDTW, is different from the above works in that: we measure similarities between two points by computing similarities between their local neighborhoods, while all the above works compute the distance between two points based on their single-point y-values (derivatives).

Since shapeDTW can be applied to classify time series (e.g., NN-shapeDTW), we review representative time series classification algorithms. In [25], the authors use the popular Bag-of-Words to represent time series instances, and then classify the representations under the nearest neighbor classifier. Concretely, it discretizes time series into local SAX [24] words, and uses the histogram of SAX words as the time series representation. In [31]

, the authors developed an algorithm to first extract class-membership discriminative shapelets, and then learn a decision tree classifier based on distances between shapelets and time series instances. In

[33], they first represent time series using recurrent plots, and then measure the similarity between recurrence plots using Campana-Keogh (CK-1) distance (PRCD). PRCD distance is used as the distance measure under the one-nearest neighbor classifier to do classification. In [4]

, a bag-of-feature framework to classify time series is introduced. It uses a supervised codebook to encode time series instances, and then uses random forest classifier to classify the encoded time series. In

[14], the authors first encode time series as a bag-of-patterns, and then use polynomial kernel SVM to do the classification. Zhao and Itti [37]

proposed to first encode time series by the 2nd order encoding method - Fisher Vectors, and then classify encoded time series by a linear kernel SVM. In their paper, subsequences are sampled from both feature points and flat regions.

shapeDTW is different from above works in that: shapeDTW is developed to align temporal sequences, but can be further applied to classify time series. However, all above works are developed to classify time series, and they are incapable to align temporal sequences at their current stages. Since time series classification is only one application of shapeDTW, we compare NN-shapeDTW against the above time series classification algorithms in the supplementary materials.

The paper is organized as follows: the detailed algorithm for shapeDTW is introduced in Sec.3, and in Sec.4 we introduce several local shape descriptors. Then we extensively test shapeDTW for both sequence alignments and time series classification in Sec. 6, and conclusions are drawn in Sec.7.

3 shape Dynamic Time Warping

In this section, we introduce a temporal alignment algorithm, shapeDTW. First we introduce DTW briefly.

3.1 Dynamic Time Warping

DTW is an algorithm to search for an optimal alignment between two temporal sequences. It returns a distance measure for gauging similarities between them. Sequences are allowed to have local non-linear distortions in the time dimension, and DTW handles local warpings to some extent. DTW is applicable to both univariate and multivariate time series, and here for simplicity we introduce DTW in the case of univariate time series alignment.

A univariate time series is a sequence of real values, i.e., . Given two sequences and of possible different lengths and , namely and , and let be an pairwise distance matrix between sequences and , where is the distance between and . One widely used pairwise distance measure is the Euclidean distance, i.e., . The goal of temporal alignment between and is to find two sequences of indices and of the same length , which match index in the time series to index in the time series , such that the total cost along the matching path is minimized. The alignment path is constrained to satisfies boundary, monotonicity and continuity conditions [32, 20, 12]:

(1)

Given an alignment path , we define two warping matrices and for and respectively, such that , otherwise , and similarly , otherwise . Then the total cost along the matching path is equal to , thus searching for the optimal temporal matching can be formulated as the following optimization problem:

(2)

Program 2 can be solved efficiently in time by a dynamic programming algorithm [10]. Various different moving patterns and temporal window constraints [32] can be enforced, but here we consider DTW without warping window constraints and taking moving patterns as in (1).

3.2 shape Dynamic Time Warping

DTW finds a global optimal alignment under certain constraints, but it does not necessarily achieve locally sensible matchings. Here we incorporate local shape information around each point into the dynamic programming matching process, resulting in more semantically meaningful alignment results, i.e., points with similar local shapes tend to be matched while those with dissimilar neighborhoods are unlikely to be matched. shapeDTW consists of two steps: (1) represent each temporal point by some shape descriptor; and (2) align two sequences of descriptors by DTW. We first introduce the shapeDTW alignment framework, and in the next section, we introduce several local shape descriptors.

Given a univariate time series , shapeDTW begins by representing each temporal point by a shape descriptor , which encodes structural information of temporal neighborhoods around , in this way, the original real value sequence is converted to a sequence of shape descriptors of the same length, i.e., . shapeDTW then aligns the transformed multivariate descriptor sequences by DTW, and at last the alignment path between descriptor sequences is transferred to the original univariate time series sequences. We give implementation details of shapeDTW:

Given a univariate time series of length , e.g.,, we first extract a subsequence of length from each temporal point . The subsequence is centered on , with its length typically much smaller than (

). Note we have to pad both ends of

by with duplicates of to make subsequences sampled at endpoints well defined. Now we obtain a sequence of subsequences, i.e., , with corresponding to the temporal point . Next, we design shape descriptors to express subsequences, under the goal that similarly-shaped subsequences have similar descriptors while differently-shaped subsequences have distinct descriptors. The shape descriptor of subsequence naturally encodes local structural information around the temporal point , and is named as shape descriptor of the temporal point as well. Designing a shape descriptor boils down to designing a mapping function , which maps subsequence to shape descriptor , i.e., , so that similarity between descriptors can be measured simply with the Euclidean distance. Different mapping functions define different shape descriptors, and one straightforward mapping function is the identity function (), in this case, , i.e., subsequence itself acts as local shape descriptor. Given a shape descriptor computation function , we convert the subsequence sequence to a descriptor sequence , i.e., . At last, we use DTW to align two descriptor sequences and transfer the warping path to the original univariate time series.

Given two univariate time series and , let and be their shape descriptor sequences respectively, shapeDTW alignment is equivalent to solving the optimization problem:

(3)

Where and are warping matrices of and , and is the -norm of matrix, i.e., , where is the row of matrix . Program 3 is a multivariate time series alignment problem, and can be effectively solved by dynamic programming in time . The key difference between DTW and shapeDTW is that: DTW measures similarities between and by their Euclidean distance , while shapeDTW uses the Euclidean distance between their shape descriptors, i.e., , as the similarity measure. shapeDTW essentially handles local non-linear warping, since it is inherently DTW, and, on the other hand, it prefers matching points with similar neighborhood structures to points with similar values. shapeDTW algorithm is described in Algo.1.

Inputs: univariate time series and ; subsequence length ; shape descriptor function

shapeDTW:

1. Sample subsequences: ;

2. Encode subsequences by shape descriptors:

;

3. Align descriptor sequences and by DTW.

Outputs:

warping matrices: and ;

shapeDTW distance:

Algorithm 1 shape Dynamic Time Warping

4 Shape descriptors

shapeDTW provides a generic alignment framework, and users can design shape descriptors adapted to their domain data characteristics and feed them into shapeDTW for alignments. Here we introduce several general shape descriptors, each of which maps a subsequence to a vector representation , i.e., .

The length of subsequences defines the size of neighborhoods around temporal points. When , no neighborhood information is taken into account. With increasing , larger neighborhoods are considered, and in the extreme case when ( is the length of the time series), subsequences sampled from different temporal points become the same, i.e., the whole time series, in which case, shape descriptors of different points resemble each other too much, making temporal points less identifiable by shape descriptors. In practice, is set to some appropriate value. But in this section, we first let be any positive integers (), which does not affect the definition of shape descriptors. In Sec.6, we will experimentally explore the sensitivity of NN-shapeDTW to the choice of .

4.1 Raw-Subsequence

Raw subsequence sampled around point can be directly used as the shape descriptor of , i.e., , where is the identity function. Although simple, it inherently captures the local subsequence shape and helps to disambiguate points with similar values but different local shapes.

4.2 Paa

Piecewise aggregate approximation (PAA) is introduced in [18, 36] to approximate time series. Here we use it to approximate subsequences. Given a -dimensional subsequence , it is divided into () equal-lengthed intervals, the mean value of temporal points falling within each interval is calculated and a vector of these mean values gives the approximation of and is used as the shape descriptor of , i.e., .

4.3 Dwt

Discrete Wavelet Transform (DWT) is another widely used technique to approximate time series instances. Again, here we use DWT to approximate subsequences. Concretely, we use a Haar wavelet basis to decompose each subsequence into 3 levels. The detail wavelet coefficients of all three levels and the approximation coefficients of the third level are concatenated to form the approximation, which is used the shape descriptor of , i.e., .

4.4 Slope

All the above three shape descriptors encode local shape information inherently. However, they are not invariant to y-shift, to be concrete, given two subsequences of exactly the same shape, but is a y-shifted relative to , e.g., , where is the magnitude of y-shift, then their shape descriptors under Raw-Subsequence, PAA and DWT differ approximately by as well, i.e., . Although magnitudes do help time series classification, it is also desirable that similarly-shaped subsequences have similar descriptors. Here we further exploit three shape descriptors in experiments, Slope, Derivative and HOG1D, which are invariant to y-shift.

Slope is extracted as a feature and used in time series classification in [4, 8]. Here we use it to represent subsequences. Given a -dimensional subsequence , it is divided into () equal-lengthed intervals. Within each interval, we employ the total least square (TLS) line fitting approach [11] to fit a line according to points falling within that interval. By concatenating the slopes of the fitted lines from all intervals, we obtain a -dimensional vector representation, which is the slope representation of , i.e., .

4.5 Derivative

Similar to Slope, Derivative is y-shift invariant if it is used to represent shapes. Given a subsequence , its first-order derivative sequence is , where is the first order derivative according to time . To keep consistent with derivatives used in derivative Dynamic Time Warping [19] (dDTW), we follow their formula to compute numeric derivatives.

4.6 Hog1d

HOG1D is introduced in [37] to represent 1D time series sequences. It inherits key concepts from the histogram of oriented gradients (HOG) descriptor [7], and uses concatenated gradient histograms to represent shapes of temporal sequences. Similarly to Slope and Derivative descriptors, HOG1D is invariant to y-shift as well.

In experiments, we divide a subsequence into 2 non-overlapping intervals, compute gradient histograms (under 8 bins) in each interval and concatenate two histograms as the HOG1D descriptor (a 16D vector) of that subsequence. We refer interested readers to [37] for computation details of HOG1D. We have to emphasize that: in [37], the authors introduce a global scaling factor and tune it using all training sequences; but here, we fix to be 0.1 in all our experiments, therefore, HOG1D computation on one subsequence takes only linear time , where is the length of that subsequence. See our published code for details.

4.7 Compound shape descriptors

Shape descriptors, like HOG1D, Slope and Derivative, are invariant to y-shift. However, in the application of matching two subsequences, y-magnitudes may sometimes be important cues as well, e.g., DTW relies on point-wise magnitudes for alignments. Shape descriptors, like Raw-Subsequence, PAA and DWT, encode magnitude information, thus they complement y-shift invariant descriptors. By fusing pure-shape capturing and magnitude-aware descriptors, the compound descriptor has the potential to become more discriminative of subsequences. In the experiments, we generate compound descriptors by concatenating two complementary descriptors, i.e., , where is a weighting factor to balance two simple descriptors, and is the generated compound descriptor.

5 Alignment quality evaluation

Here we adopt the “mean absolute deviation” measure used in the audio literature [21] to quantify the proximity between two alignment paths. “Mean absolute deviation” is defined as the mean distance between two alignment paths, which is positively proportional to the area between two paths. Intuitively, two spatially proximate paths have small between-areas, therefore low “Mean absolute deviation”. Formally, given a reference sequence , a target sequence and two alignment paths between them, the Mean absolute deviation between and is calculate as: , where is the area between and and is the length of the reference sequence . Fig. 3 shows two alignment paths , blue and red curves, between and . is the area of the slashed region, and in practice, it is computed by counting the number of cells falling within it. Here a cell refers to the position in the pairwise distance matrix between and .

Fig. 3: Mean absolute deviation”, which measures the proximity between alignment paths. The red and blue curves are two alignment paths between sequences and , and “Mean absolute deviation” between these two paths is defined as: the area of the slashed region divided by the length of the reference sequence .

6 Experimental validation

We test shapeDTW for sequence alignment and time series classification extensively on 84 UCR time series datasets [6] and the Bach10 dataset [9]. For sequence alignment, we compare shapeDTW against DTW and its other variants both qualitatively and quantitatively: specifically, we first visually compare alignment results returned by shapeDTW and DTW (and its variants), and then quantify their alignment path qualities on both synthetic and real data. Concretely, we simulate aligned pairs by artificially scaling and stretching original time series sequences, align those pairs by shapeDTW and DTW (and its variants), and then evaluate the alignment paths against the ground-truth alignments. We further evaluate the alignment performances of shapeDTW and DTW (and its variants) on audio signals, which have the ground-truth point-to-point alignments. For time series classification, since it is widely recognized that the nearest neighbor classifier with the distance measure DTW (NN-DTW) is very effective and is hard to beaten [34, 2], we use the nearest neighbor classifier as well to test the effectiveness of shapeDTW (NN-shapeDTW), and compare NN-shapeDTW against NN-DTW. We further compare NN-shapeDTW against six other state-of-the-art classification algorithms in the supplementary materials.

6.1 Sequence alignment

We evaluate sequence alignments qualitatively in Sec. 6.1.2 and quantitatively in Sec. 6.1.3 and Sec. 6.1.4. We compare shapeDTW against DTW, derivative Dynamic Time Warping (dDTW) [19] and weighted Dynamic Time Warping (wDTW)[17]. dDTW first computes derivative sequences, and then aligns them by DTW. wDTW uses a weighted distance, instead of the regular distance, to compute distances between points, and the weight accounts for the phase differences between points. wDTW is essentially a DTW algorithm. Here, both dDTW and wDTW are variants of the original DTW. Before the evaluation, we briefly introduce some popular step patterns in DTW.

6.1.1 Step pattern in DTW

Step pattern in DTW defines the allowed transitions between matched pairs, and the corresponding weights. In both Program. 2 (DTW) and Program. 3 (shapeDTW), we use the default step pattern, whose recursion formula is . In the following alignment experiments, we try other well-known step patterns as well, and we follow the naming convention in [13] to name these step-patterns. Five popular step-patterns, “symmetric1”, “symmetric2”, “symmetric5”, “asymmetric” and “rabinerJuang”, are listed in Fig. 4. Step-pattern (a), “symmetric1”, is the one used by shapeDTW in all the following alignment and classification experiments, and we will not explicitly mention that in following texts.

Fig. 4: Five step patterns. Numbers on transitions indicate the multiplicative weight for the local distance . Step-pattern (a) “symmetric1” is the default step pattern for DTW and (b) gives more penalties to the diagonal directions, such that the warping favors stair-stepping paths. Step patterns (a) and (b) obtain a continuous warping path, while step patterns (c), (d) and (e) may result in skipping elements, i.e., some temporal points from one sequence are not matched to any points from the other sequence, and vice verse.

6.1.2 Qualitative alignment assessment

We plot alignment results by shapeDTW and DTW/dDTW, and evaluate them visually. shapeDTW under 5 shape descriptors, Raw-Subsequence, PAA, DWT, Derivative and HOG1D, obtains similar alignment results, here we choose Derivative as a representative to report results, with the subsequence length set to be 30. Here, shapeDTW, DTW and dDTW all use step pattern (a) in Fig. 4.

Time series with rich local features: time series with rich local features, such as those in the “OSUleaf” dataset (bottom row in Fig.5), have many bumps and valleys; DTW becomes quite brittle to align such sequences, since it matches two points based on their single-point y-magnitudes. Because single magnitude value does not incorporate local neighborhood information, it is hard for DTW to discriminate a peak point from a valley point with the same magnitude, although and have dramatically different local shapes. dDTW bears similar weakness as DTW, since it matches points bases on their derivative differences and does not take local neighborhood into consideration either. On the contrary, shapeDTW distinguishes peaks from valleys easily by their highly different local shape descriptors. Since shapeDTW takes both non-linear warping and local shapes into account, it gives more perceptually interpretable and semantically sensible alignments than DTW (dDTW). Some typical alignment results of time series from feature rich datasets “OSUleaf” and “Fish” are shown in Fig.5.

Fig. 5: Alignments between time series with rich local features. Time series at the top and bottom row are from “Fish”(train-165, test-1) and “OSUleaf”(test-114, test-134) datasets respectively. In each pair of time series, temporal points with similar local structures are boxed out by rectangles. Perceptually, shapeDTW aligns these corresponding points better than both DTW and dDTW.

6.1.3 Simulated sequence-pair alignment

We simulate aligned sequence pairs by scaling and stretching original time series. Then we run shapeDTW and DTW (and its variants) to align the simulated pairs, and compare their alignment paths against the ground-truth. In this section, shapeDTW is run under the fixed settings: (1) fix the subsequence length to be 30, (2) use Derivative as the shape descriptor and (3) use “symmetric1” as the step-pattern.

concretely, given a time series of length , we simulate a new time series by locally scaling and stretching . The simulation consists of two sequential steps: (1) scaling: scale point-wisely, resulting in a new time series , where is a positive scale vector with the same length as , and is a point-wise multiplication operator; (2) stretching: randomly choose percent of temporal points from , stretch each point by a random length and result in a new time series . and are a simulated alignment pair, with the ground-truth alignment known from the simulation process. The simulation algorithm is described in Alg. 2.

One caveat we have to pay attention to is that: scaling an input time series by a random scale vector can make the resulting time series perceptually quite different from the original one, such that simulated alignment pairs make little sense. Therefore, in practice, a scale vector should be smooth, i.e., adjacent elements in cannot be random, instead, they should be similar in magnitude, making adjacent temporal points from the original time series be scaled by a similar amount. In experiments, we first use a random process, which is similar to Brownian motion, to initialize scale vectors, and then recursively smooth it. The scale vector generation algorithm is shown in Alg. 2. As seen, adjacent scales are initialized to be differed by at most 1 (i.e., ), such that the first order derivatives are bounded and initialized scale vectors do not change abruptly. Initialized scale vectors usually have local bumps, and we further recursively utilize cumulative summation and sine-squashing, as described in the algorithm, to smooth the scale vectors. Finally, the smoothed scale vectors are linearly squashed into a positive range .

After non-uniformly scaling an input time series by a scale vector, we obtain a scale-transformed new sequence, and then we randomly pick percent of points from the new sequence and stretch each of them by some random amount . Stretching at point by some amount is to duplicate by times.

Inputs: a time series instance ; scale vector range , smoothing iterations ; stretching percentage , stretching amount

1. simulate a scale vector ;

2. scale point-wisely, ;

3. stretching percent of points from by a random amount , resulting in a simulated time series .

Outputs:

Simulate a scale vector:

Inputs: length , iteration , range

1.Initialize:

2.smoothing:

while iteration

a. set the cumulative sum up to as the scale at :

b. squash scale at into the range :

,

end

3. squash elements in the scale vector into range by linear scaling.

Outputs: a scale vector

Algorithm 2 simulate alignment pairs

using training data from each UCR dataset as the original time series, we simulate their alignment pairs by running Alg. 2. Since there are 27,136 training time series instances from 84 UCR datasets, we simulate 27,136 aligned-pairs in total. We fix most simulation parameters as follows: , , , and the stretching percentage is the only flexible parameter we will vary, e.g., when , each original input time series is on average stretched by (in length). Typical scale vectors and simulated alignment pairs are shown in Fig. 6. The scale vectors are smooth and the simulated time series are both scaled and stretched, compared with the original ones.

Fig. 6: Alignments between simulated time series pairs. (a) simulated scale vectors: they are smooth and squashed to the range ; (b) a simulated alignment pair: generated by artificially scale and stretch the original time series; (c) dDTW alignment: run dDTW to align the simulated pair; (d) ground truth alignment; (e) shapeDTW alignment. The plot on the right shows alignment paths of dDTW, shapeDTW and the ground-truth, visually the alignment path of shapeDTW is closer to the ground-truth, and quantitatively, shapeDTW has 1.1 alignment errors in terms of “Mean Absolute Deviation” score, compared with 4.7 of dDTW.

we run shapeDTW and DTW/dDTW/wDTW to align simulated pairs, and compare alignment paths against the ground-truth in terms of “Mean Absolute Deviation” scores. DTW and dDTW are parameter-free, but wDTW has one tuning parameter (see Eq. (3) in their paper), which controls the curvature of the logistic weight function. However in the case of aligning two sequences, is impossible to be tuned and should be pre-defined by experiences. Here we fix to be 0.1, which is the approximate mean value of the optimal in the original paper. For the purpose of comparing the alignment qualities of different algorithms, we use the default step pattern, (a) in Fig. 4, for both shapeDTW and DTW/dDTW/wDTW, but we further evaluate effects of different step-patterns in the following experiments.

We simulate alignment pairs by stretching raw time series by different amounts, , , , and , and report the alignment qualities of shapeDTW and DTW/dDTW/wDTW under each stretching amount in terms of the mean of “Mean Absolute Deivation” scores over 27,136 simulated pairs. The results are shown in Fig. 7, which shows shapeDTW achieves lower alignment errors than DTW / dDTW / wDTW over different stretching amounts consistently. shapeDTW almost halves the alignment errors achieved by dDTW, although dDTW already outperforms its two competitors, DTW and wDTW, by a large margin.

Fig. 7: Alignment quality comparison between shapeDTW and DTW/dDTW/wDTW, under the step pattern “symmetric1”. As seen, as the stretching amount increases, the alignment qualities of both shapeDTW and DTW/dDTW/wDTW drop. However, shapeDTW consistently achieves lower alignment errors under different stretching amounts, compared with DTW, dDTW and wDTW.

choosing a suitable step pattern is a traditionally way to improve sequence alignments, and it usually needs domain knowledge to make the right choice. Here, instead of choosing an optimal step pattern, we run DTW/dDTW/wDTW under all 5 step patterns in Fig. 4 and compare their alignment performances against shapeDTW. Similar as the above experiments, we simulate aligned-pairs under different amounts of stretches, report alignment errors under different step patterns in terms of the mean of “Mean Absolute Deivation” scores over 27,136 simulated pairs, and plot the results in Fig. 8. As seen, different step patterns obtain different alignment qualities, and in our case, step patterns, “symmetric1” and “asymmetric”, have similar alignment performances and they reach lower alignment errors than the other 3 step patterns. However, shapeDTW still wins DTW/dDTW/wDTW (under “symmetric1” and “asymmetric” step-patterns) by some margin.

Fig. 8: Align sequences under different step patterns. We align sequence-pairs by DTW/dDTW/wDTW under 5 different step patterns (Fig. 4), “symmetric1”, “symmetric2”, “symmetric5”, “asymmetric” and “rabinerJuang”, and compare their alignment errors against those obtained by shapeDTW. As seen, different step patterns usually reach different alignment results, which shows the importance of choosing an appropriate step pattern adapted to the application domain. In our case, “asymmetric” step pattern achieves slightly lower errors than “symmetric1” step pattern (under DTW, wDTW and dDTW), however, shapeDTW consistently wins DTW/dDTW/wDTW under the best step pattern - “asymmetric”.
Mean Absolute Deviation from the ground-truth alignments
mean std. mean std.
datasets shapeDTW dDTW shapeDTW dDTW datasets shapeDTW dDTW shapeDTW dDTW
50words 1.49 2.85 1.03 2.14 MedicalImages 0.93 2.14 0.66 2.05
Adiac 1.77 5.73 0.61 2.45 MiddlePhalanxOutlineAgeGroup 0.47 0.80 0.18 0.30
ArrowHead 0.94 1.70 0.48 0.91 MiddlePhalanxOutlineCorrect 0.46 0.81 0.18 0.27
Beef 0.85 1.86 0.22 0.83 MiddlePhalanxTW 0.53 0.91 0.27 0.39
BeetleFly 0.69 2.22 0.16 0.80 MoteStrain 0.78 1.07 0.31 0.85
BirdChicken 1.11 2.35 0.85 1.65 NonInvasiveFatalECG-Thorax1 0.65 0.72 0.24 0.49
Car 1.83 6.34 1.74 3.21 NonInvasiveFatalECG-Thorax2 0.80 1.06 0.51 0.89
CBF 0.60 0.13 0.28 0.03 OliveOil 1.89 3.90 0.79 0.69
ChlorineConcentration 0.64 0.23 0.18 0.24 OSULeaf 0.69 1.92 0.17 0.94
CinC-ECG-torso 0.69 0.67 0.33 0.92 PhalangesOutlinesCorrect 0.62 1.04 0.29 0.49
Coffee 0.69 1.36 0.17 0.41 Phoneme 0.69 0.89 0.52 5.37
Computers 11.18 10.73 12.62 13.10 Plane 0.51 1.44 0.16 0.59
Cricket-X 0.64 0.18 0.17 0.07 ProximalPhalanxOutlineAgeGroup 0.60 1.15 0.29 0.52
Cricket-Y 0.65 0.19 0.16 0.07 ProximalPhalanxOutlineCorrect 0.61 1.14 0.29 0.49
Cricket-Z 0.65 0.19 0.15 0.06 ProximalPhalanxTW 0.56 1.08 0.26 0.49
DiatomSizeReduction 2.21 7.43 1.15 2.82 RefrigerationDevices 1.28 1.21 1.33 1.53
DistalPhalanxOutlineAgeGroup 0.57 0.88 0.27 0.49 ScreenType 11.26 11.00 11.29 11.70
DistalPhalanxOutlineCorrect 0.57 0.85 0.30 0.49 ShapeletSim 0.60 0.20 0.17 0.10
DistalPhalanxTW 0.60 0.85 0.25 0.44 ShapesAll 1.13 3.07 0.79 2.65
Earthquakes 0.97 0.77 0.59 0.76 SmallKitchenAppliances 15.77 15.88 11.67 12.16
ECG200 0.61 0.22 0.25 0.15 SonyAIBORobotSurface 0.63 0.18 0.16 0.11
ECG5000 0.67 0.24 0.25 0.13 SonyAIBORobotSurfaceII 0.79 0.16 0.28 0.06
ECGFiveDays 0.78 0.26 0.33 0.15 Strawberry 0.71 1.07 0.17 0.47
FaceAll 0.54 0.23 0.19 0.11 SwedishLeaf 0.65 1.36 0.29 1.25
FaceFour 0.64 0.16 0.10 0.07 Symbols 2.20 6.04 1.73 4.17
FacesUCR 0.55 0.25 0.17 0.12 synthetic-control 0.54 0.12 0.59 0.07
FISH 2.64 10.56 1.16 3.33 ToeSegmentation1 0.69 0.36 0.17 0.19
FordA 0.50 0.59 0.07 0.20 ToeSegmentation2 0.65 0.45 0.22 0.42
FordB 0.50 0.64 0.07 0.15 Trace 0.62 0.25 0.24 0.22
Gun-Point 1.36 5.95 0.65 2.86 TwoLeadECG 0.78 0.78 0.23 0.39
Ham 0.73 0.63 0.13 0.29 Two-Patterns 0.63 0.35 0.22 0.17
HandOutlines 7.08 22.92 6.86 6.92 UWaveGestureLibraryAll 1.13 2.45 0.79 2.57
Haptics 1.37 2.00 0.70 1.19 uWaveGestureLibrary-X 1.44 3.69 1.62 4.02
Herring 0.97 3.44 0.40 1.45 uWaveGestureLibrary-Y 1.39 3.98 1.33 4.48
InlineSkate 0.68 0.19 0.16 0.09 uWaveGestureLibrary-Z 1.52 4.07 1.52 4.44
InsectWingbeatSound 1.09 3.06 0.64 3.98 wafer 1.08 5.26 0.58 3.36
ItalyPowerDemand 0.60 0.25 0.39 0.16 Wine 1.25 2.00 0.26 0.45
LargeKitchenAppliances 19.88 20.38 12.03 15.98 WordsSynonyms 1.57 2.89 1.23 2.29
Lighting2 1.71 3.20 0.58 2.72 WordSynonyms 1.48 2.92 1.04 2.50
Lighting7 1.23 1.90 0.40 1.68 Worms 0.65 1.00 0.12 3.48
MALLAT 2.45 3.98 0.50 0.99 WormsTwoClass 0.64 2.77 0.11 18.75
Meat 2.10 3.32 0.72 0.71 yoga 1.23 5.26 0.65 2.92
TABLE I: Alignment errors of shapeDTW vs dDTW. We use training data from each UCR dataset as the original time series, and simulate alignment pairs by scaling and streching the original time series (stretched by ). Then we run shapeDTW and dDTW to align these synthesized alignment pairs, and evaluate the alignment paths against the ground-truth by computing “Mean Absolute Deviation

” scores. The mean and standard deviation of the “

Mean Absolute Deviation” scores on each dataset is documented, with smaller means and stds in bold font. shapeDTW achieves lower “Mean Absolute Deviation” scores than dDTW on 56 datasets, showing its clear advantage for time series alignment.

From the above simulation experiments, we observe dDTW (under the step patterns “symmetric1” and “asymmetric”) has the closest performance as shapeDTW. Here we simulate aligned-pairs with on average stretches, run dDTW (under “symmetric1” step pattern) and shapeDTW alignments, and report the “Mean Absolute Deviation” scores in Table I. shapeDTW has lower “Mean Absolute Deivation” scores on 56 datasets, and the mean of “Mean Absolute Deivation” on 84 datasets of shapeDTW and dDTW are 1.68/2.75 respectively, indicating shapeDTW achieves much lower alignment errors. This shows a clear superiority of shapeDTW to dDTW for sequence alignment.

The key difference between shapeDTW and DTW/dDTW/wDTW is that whether neighborhood is taken into account when measuring similarities between two points. We demonstrate that taking local neighborhood information into account (shapeDTW) does benefit the alignment.

Notes: before running shapeDTW and DTW variants alignment, two sequences in a simulated pair are z-normalized in advance; when computing “Mean Absolute Deviation”, we choose the original time series as the reference sequence, i.e., divide the area between two alignment paths by the length of the original time series.

Fig. 9: Align audio and midi-2-audio sequences. (a) top: the audio waveform of the Chorale ’05-DieNacht’ and its 5D MFCCs features; bottom: the converted audio waveform from the MIDI score of the Chorale ’05-DieNacht’ and its corresponding 5D MFCCs features; (b) alignment paths: align two MFCCs sequences by DTW, dDTW and shapeDTW, and the plot shows their alignment paths, together with the ground-truth alignment. As seen, the alignment paths of dDTW and shapeDTW are closer to the ground-truth than that of DTW. (c) “Mean Absolute Deviation” from the ground truth alignment: on 9 (10) out of 10 chorales, shapeDTW achieves smaller alignment errors than dDTW (DTW), showing that shapeDTW outperforms DTW/dDTW to align real sequence pairs as well.

6.1.4 MIDI-to-audio alignment

We showed the superiority of shapeDTW to align synthesized alignment pairs, and in this section, we further empirically demonstrate its effectiveness to align audio signals, which have ground-truth alignments.

The Bach10 dataset [9] consists of audio recordings of 10 pieces of Bach’s Chorales, as well as their MIDI scores and the ground-truth alignment between the audio and the MIDI score. MIDI scores are symbolic representations of audio files, and by aligning symbolic MIDI scores with audio recordings, we can do musical information retrieval from MIDI input-data [16]. Many previous work used DTW to align MIDI to audio sequences [16, 9, 12], and they typically converted MIDI data into audios as a first step, and the problem boils down to audio-to-audio alignment, which is then solved by DTW. We follow this convention to convert MIDI to audio first, but run shapeDTW instead for alignments.

Each piece of music is approximately 30 seconds long, and in experiments, we segment both the audio and the converted audio from MIDI data into frames of 46ms length with a hopsize of 23ms, extract features from each 46ms frame window, and in this way, the audio is represented as a multivariate time series with the length equal to the number of frames and dimension equal to the feature dimensions. There are many potential choices of frame features, but how to select and combine features in an optimal way to improve the alignment is beyond the scope of this paper, we refer the interested readers to [21, 12]. Without loss of generality, we use Mel-frequency cepstral coefficients (MFCCs) as features, due to its common usage and good performance in speech recognition and musical information retrieval [26]. In our experiments, we use the first 5 MFCCs coefficients.

After MIDI-to-audio conversion and MFCCs feature extraction, MIDI files and audio recordings are represented as 5-dimensional multivariate time series, with approximately length

. A typical audio signal, MIDI-converted audio signal, and their 5D MFCCs features are shown in Fig. 9. We align 5D MFCCs sequences by shapeDTW: although shapeDTW is designed for univariate time series alignments, it naturally extends to multivariate cases: first extract a subsequence from each temporal point, then encode subsequences by shape descriptors, and in this way, the raw multivariate time series is converted to a descriptor sequence. In the multivariate time series case, each extracted subsequence is multi-dimensional, having the same dimension as the raw time series, and to compute the shape descriptor of a multi-dimensional subsequence, we compute shape descriptors of each dimension independently, concatenate all shape descriptors, and use it as the shape representation of that subsequence.

We compare alignments by shapeDTW against DTW/dDTW, and all of them use the “symmetric1” step pattern. The length of subsequences in shapeDTW is fixed to be 20 (we tried 5,10, 30 as well and achieved quite similar results), and Derivative is used as the shape descriptor. The alignment qualities in terms of “Mean Absolute Deviation” on 10 Chorales are plotted in Fig. 9. To be consistent with the convention in the audio community, we actually report the mean-delayed-second between the alignment paths and the ground-truth. The mean-delayed-second is computed as: dividing “Mean Absolute Deviation” by the sampling rate of the audio signal. shapeDTW outperforms dDTW/DTW on 9/10 MIDI-to-audio alignments. This shows taking local neighborhood information into account does benefit the alignment.

Fig. 10: Classification accuracy comparisons between NN-DTW and NN-shapeDTW on 84 UCR time series datasets. shapeDTW under 4 shape descriptors, Raw-Subsequence, PAA, DWT and HOG1D, outperforms DTW on 64/63/64/61 datasets respectively, and Wilcoxon signed rank test shows shapeDTW under all descriptors performs significantly better than DTW. Raw-Subsequence (PAA and DWT as well) outperforms DTW on more datasets than HOG1D does, but HOG1D achieves large accuracy improvements on more datasets, concretely, HOG1D boosts accuracies by more than on 18 datasets, compared with on 12 datasets by Raw-Subsequence.

6.2 Time series classification

We compare NN-shapeDTW with NN-DTW on 84 UCR time series datasets for classification. Since these datasets have standard partitions of training and test data, we experiment with these given partitions and report classification accuracies on the test data.

In the above section, we explore the influence of different steps patterns, but here both DTW and shapeDTW use the widely adopted step pattern “symmetric1”(Fig. 4 (a)) under no temporal window constraints to align sequences.

NN-DTW: each test time series is compared against the training set, and the label of the training time series with the minimal DTW distance to that test time series determines the predicted label. All training and testing time series are z-normalized in advance.

shapeDTW: we test all 5 shape descriptors. We z-normalize time series in advance, sample subsequences from the time series, and compute 3 magnitude-aware shape descriptors, Raw-Subsequence, PAA and DWT, and 2 y-shift invariant shape descriptors, Slope and HOG1D. Parameter setting for 5 shape descriptors: (1) The length of subsequences to be sampled around temporal points is fixed to 30, as a result Raw-Subsequence descriptor is a 30D vector; (2) PAA and Slope uses 5 equal-lengthed intervals, therefore they have the dimensionality 5; (3) As mentioned, HOG1D uses 8 bins and 2 non-overlapping intervals, and the scale factor is fixed to be 0.1. At last HOG1D is a 16D vector representation.

NN-shapeDTW: first transform each training/testing time series to a shape descriptor sequence, and in this way, original univariate time series are converted into multivariate descriptor time series. Then apply NN-DTW on the multivariate time series to predict labels.

NN-shapeDTW vs. NN-DTW: we compare NN-shapeDTW, under 4 shape descriptors Raw-Subsequence, PAA, DWT and HOG1D, with NN-DTW, and plot their classification accuracies on 84 datasets in Fig.10. shapeDTW outperforms (including ties) DTW on 64/63/64/61 (Raw-Subsequence/PAA/DWT/HOG1D) datasets, and by running the Wilcoxon signed rank test between performances of NN-shapeDTW and NN-DTW, we obtain p-values ///, showing that shapeDTW under all 4 descriptors performs significantly better than DTW. Compared with DTW, shapeDTW has a preceding shape descriptor extraction process, and approximately takes time , where and is the length of subsequence and time series respectively. Since generally , the total time complexity of shapeDTW is , which is the same as DTW. By trading off a slight amount of time and space, shapeDTW brings large accuracy gains.

Since PAA and DWT are approximations of Raw-Subsequence, and they have similar performances as Raw-Subsequence under the nearest classifier, we choose Raw-Subsequence as a representative for following analysis. Shape descriptor Raw-Subsequence loses on 20 datasets, on 18 of which it has minor losses (), and on the other 2 datasets, “Computers” and “Synthetic-control”, it loses by and . Time series instances from these 2 datasets either have high-frequency spikes or have many abrupt direction changes, making them resemble noisy signals very much. Possibly, comparing the similarity of two points using their noisy neighborhoods is not as good as using their single coordinate values (DTW), since temporal neighborhood may accumulate and magnify noise.

HOG1D loses on 23 datasets, on 18 of which it has minor losses (), and on the other 5 datasets, “CBF”, “Computers”, “ItalyPowerDemand”, “Synthetic-control” and “Wine”, it loses by , , , and . By visually inspecting, time series from “Computers”, “CBF” and “Synthetic-control” are spiky and bumpy, making them highly non-smooth. This makes the first-order-derivative based descriptor HOG1D inappropriate to represent local structures. Time series instances from ’ItalyPowerDemand’ have length 24, while we sample subsequences of length 30 from each point, this makes HOG1D descriptors from different local points almost the same, such that HOG1D becomes not discriminative of local structures. This makes shapeDTW inferior to DTW. Although HOG1D loses on more datasets than Raw-Subsequence, HOG1D boosts accuracies by more than on 18 datasets, compared with on 12 datasets by Raw-Subsequence. On datasets “OSUleaf” and “BirdChicken”, the accuracy gain is as high as and . By checking these two datasets closely, we find different classes have membership-discriminative local patterns (a.k.a shapelets [35]), however, these patterns differ only slightly among classes. Raw-Subsequence shape descriptor can not capture these minor differences well, while HOG1D is more sensitive to shape variations since it calculates derivatives.

Both Raw-Subsequence and HOG1D bring significant accuracy gains, however, they boost accuracies to different extents on the same dataset. This indicates the importance of designing domain-specific shape descriptors. Nevertheless, we show that even by using simple and dataset-independent shape descriptors, we still obtain significant improvements over DTW. Classification error rates of DTW, Raw-Subsequence and HOG1D on 84 datasets are documented in Table.II.

Superiority of Compound shape descriptors: as mentioned in Sec.4, a compound shape descriptor obtained by fusing two complementary descriptors may inherit benefits from both descriptors, and becomes even more discriminative of subsequences. As an example, we concatenate a y-shift invariance descriptor HOG1D and a magnitude-aware descriptor DWT using equal weights, resulting in a compound descriptor . Then we evaluate classification performances of 3 descriptors under the nearest neighbor classifier, and plot the comparisons in Fig.11. HOG1D+DWT outperforms (including ties) HOG1D / DWT on 66/51 (out of 84) datasets, and by running the Wilcoxon signed rank hypothesis test between performances of HOG1D+DWT and HOG1D (DWT), we get p-values /, showing the compound descriptor outperforms individual descriptors significantly under the confidence level . We can generate compound descriptors by weighted concatenation, with weights tuned by cross-validation on training data, but this is beyond the scope of this paper.

Fig. 11: Performance comparisons between the fused descriptor HOG1D+DWT and individual ones HOG1D/DWT. HOG1D+DWT outperforms HOG1D/DWT

on 66/51 (out of 84) datasets, and statistical hypothesis tests show the improvements are significant.

Texas Sharpshooter plot: although NN-shapeDTW performs better than NN-DTW, knowing this is not useful unless we can tell in advance on which problems it will be more accurate, as stated in [3]. Here we use the Texas sharpshooter plot [3] to show when NN-shapeDTW has superior performance on the test set as predicted from performance on the training set, compared with NN-DTW. We run leave-one-out cross validation on training data to measure the accuracies of NN-shapeDTW and NN-DTW, and we calculate the expected gain: accuracy(NN-shapeDTW)/accuracy(NN-DTW). We then measure the actual accuracy gain using the test data. The Texas Sharpshooter plots between Raw-Subsequence/HOG1D and DTW on 84 datasets are shown in Fig.12. / points (Raw-Subsequence/HOG1D) fall in the TP and TN regions, which means we can confidently predict that our algorithm will be superior/inferior to NNDTW. There are respectively 7/7 points falling inside the FP region for descriptors Raw-Subsequence/HOG1D, but they just represent minor losses, i.e., actual accuracy gains lie within .

Fig. 12: Texas sharpshoot plot between Raw-Subsequence/HOG1D and DTW on 84 datasets. TP: true positive (our algorithm was expected from the training data to outperform NNDTW, and it actually did on the test data). TN: true negatives, FP: false positives, FN: false negatives. There are / points (Raw-Subsequence/HOG1D vs. DTW) falling in the TP and TN regions, which indicates we can confidently predict that our algorithm will be superior/inferior to NNDTW.

6.3 Sensitivity to the size of neighborhood

In the above experiments, we showed that shapeDTW outperforms DTW both qualitatively and quantitatively. But we are still left with one free-parameter: the size of neighborhood, i.e., the length of the subsequence to be sampled from each point. Let be some temporal point on the time series , and be the subsequence sampled at . When , shapeDTW (under the Raw-Subsequence shape descriptor) degenerates to DTW; when , subsequences sampled at different points become almost identical, make points un-identifiable by their shape descriptors. This shows the importance to set an appropriate subsequence length. However, without dataset-specific domain knowledge, it is hard to determine the length intelligently. Here instead, we explore the sensitivity of the classification accuracies to different subsequence lengths. We conduct experiments on 42 old UCR datasets.

We use Raw-Subsequence

as the shape descriptor, and NN-shapeDTW as the classifier. We let the length of subsequences to vary from 5 to 100, with stride 5, i.e., we repeat classification experiments on each dataset for 20 times, and each time set the length of subsequences to be

, where is the index of experiments (). The test accuracies under 20 experiments are shown by a box plot ( Fig.13). On 33 out of 42 datasets, even the worst performances of NN-shapeDTW are better than DTW, indicating shapeDTW performs well under wide ranges of neighborhood sizes.

Fig. 13: Performances of shapeDTW are insensitive to the neighborhood size. The green stairstep curve shows dataset-wise test accuracies of NN-DTW, and the box plot shows performances of NN-shapeDTW under the shape descriptor Raw-Subsequence. On each dataset, we plot a blue box with two tails: the lower and upper edge of each blue box represent and percentiles of 20 test accuracies (obtained under different neighborhood sizes, i.e., 5, 10, 15, …, 100) on that dataset, with the red line inside the box marking the median accuracy and two tails indicating the best and worst test accuracies. On 36 out of 42 datasets, the median accuracies of NN-shapeDTW are larger than accuracies obtained by NN-DTW, and on 33 datasets, even the worst performances by NN-shapeDTW are better than NN-DTW. All these statistics show shapeDTW works well under wide ranges of neighborhood sizes.
classification error rates on 84 UCR datasets
datasets DTW Raw-Subsequence HOG1D datasets DTW Raw-Subsequence HOG1D
50words 0.310 0.202 0.242 MedicalImages 0.263 0.254 0.264
Adiac 0.396 0.335 0.269 MiddlePhalanxOutlineAgeGroup 0.250 0.260 0.260
ArrowHead 0.297 0.194 0.177 MiddlePhalanxOutlineCorrect 0.352 0.240 0.250
Beef 0.367 0.400 0.267 MiddlePhalanxTW 0.416 0.429 0.429
BeetleFly 0.300 0.300 0.200 MoteStrain 0.165 0.101 0.110
BirdChicken 0.250 0.250 0.050 NonInvasiveFatalECG-Thorax1 0.209 0.223 0.219
Car 0.267 0.117 0.133 NonInvasiveFatalECG-Thorax2 0.135 0.110 0.140
CBF 0.003 0.016 0.080 OliveOil 0.167 0.133 0.100
ChlorineConcentration 0.352 0.355 0.355 OSULeaf 0.409 0.289 0.132
CinC-ECG-torso 0.349 0.248 0.209 PhalangesOutlinesCorrect 0.272 0.235 0.261
Coffee 0.000 0.036 0.036 Phoneme 0.772 0.761 0.736
Computers 0.300 0.400 0.356 Plane 0.000 0.000 0.000
Cricket-X 0.246 0.221 0.208 ProximalPhalanxOutlineAgeGroup 0.195 0.234 0.210
Cricket-Y 0.256 0.226 0.226 ProximalPhalanxOutlineCorrect 0.216 0.192 0.206
Cricket-Z 0.246 0.205 0.208 ProximalPhalanxTW 0.263 0.282 0.275
DiatomSizeReduction 0.033 0.039 0.069 RefrigerationDevices 0.536 0.549 0.507
DistalPhalanxOutlineAgeGroup 0.208 0.223 0.233 ScreenType 0.603 0.611 0.525
DistalPhalanxOutlineCorrect 0.232 0.247 0.228 ShapeletSim 0.350 0.328 0.028
DistalPhalanxTW 0.290 0.277 0.290 ShapesAll 0.232 0.163 0.112
Earthquakes 0.258 0.183 0.258 SmallKitchenAppliances 0.357 0.363 0.301
ECG200 0.230 0.140 0.100 SonyAIBORobotSurface 0.275 0.261 0.193
ECG5000 0.076 0.070 0.071 SonyAIBORobotSurfaceII 0.169 0.136 0.174
ECGFiveDays 0.232 0.079 0.057 Strawberry 0.060 0.059 0.051
FaceAll 0.192 0.217 0.238 SwedishLeaf 0.208 0.128 0.085
FaceFour 0.170 0.102 0.091 Symbols 0.050 0.031 0.039
FacesUCR 0.095 0.034 0.081 synthetic-control 0.007 0.073 0.153
FISH 0.177 0.051 0.051 ToeSegmentation1 0.228 0.171 0.101
FordA 0.438 0.316 0.279 ToeSegmentation2 0.162 0.100 0.138
FordB 0.406 0.337 0.261 Trace 0.000 0.010 0.000
Gun-Point 0.093 0.013 0.007 TwoLeadECG 0.096 0.078 0.006
Ham 0.533 0.457 0.457 Two-Patterns 0.000 0.000 0.001
HandOutlines 0.202 0.191 0.206 UWaveGestureLibraryAll 0.108 0.046 0.058
Haptics 0.623 0.575 0.562 uWaveGestureLibrary-X 0.273 0.224 0.263
Herring 0.469 0.375 0.500 uWaveGestureLibrary-Y 0.366 0.309 0.358
InlineSkate 0.616 0.587 0.629 uWaveGestureLibrary-Z 0.342 0.314 0.338
InsectWingbeatSound 0.645 0.533 0.584 wafer 0.020 0.008 0.010
ItalyPowerDemand 0.050 0.037 0.103 Wine 0.426 0.389 0.537
LargeKitchenAppliances 0.205 0.184 0.160 WordsSynonyms 0.351 0.245 0.260
Lighting2 0.131 0.131 0.115 WordSynonyms 0.351 0.245 0.260
Lighting7 0.274 0.178 0.233 Worms 0.536 0.503 0.475
MALLAT 0.066 0.064 0.062 WormsTwoClass 0.337 0.293 0.287
Meat 0.067 0.067 0.100 yoga 0.164 0.133 0.117
TABLE II: Error rates of NN-DTW and NN-shapeDTW (under descriptors Raw-Subsequence and HOG1D) on 84 UCR datasets. The error rates on datasets where NN-shapeDTW outperforms NN-DTW are highlighted in bold font. Underscored datasets are those on which shapeDTW has improved the accuracies by more than .

7 Conclusion

We have proposed an new temporal sequence alignment algorithm, shapeDTW, which achieves quantitatively better alignments than DTW and its variants. shapeDTW is a quite generic framework as well, and uses can design their own local subsequence descriptor and fit it into shapeDTW. We experimentally showed that shapeDTW under the nearest neighbor classifier obtains significantly improved classification accuracies than NN-DTW. Therefore, NN-shapeDTW sets a new accuracy baseline for further comparison.

Acknowledgments

This work was supported by the National Science Foundation (grant number CCF-1317433), the Office of Naval Research (N00014-13-1-0563) and the Army Research Office (W911NF-11-1-0046 and W911NF-12-1-0433). The authors affirm that the views expressed herein are solely their own, and do not represent the views of the United States government or any agency thereof.

References

  • [1] S. Agarwal and D. Roth. Learning a sparse representation for object detection. In ECCV, pages 113–127. Springer, 2002.
  • [2] A. Bagnall and J. Lines. An experimental evaluation of nearest neighbour time series classification. arXiv preprint arXiv:1406.4757, 2014.
  • [3] G. Batista, X. Wang, and E. Keogh. A complexity-invariant distance measure for time series. In SDM, volume 11, pages 699–710, 2011.
  • [4] M. Baydogan, G. Runger, and E. Tuv. A bag-of-features framework to classify time series. PAMI, 35(11):2796–2802, 2013.
  • [5] S. Candan, R. Rossini, X. Wang, and M. Sapino. sdtw: computing dtw distances using locally relevant constraints based on salient feature alignments. Proceedings of the VLDB Endowment, 5(11):1519–1530, 2012.
  • [6] Y. Chen, E. Keogh, B. Hu, N. Begum, A. Bagnall, A. Mueen, and G. Batista. The ucr time series classification archive, July 2015. www.cs.ucr.edu/~eamonn/time_series_data/.
  • [7] N. Dalal and B. Triggs. Histograms of oriented gradients for human detection. In CVPR, volume 1, pages 886–893. IEEE, 2005.
  • [8] H. Deng, G. Runger, E. Tuv, and M. Vladimir. A time series forest for classification and feature extraction. Information Sciences, 239:142–153, 2013.
  • [9] Z. Duan and B. Pardo. Soundprism: An online system for score-informed source separation of music audio. IEEE Journal of Selected Topics in Signal Processing, 5(6):1205–1215, 2011.
  • [10] D. Ellis. Dynamic time warp (dtw) in matlab, 2003. www.ee.columbia.edu/~dpwe/resources/matlab/dtw/.
  • [11] David A Forsyth and Jean Ponce. A modern approach. Computer Vision: A Modern Approach, pages 88–101, 2003.
  • [12] D. Garreau, R. Lajugie, S. Arlot, and F. Bach. Metric learning for temporal sequence alignment. In NIPS, pages 1817–1825, 2014.
  • [13] T. Giorgino. Computing and visualizing dynamic time warping alignments in r: the dtw package. Journal of statistical Software, 31(7):1–24, 2009.
  • [14] J. Grabocka and L. Schmidt-Thieme. Invariant time-series factorization. DMKD, 28(5-6):1455–1479, 2014.
  • [15] E. Hsu, K. Pulli, and J. Popović. Style translation for human motion. ACM Transactions on Graphics, 24(3):1082–1089, 2005.
  • [16] N. Hu, R. Dannenberg, and G. Tzanetakis. Polyphonic audio matching and alignment for music retrieval. Computer Science Department, page 521, 2003.
  • [17] Y. Jeong, M. Jeong, and O. Omitaomu. Weighted dynamic time warping for time series classification. Pattern Recognition, 44(9):2231–2240, 2011.
  • [18] E. Keogh, K. Chakrabarti, M. Pazzani, and S. Mehrotra. Dimensionality reduction for fast similarity search in large time series databases. Knowledge and information Systems, 3(3):263–286, 2001.
  • [19] E. Keogh and M. Pazzani. Derivative dynamic time warping. In SDM, volume 1, pages 5–7. SIAM, 2001.
  • [20] E. Keogh and C. Ratanamahatana. Exact indexing of dynamic time warping. Knowledge and information systems, 7(3):358–386, 2005.
  • [21] H. Kirchhoff and A. Lerch. Evaluation of features for audio-to-audio alignment. Journal of New Music Research, 40(1):27–41, 2011.
  • [22] K. Kulkarni, G. Evangelidis, J. Cech, and R. Horaud. Continuous action recognition based on sequence alignment. IJCV, pages 1–25, 2014.
  • [23] R. Lajugie, D. Garreau, F. Bach, and S. Arlot. Metric learning for temporal sequence alignment. In NIPS, pages 1817–1825, 2014.
  • [24] J. Lin, E. Keogh, S. Lonardi, and B. Chiu. A symbolic representation of time series, with implications for streaming algorithms. In SIGMOD workshop, pages 2–11. ACM, 2003.
  • [25] J. Lin, R. Khade, and Y. Li. Rotation-invariant similarity in time series using bag-of-patterns representation. Journal of Intelligent Information Systems, 39(2):287–315, 2012.
  • [26] Beth Logan et al. Mel frequency cepstral coefficients for music modeling. In ISMIR, 2000.
  • [27] D. Lowe. Distinctive image features from scale-invariant keypoints. IJCV, 60(2):91–110, 2004.
  • [28] F. Petitjean, G. Forestier, G Webb, A Nicholson, Y. Chen, and E. Keogh. Dynamic time warping averaging of time series allows faster and more accurate classification. In ICDM, 2014.
  • [29] L. Rabiner and B. Juang. Fundamentals of speech recognition, volume 14. PTR Prentice Hall Englewood Cliffs, 1993.
  • [30] T. Rakthanmanon, B. Campana, A. Mueen, G. Batista, B. Westover, Q. Zhu, J. Zakaria, and E. Keogh. Searching and mining trillions of time series subsequences under dynamic time warping. In SIGKDD, pages 262–270. ACM, 2012.
  • [31] T. Rakthanmanon and E. Keogh. Fast shapelets: A scalable algorithm for discovering time series shapelets. In SDM, 2013.
  • [32] H. Sakoe and S. Chiba. Dynamic programming algorithm optimization for spoken word recognition. IEEE Transactions on Acoustics, Speech and Signal Processing, 26(1):43–49, 1978.
  • [33] D. Silva, V. De Souza, G. Batista, et al. Time series classification using compression distance of recurrence plots. In ICDM, pages 687–696. IEEE, 2013.
  • [34] X. Wang, A. Mueen, H. Ding, G. Trajcevski, P. Scheuermann, and E. Keogh. Experimental comparison of representation methods and distance measures for time series data. DMKD, 26(2):275–309, 2013.
  • [35] L. Ye and E. Keogh. Time series shapelets: a new primitive for data mining. In SIGKDD, pages 947–956. ACM, 2009.
  • [36] B. Yi and C. Faloutsos. Fast time sequence indexing for arbitrary lp norms. In VLDB. VLDB, 2000.
  • [37] Jiaping Zhao and Laurent Itti. Classifying time series using local descriptors with hybrid sampling. Transaction on Knowledge and data engineering, 2015.