SparseDTW: A Novel Approach to Speed up Dynamic Time Warping

Ghazi Al-Naymat, Sanjay Chawla, Javid Taheri

TL;DR

SparseDTW is a novel algorithm that significantly speeds up Dynamic Time Warping (DTW) and reduces its memory footprint without sacrificing optimality. By dynamically exploiting the inherent correlation between two time series, it creates an adaptive, sparse search space that guarantees the same "perfect" result as the standard algorithm but at a fraction of the computational cost.

Introduction: The Challenge of Time Series Alignment

Dynamic Time Warping (DTW) is widely regarded as the "gold standard" for measuring similarity between sequences that may vary in speed or time, such as speech patterns, stock market trends, or sensor readings. Unlike Euclidean distance, DTW can non-linearly "warp" the time axis to find the best possible alignment between two series. However, the standard DTW algorithm suffers from a major Achilles' heel: its computational complexity is $O(mn)$, where $m$ and $n$ are the lengths of the sequences.

In modern data-intensive applications, this quadratic growth is a significant barrier. For instance, comparing two sequences of length 30,000 would require a cost matrix with nearly a billion entries, exceeding the memory and processing capabilities of many systems. To address this, researchers have historically relied on "Global Constraints," such as the Sakoe-Chiba band or the Itakura Parallelogram.

A traditional Sakoe-Chiba band restricts the search space to a fixed diagonal area, potentially missing the optimal path.

As shown in the figure above, these methods restrict the search to a narrow diagonal band. While they offer substantial speedups, they are heuristics—they risk missing the globally optimal alignment path if it deviates significantly from the diagonal. SparseDTW was developed to bridge this gap, offering the efficiency of a constrained search with the mathematical guarantee of a full, exhaustive search.

Methodology: The SparseDTW Algorithm

The core innovation of SparseDTW is its ability to minimize the number of cells calculated in the warping matrix through a three-step process:

  1. Quantization: The input time series are first quantized into overlapping bins based on a user-defined resolution parameter (Res). This step simplifies the data representation while preserving essential similarity features.
  2. Sparse Matrix Initialization: Rather than initializing a full $N \times M$ grid, the algorithm creates a sparse matrix. It only "opens" cells for calculation where the corresponding data points from the two series fall into the same or neighboring bins. This creates an initial search area based on data similarity rather than a rigid geometric constraint.
  3. Dynamic Unblocking: This is the critical mechanism for maintaining optimality. As the algorithm traverses the warping path, it monitors whether the path is being forced toward a "blocked" (uncalculated) cell. If a blocked cell is necessary to maintain the potential for a globally optimal path, the algorithm "unblocks" it on the fly, calculating its value and integrating it into the search space.
The relationship between the alignment of two time series (left) and the resulting optimal path within the cumulative cost matrix (right).

Unlike the popular Divide and Conquer (DC) approach (e.g., Hirschberg’s algorithm), which focuses on reducing space but can fail to find the global DTW optimum, SparseDTW is mathematically proven to yield the exact same distance as the standard, exhaustive DTW algorithm.

Experimental Evaluation

The authors evaluated SparseDTW against standard DTW and heuristic-based BandDTW using a variety of datasets, including GunX (video surveillance), Trace (nuclear power plant instrumentation), Burst-Water (sensor data), Sun-Spot (historical solar activity), and ERP (brain activity). Synthetic datasets were also used to test varying levels of correlation.

Key Results

The experimental results highlight several advantages of the SparseDTW approach:

  • Computational Efficiency: SparseDTW typically computed only 20% to 40% of the cells required by the standard algorithm.
  • Performance on Large Data: For sequences exceeding 6,000 points, standard DTW often failed due to memory exhaustion. SparseDTW, however, completed these tasks efficiently.
  • Optimality and Accuracy: While BandDTW exhibited error rates between 30% and 500% due to its heuristic nature, SparseDTW consistently achieved 0% error, matching the standard DTW distance perfectly.
  • Execution Speed: On the Sun-Spot dataset, SparseDTW was significantly faster than standard DTW and even outperformed BandDTW in certain scenarios by avoiding the calculation of irrelevant cells.

Discussion and Future Directions

SparseDTW treats the search space as a data-driven problem rather than a geometric one. By recognizing that highly dissimilar points are unlikely to be part of an optimal alignment, the algorithm avoids unnecessary computations. However, it is important to note that in the worst-case scenario—where two time series have zero correlation—SparseDTW may end up unblocking most cells, reverting to $O(mn)$ complexity.

Furthermore, the algorithm's performance is influenced by the resolution parameter used for quantization. While this parameter does not impact the final accuracy, it dictates the space-time tradeoff. Future research will focus on developing automated methods for determining the optimal resolution and applying this sparse dynamic programming logic to other data mining domains.

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