pollen-robotics / dtw

DTW (Dynamic Time Warping) python module
GNU General Public License v3.0
1.16k stars 233 forks source link

Added fastdtw #8

Closed capkuro closed 7 years ago

capkuro commented 7 years ago

Hi, I'm implementing a speech comparison back-end and i used your library. In my journey of developing my application, I found out that the speed for calculating the DTW between a large number of MFCC coefficients is slow (in the context of my application). For that reason, fastdtw was implemented, by making use of scipy's cdist function which has optimised functions for calculating the distance between matrices.

This function supports giving the distance function as a parameter, or giving it as a string. If the latter is used, then cdist will be using an corresponding optimised function. Here below is a little code for time benchmarking purposes:

import numpy as np
from scipy.spatial.distance import cosine
from dtw import dtw, fastdtw
import timeit

x = np.random.rand(1000).reshape(-1,1)
y = np.random.rand(1000).reshape(-1,1)

start = timeit.default_timer()
fastdtw(x,y,cosine)
end = timeit.default_timer()
print ("DTW with scipy cosine distance:" ,end-start)
print "========"
start = timeit.default_timer()
fastdtw(x,y,'cosine')
end = timeit.default_timer()
print ("DTW with scipy cdist using cosine distance:",end-start)

And the output of this code in a I5-5gen with 8gb of ram is:

('DTW with scipy cosine distance:', 47.640693556034876)
========
('DTW with scipy cdist using cosine distance:', 1.4689458024448427)

Also, thanks for sharing your code. Sebastian

pierre-rouanet commented 7 years ago

Great add to the library! Thanks a lot!

ludovicamicaroni3 commented 5 years ago

Hi, If I install the package dtw it cannot find this function on the import. shall I install something else?

pierre-rouanet commented 5 years ago

It has been renamed accelerated_dtw (see https://github.com/pierre-rouanet/dtw/pull/28)

pankeda123 commented 4 years ago

Hi, this is really a very easy to use package, thank you for providing. I am using it for clustering large amounts of data,so I use the ‘accelerated_dtw’ function for calculation. But function ‘accelerated_dtw’ seems to be unable to adjust the parameter ‘w’, is there a way to solve this problem?

soso-maitha commented 2 years ago

Thanks lot really this is much more faster than the dtw. If you have any paper let me know so that I reference it in my MSc. dissertation. best regards,