Dynamic Time warping (DTW) is a method to calculate the optimal matching between two usually temporal sequences that failed to sync up perfectly. It compares the time series data dynamically that results from the plethora of natural and man-made time-series events occurring worldwide. The list can include temperature, school grades, kinetics, kinematic variables, and other variables.

It was originally used to compare distinct speech patterns. But, in the present era, it finds applications in domains like the financial markets, data mining, speech recognition, and others. We observed its significant use in data mining, where it measures the distance between the two time series. It has also coped with different speeds and time deformations linked with time-dependent data automatically.

In this article, we are going to dig deep into the importance of dynamic time warping by considering its different applications and examples.

Let’s understand how the dynamic time warping algorithms help businesses plan a better marketing campaign strategy for brilliant results.

Let’s consider a business that ran a marketing campaign for one year (Jan 2019 - Jan 2020) in a particular market. They termed it an ideal market because of the highly successful output involving incremental leads.

The business plans to run the same campaign in the new markets because of its highly successful results. However, they were unsure about the ideal markets for their marketing campaign. The cost concern stretching over the period of one year also added to the second thoughts.

The dilemma was to look for an approach that would help in identifying which market was an ideal market for the business so that the same marketing campaign could bring the same results at the end of the year.

Dynamic time warping (DTW) helped the business in recognizing which market meets the status of the ideal market. Here’s how the issue was dealt with and the solution followed.

The marketing campaign that ran successfully from Jan 2019 to Jan 2020 was taken into consideration for 6 other prospect or candidate markets for the same marketing campaign.

The leads and campaign data was available for these six markets for a period of Feb 2020 to July 2020. Later, this data from candidate markets was compared with the ideal market using the dynamic time warping algorithm.

Market | Marketing Campaign duration | DTW distance |
---|---|---|

Ideal Market | Jan 2019 - Jan 2020 | 130 |

Candidate market A | Feb 2020 - July 2020 | 143 |

Candidate market B | Feb 2020 - July 2020 | 132 |

Candidate market C | Feb 2020 - July 2020 | 136 |

Candidate market D | Feb 2020 - July 2020 | 155 |

Candidate market E | Feb 2020 - July 2020 | 138 |

Candidate market F | Feb 2020 - July 2020 | 144 |

**Note:** The DTW distance refers to the distance between two-time series or arrays with distinct lengths.

After utilizing the dynamic time warping algorithm on the data of the candidate market, the candidate markets that had the lowest distance to the ideal market were selected for implementation of the marketing campaign.

Market | Marketing Campaign duration | DTW distance |
---|---|---|

Ideal Market | Jan 2019 - Jan 2020 | 130 |

Candidate market A | Feb 2020 - July 2020 | 143 |

Candidate market B | Feb 2020 - July 2020 | 132 |

Candidate market C | Feb 2020 - July 2020 | 136 |

Candidate market D | Feb 2020 - July 2020 | 155 |

Candidate market E | Feb 2020 - July 2020 | 135 |

Candidate market F | Feb 2020 - July 2020 | 144 |

These were the candidate markets B, C and E. Only three out of the six candidate markets were considered, showing similar results to that of the ideal market. And the business continued to start the marketing campaign for the three shortlisted markets.

This way, instead of running the campaign on all the candidate markets, the business was able to use their investment precisely with the results from the dynamic time warping algorithm.

Later, the business was able to incur incremental leads of 5%, 9%, and 6% from the candidate markets B, C, and E respectively. The solution from DTW helped the business in netting a greater number of leads by correctly identifying the markets similar to its ideal market, thereby cutting down the cost of investment in marketing.

Biomechanics includes the academic focus on human movements and time series data such as kinetic, kinematics variables, and spatiotemporal variables that are analyzed frequently to describe and explain human movement. To put it simply, gait research is a systematic approach to studying human motion using the brain and the eye of the observer.

In such research, evaluating the pattern similarity is a challenging task. The visual method may be convenient, but meeting the objectives of the study causes a compromise in the process. For instance, if one has to identify the direction and degree to which the left and right foot of a person in gait diverge from each other, the results are better attained by analyzing the pattern similarity of time series data using mathematical and statistical calculation.

Let’s understand it with a practical example to discover how dynamic time warping can be helpful.

Let’s consider 16 participants in this study in which we have an equal number of males and females. The below-given table illustrates the anthropometric data of the participants.

Sex | Age (yr) | Height (cm) | Weight (kg) |
---|---|---|---|

Male | 23.6±1.8 | 177.2±4.2 | 69.4±5.9 |

Female | 21.4±1.0 | 164.5±3.3 | 53.7±7.1 |

Total | 22.7±1.8 | 170.9±7.4 | 62.5±9.5 |

In this case, we would use three conditions to find the optimal alignment. These are listed below.

In the above conditions,

- p = The path discovered by dynamic time warping algorithm
- c = The local cost involved in the warping path
- m, n = The index number of the found warping path
- L = Warping path maximum length
- x, y = Parameters representing sequence data

The optimum walking path is discovered by transforming two sequences into a matrix. Further, it calculates the distinct value of each element of two sequences, which we refer to as local cost that helps us in finding the optimal warping path.

**Note:** The smallest sum of these local costs defines the optimal warping path and the sum of local costs is called the global cost.

Here’s how you can find it mathematically.

In the above given mathematical formulations, d represents the distance between every element of the two sequences. γ represents the distance accumulated of the warping path. So when the difference between two sequences is null, the resulting warping path comes as the diagonal of the matrix.

However, the symmetry index is used traditionally for evaluating the similarity in gait research. It is done using the following formula.

For a value of SI < 10%, the symmetry is accepted.

In the study that we have considered, we will compare the results of the symmetry index and dynamic time warping.

The results achieved from the implementation of the data into DTW and SI gave rise to the following result.

Here, the picture on the left shows the alignment and warping path of data sequences when we compare the left and right foot evaluations to those similar in SI and DTW.

Another case where the evaluations were non-similar in the case of SI and DTW showed a different picture.

Another case also came into the picture where the evaluations were similar in SI but were non-similar in DTW, as given below.

This study was done to understand the effectiveness of dynamic time warping in gait research. As per the results achieved, DTW has confirmed its applicability for gait research by showing different results from SI which is a basic test to test the similarity of gait. To put it simply, the results achieved have pointed out the fact that dynamic time warping can be used for similarity tests of gait research.

It’s no secret that a dynamic time warping algorithm is a powerful distance metric to have in one’s toolbox. It comes in handy when one works with two non-linear sequences, exceptionally when one of them is a shrunk or non-linear version of the other. From comparing the stock trading data over similar time frames to accurately calculating the speed of the walker, it is a great technique that data scientists and data analysts must be familiar with in order to work with time series data.

### Srishti Chaudhary

Srishti is a competent content writer and marketer with expertise in niches like cloud tech, big data, web development, and digital marketing. She looks forward to grow her tech knowledge and skills.

Is dynamic time warping related to artificial intelligence?

What does soft DTW mean?

What is the use of time series?

What's up with Turing?
Get the latest news about us here.

Know more about remote work.

Checkout our blog here.

Checkout our blog here.

Have any questions?

We'd love to hear from you.

We'd love to hear from you.

Tell us the skills you need and we'll find the best developer for you in days, not weeks.