Dynamic Time Warping (DTW) algorithm implementation
In time series analysis, dynamic time warping (DTW) is an algorithm for measuring similarity between two temporal sequences, which may vary in speed. For instance, similarities in walking could be detected using DTW, even if one person was walking faster than the other, or if there were accelerations and decelerations during the course of an observation. DTW has been applied to temporal sequences of video, audio, and graphics data — indeed, any data that can be turned into a one-dimensional sequence can be analyzed with DTW. A well-known application has been automatic speech recognition, to cope with different speaking speeds. Other applications include speaker recognition and online signature recognition. It can also be used in partial shape matching applications.
In general, DTW Is a method that calculates an optimal match between two given sequences (e.g. time series) with certain restriction And rules:
- Every index from the first sequence must be matched With one Or more indices from the other sequence, And vice versa
- The first index from the first sequence must be matched With the first index from the other sequence (but it does Not have To be its only match)
- The last index from the first sequence must be matched With the last index from the other sequence (but it does Not have To be its only match)
- The mapping Of the indices from the first sequence To indices from the other sequence must be monotonically increasing, And vice versa, i.e. If j > i are indices from the first sequence, then there must Not be two indices l > k in the other sequence, such that index i Is matched with index l And index j Is matched with index k, And vice versa.