SparseDTW: A Novel Approach to Speed up Dynamic Time Warping

Ghazi Al-Naymat, Sanjay Chawla, Javid Taheri

TL;DR

This paper introduces SparseDTW, a novel approach to speed up Dynamic Time Warping (DTW) by dynamically exploiting similarities between time series. Unlike previous methods that often sacrifice optimality for speed, SparseDTW maintains accuracy while significantly reducing computational space and time by using sparse matrices.

What Problem Does This Paper Address?

Dynamic Time Warping (DTW) is a powerful technique for measuring similarity between two time series, widely used in fields like speech recognition and data mining. However, the standard DTW algorithm has a quadratic time and space complexity (O(mn)), making it impractical for the large datasets common today. For instance, aligning two stock price time series with second-level granularity could require storing millions of matrix entries. Existing methods to speed up DTW often rely on pre-defined constraints that can lead to sub-optimal results or data abstraction techniques that don't guarantee optimality. The core challenge is to achieve significant speedups and space reductions without compromising the accuracy of the optimal alignment.

Methods

The proposed method, SparseDTW, tackles the DTW problem by leveraging the inherent similarity and correlation between time series. The key idea is to use a sparse matrix representation for the warping matrix, which is dynamically constructed.

Here's a breakdown of the core techniques:

  • Quantization: The input time series are first quantized into a range (e.g., [0, 1]) to facilitate similarity comparisons.
  • Sparse Matrix Construction: Instead of computing the full n x m DTW matrix, SparseDTW constructs a sparse matrix (SM). This matrix only stores "interesting" entries, representing potential similarities between points in the time series. Cells that are not part of potential alignments are marked as "blocked" (B).
  • Dynamic Banding: Unlike traditional methods like Sakoe-Chiba band (BandDTW) which use fixed bands, SparseDTW creates an adaptive band around the optimal warping path. This band expands or contracts based on the detected similarity between the time series.
  • Dynamic Programming with Sparse Matrix: The core dynamic programming approach of DTW is adapted to work with the sparse matrix. This involves "unblocking" cells only when necessary, guided by lower and upper bounds derived from the quantized sequences and a resolution parameter.
  • Optimal Path Retrieval: The warping path is then efficiently retrieved by traversing only the "open" (non-blocked) cells in the sparse matrix, starting from the end and working backward.

This approach contrasts with standard DTW (which computes all cells), BandDTW (which uses fixed constraints), and Divide and Conquer (DC) methods (which can be non-optimal).

Datasets

The paper evaluates SparseDTW using a combination of benchmark and synthetically generated datasets:

  • Benchmark Datasets:
    • GunX: From the UCR time series data mining archive, capturing gun shapes from video surveillance (100 sequences, 150 time steps each).
  • Trace: Simulates instrumentation failures in a nuclear power plant (200 time series, 273 length each).
  • Burst-Water: Combines data from two applications, with an average series length of 2200.
  • Sun-Spot: Daily sunspot numbers collected since 1818 (length 2898).
  • ERP (Event Related Potentials): Data from human subjects, 20 sequences of length 256.
  • Synthetic Datasets: Generated to specifically control the correlation between sequences (length 500), allowing the authors to test the effect of correlation on performance.

No new benchmark datasets were introduced; existing ones were used for evaluation.

Key Insights and Ideas

  • Similarity is Key: The most significant insight is that exploiting the actual similarity and correlation between time series, rather than imposing a priori constraints, is a powerful way to speed up DTW. This is the core of SparseDTW's advantage.
  • Adaptive Banding Outperforms Fixed: The dynamic, adaptive band created by SparseDTW is more efficient than the fixed bands used in BandDTW. This allows SparseDTW to focus computation only where needed, adapting to the data's structure.
  • Optimality Preserved: A crucial finding is that SparseDTW achieves significant speedups and space reductions while guaranteeing the optimal DTW alignment, a feat not achieved by many previous speed-up techniques.
  • Sparse Matrix Efficiency: The use of sparse matrices is not just an optimization; it's fundamental to how SparseDTW manages computational space, especially when time series are highly correlated.

Key Results

  • Speed and Space Efficiency: SparseDTW consistently outperforms standard DTW, BandDTW, and DC in terms of both elapsed time and the number of computed cells, especially on datasets with inherent similarity (e.g., GunX, Trace).
  • Optimality: SparseDTW always yields the optimal DTW distance, as confirmed by experiments and comparisons with standard DTW. BandDTW, in contrast, showed error rates from 30% to 500%.
  • Scalability: For large datasets (e.g., > 6K length), standard DTW becomes infeasible due to memory limitations (N.A. in Table 3), while SparseDTW remains applicable. For example, on a 12K dataset, DTW was not applicable, but SparseDTW took 200 seconds.
  • Correlation Impact: Higher correlation between time series leads to fewer "open" cells in SparseDTW, resulting in faster computation. Conversely, lower correlation requires more cells to be opened.
  • Minimal Cell Computation: Figure 6 shows that SparseDTW computes a significantly lower percentage of cells compared to DTW, BandDTW, and DC, highlighting its efficiency. For instance, on the Sun-Spot dataset (length 2898), SparseDTW computed only about 30% of cells, while DTW computed 100%.

Limitations and Future Work

  • Worst-Case Time Complexity: While SparseDTW is efficient in practice, its worst-case time complexity remains O(nm) because, in scenarios with no similarity, it might still need to access every cell. However, the paper argues that this worst-case is rare in practice.
  • Parameter Tuning (Resolution): The paper mentions that the resolution parameter affects the amount of space utilized but not optimality. Further exploration into optimal parameter selection for various data types could be beneficial.
  • Future Work: The authors suggest that SparseDTW's ability to find optimal alignments efficiently makes it suitable for integration with lower-bound approaches, potentially leading to further speedups in large-scale similarity search. The paper also implies that the concept of exploiting correlation for sparse matrix construction could be applied to other dynamic programming problems.

Summary updated

BibTeX
@inproceedings{alnaymat2009sparsedtw,
  author = {Ghazi Al-Naymat and Sanjay Chawla and Javid Taheri},
  title = {{SparseDTW: A Novel Approach to Speed up Dynamic Time Warping}},
  booktitle = {AusDM},
  year = {2009},
}
Figure