pythonsignalssignal-processingdtw

How to apply/implement Dynamic Time Warping (DTW) or Fast Dynamic Time Warping (FastDTW) in python between 3 or more signals?


In time series analysis, dynamic time warping (DTW) is one of the algorithms for measuring similarity between two temporal sequences, which may vary in speed. Fast DTW is a more faster method. I would like to know how to implement this method not only between 2 signals but 3 or more.

distance, warp_path = fastdtw(series2, series1, dist=euclidean)

Solution

  • You essentially need to construct a matrix, evaluating the FastDTW algorithm on all possible combinations of the series.

    import fastdtw
    import scipy.spatial.distance as sd
    
    def my_fastdtw(sales1, sales2):
        return fastdtw.fastdtw(sales1,sales2)[0]
    
    distance_matrix = sd.pdist(sales, my_fastdtw)
    

    You can see this thread for a reference on how to do it, as well as other possibilities: Efficient pairwise DTW calculation using numpy or cython