wannesm / dtaidistance

Time series distances: Dynamic Time Warping (fast DTW implementation in C)
Other
1.09k stars 185 forks source link

What is happening with the dtw distance? #8

Closed hazzehh closed 6 years ago

hazzehh commented 6 years ago

I was just comparing results with other dynamic time warping libraries and noticed significant differences in the dtw distances, despite similar paths. Am I missing something or is there an error somewhere in your distance calculation?

dist1,paths= dtw.warping_paths(s1,s2)
path = dtw.best_path(paths) 
print(dist1)

dist2 = 0
for [a, b] in path:
    dist2 += abs(s1[a]-s2[b])
print(dist2)

dist1 and dist2 are vastly different in my examples.

wannesm commented 6 years ago

This toolbox uses quadratic differences instead of absolute. Thus (a-b)**2 instead of abs(a-b).

hazzehh commented 6 years ago

@wannesm Ahh, of course. Is there any particular reason reason why?

wannesm commented 6 years ago

It’s often used because it prefers many small deviations over a few large ones, which would add up to the same amount when using the difference (but abs(a-b) is faster). It appears also to be the most popular one in papers. See for example the extensive work by Eamonn Keogh, http://www.cs.ucr.edu/%7Eeamonn/AAAI_2011_keogh.pdf and http://www.cs.unm.edu/~mueen/DTW.pdf .