What (idea)?

Suppose that we need to compare 2 time series (quite look-alike),

An example of 2 time series to be compared using DTW. Source of the idea.

An example of 2 time series to be compared using DTW. Source of the idea.

How (idea)?

By using a distance matrix, we can find a good distance between 2 timeseries using DTW. Here, $8=3^2-1^2$ and we choose the smallest distance in the nearest position. Source.

By using a distance matrix, we can find a good distance between 2 timeseries using DTW. Here, $8=3^2-1^2$ and we choose the smallest distance in the nearest position. Source.

More detailed of calculating the distance matrix using DTW. : element th of ; : The DTW between element th and th. Source.

More detailed of calculating the distance matrix using DTW. Ai: element ith of A; D[i-1, j-1]: The DTW between element i-1th and j-1th. Source.

When to use?

  1. An example: Voice of a man. He can speak fast. He can speak slowly. However, the both voices are his. If we don't use DTW but Euclidian distance, the distance is very large → there are 2 voices → wrong prediction!
  2. Sound Pattern Recognition: detect the same kind of sound pattern (like the above example).
  3. Stock Market:

Algorithm

  1. Divide 2 time series into equal points.
  2. Calculate distance between 1st point in TS1 with all points in TS2 and then store the min.
  3. Move to 2nd point.
  4. Repeat step 2 & 3 but with 2nd point as a reference point.
  5. Add up all stored distances. This is a true measure between 2 time series.

👉 Check this video fore a more explanation.