Back to Glossary
Algorithms

Dynamic time warping (DTW)

Dynamic Time Warping (DTW) is an algorithm used to measure the similarity between two time series that may vary in speed or time. It optimally aligns the sequences by warping the time dimension, allowing for non-linear correspondences between points.

Explanation

DTW is particularly useful in scenarios where temporal variations make traditional distance metrics, like Euclidean distance, ineffective. The algorithm works by constructing a cost matrix representing the distances between all pairs of points in the two time series. A warping path through this matrix represents an alignment between the sequences, and the optimal path (the one with the minimal cumulative cost) provides the DTW distance. This distance reflects the similarity even if one sequence is faster or slower than the other, or if there are local time shifts. Common applications include speech recognition (where different speakers pronounce the same word at different speeds), gesture recognition, and bioinformatics (aligning DNA sequences). DTW's complexity is O(n*m) where n and m are the lengths of the two sequences, but variations and approximations exist to improve its efficiency. A key consideration when using DTW is the choice of the local distance metric used to populate the cost matrix (e.g., Euclidean, Manhattan distance).

Related Terms