shapeDTW: shape Dynamic Time Warping

Jiaping Zhao, Laurent Itti · DOI

Abstract

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% on 18 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.

Introduction

Dynamic Time Warping (DTW) has long been considered the "gold standard" for measuring similarity between time series that may be shifted or stretched non-linearly. However, standard DTW suffers from a fundamental limitation: it is a point-to-point matching algorithm that relies solely on raw coordinate values. Because it ignores the local context of a point, DTW can produce "nonsensible" alignments—for instance, matching a peak in one sequence to a valley in another simply because they share the same numerical value. This lack of structural awareness leads to poor interpretability and limits classification accuracy in complex time series where the shape of a segment is more critical than the raw value of a single point.

Comparison of standard DTW and shapeDTW alignments. Standard DTW (c) often produces nonsensible matchings between points with different local structures, whereas shapeDTW (d) maintains structural consistency.

The shapeDTW Framework

To address the shortcomings of standard DTW, we introduce shapeDTW. The core idea is to incorporate local neighborhood information into the alignment process, mirroring how computer vision handles image matching by comparing patches rather than individual pixels.

The algorithm follows a two-step framework:

  1. Shape Descriptor Extraction: For every point in a time series, a local subsequence (neighborhood) of length $l$ is extracted. This subsequence is then encoded into a "shape descriptor." Various descriptors can be used, such as raw subsequences, Piecewise Aggregate Approximation (PAA), or more sophisticated 1D adaptations of the "Histogram of Oriented Gradients" (HOG1D).
  2. Sequence Alignment: Instead of aligning the original raw sequences, the algorithm applies standard DTW to the sequences of these multi-dimensional descriptors. The distance between two points is calculated as the Euclidean distance between their respective shape descriptors.
The shapeDTW framework: (a-c) extracting local shape descriptors for each point, (d-e) aligning the descriptor sequences using DTW, and (f) transferring the resulting warping path back to the original series.

By using descriptors, the algorithm "sees" whether a point is part of a rising edge, a peak, or a noisy plateau. Crucially, while this adds a preprocessing step, the overall complexity remains $O(L^2)$, making it computationally feasible for most applications.

Experimental Evaluation

We conducted an extensive evaluation of shapeDTW across several domains, including the UCR Time Series Archive (84 datasets), the Bach10 audio dataset for MIDI-to-audio alignment, and simulated pairs with known ground-truth alignments.

Key Results

The results demonstrate that shapeDTW significantly outperforms standard DTW and its variants:

  • Classification Accuracy: In a Nearest Neighbor (NN) classifier scheme, shapeDTW outperformed standard DTW on 64 out of 84 UCR datasets. On 18 of those datasets, classification accuracy improved by more than 10%.
  • Alignment Precision: In simulated tests, shapeDTW achieved significantly lower Mean Absolute Deviation from ground-truth alignments compared to DTW, Derivative DTW (dDTW), and Weighted DTW (wDTW).
  • Audio Alignment: In MIDI-to-audio alignment tasks, shapeDTW outperformed competitors on 9 out of 10 musical pieces.

Conclusion

shapeDTW represents a significant advancement in time series analysis by giving the classic DTW algorithm a "sense" of local structure. By representing points as shape descriptors, it avoids nonsensible matchings and produces alignments that are both more accurate and more interpretable. As the first distance measure to significantly outperform DTW across a wide range of benchmarks, shapeDTW sets a new state-of-the-art for time series classification and alignment.

Summary updated

BibTeX
@article{zhao2016shapedtw,
  author = {Jiaping Zhao and Laurent Itti},
  title = {{shapeDTW: shape Dynamic Time Warping}},
  journal = {Pattern Recognition},
  year = {2016},
  doi = {10.1016/j.patcog.2017.09.020},
}
Figure