# What is the distance metric in dynamic time warping?

I am reading the lecture slides from this site http://luthuli.cs.uiuc.edu/~daf/courses/CS-498-DAF-P/Lecture%2018%20-%20Time%20series,%20DTW.pdf

In slide 24, the lecture suggest using metric of the following

d(i, j) = ||f(i) - f(j)||

select top frequency in i and top frequency in j,
find the Euclidean distance between the two


I am not exactly sure what do they mean by Euclidean distance between the two.

Did they meant to have top n frequency sorted in order and match the order for subtraction and find the euclidean distance?

For example

f1 = [1, 2, 3, 4]

f2 = [1, 100, 200 ,300]

d(1,2) = |1-1| + |100-2| + |200-3| + |300-4|


Any help would be appreciated

Thanks

The Euclidean distance between two vectors $\mathbf a$ and $\mathbf b$ is $\mathrm d(\mathbf a, \mathbf b) \equiv \sqrt {\sum_i (a_i - b_i)^2}$

In your example you forgot to square the differences. Remember the way you calculate hypotenuse of a triangle; it's the same idea.

• Thanks, so I just want to confirm that the metric is using the top n frequency and minus each other according to the order? So you wouldn't have second highest subtract the fourth highest frequency? Commented Dec 3, 2014 at 18:39
• Where does it say that on slide 24? The only thing I see is "Given our robust feature we can use a simple measure like Euclidean distance".
– Emre
Commented Dec 3, 2014 at 20:22
• exactly, so because it wasn't elucidated in the document, I was confused on what to compare, for example given a's top frequency is [a1, a2] and b's top frequency is [b1, b2], in general |a1-b1|_2 + |a2-b2|_2 is not the same as |a1-b2|_2 + |a2-b1|_2 Commented Dec 3, 2014 at 21:00
• So where did you get the idea that you were supposed to do that?
– Emre
Commented Dec 3, 2014 at 21:12
• I am not exactly sure what else to do, is there other way of pairing $a_i$ to $b_i$? Commented Dec 3, 2014 at 21:26