slaypni / fastdtw

A Python implementation of FastDTW
MIT License
774 stars 122 forks source link

Changing radius has no effect #22

Open dmitra79 opened 5 years ago

dmitra79 commented 5 years ago

Please see the example below - changing radius produces no change in distance function, which doesn't make sense for this example. It seems like radius parameter is ignored....

N = 100
idx = np.linspace(0, 2*np.pi, N)
T1 = np.cos(idx)
Q1 = np.sin(idx) + np.array(np.random.uniform(low=0,high=1,size=(N,)))/10

for r in range(1,10):
    print(5*r)
    dist_f1, path_f1 = fastdtw(Q1, T1, dist=euclidean, radius=r)
    print(dist_f1)
jlc-christie commented 5 years ago

Haven't ran this code myself so can't say for sure, but is this because the optimal path is within 1 cell away from the diagonal? I.e. the algorithm is computing the whole distance matrix but the optimal path is close enough to the diagonal that it is irrelevant

dmitra79 commented 5 years ago

The optimal path is not close to diagonal (also, I've tried this with other packages and changing radius does make a difference)

jlc-christie commented 5 years ago

I just repeated this and plotted the path and all paths are identical and clearly don't use the specified radius, e.g. radius 1 through 9 all look like the image below, which clearly has a radius greater than 1. image

flekschas commented 5 years ago

Could this be caused by the fact that the radius is applied relative to the downsampled time series? For example, if you have 2 time series of length 90 and you downsample them until they only have a length of 3 then and your path suggest to go one step away from the diagonal then this one step will eventually look like the radius was 30 after you've upsampled the path again.

Without being the develop or having any deep knowledge it looks like the radius is applied relative to the path that was found by DTW on the downsampled time series.