DynamicTimeWarping / dtw-python

Python port of R's Comprehensive Dynamic Time Warp algorithms package
https://dynamictimewarping.github.io
GNU General Public License v3.0
279 stars 35 forks source link

dist_method= 'jensenshannon' seems broken #72

Closed CNelias closed 1 year ago

CNelias commented 1 year ago

Describe the bug A simple test with two different sinusoidal signals of different frequency and amplitude returns a distance of 0. Actually it always returns a distance of 0.

To Reproduce

import numpy as np
from dtw import *
from scipy.spatial.distance import jensenshannon

t_steps = np.linspace(0, 6, 100)
s1 = np.sin(t_steps) + 2
s2 = 4*np.cos(t_steps) + 8
d = dtw(s1, s2, dist_method='jensenshannon').distance #d is always equal to 0 somehow, no matter which signals I try.
correct_d = jensenhannon(s1, s2) # this is a problem, because correct_d is clearly non-zero.

Version latest

tonigi commented 1 year ago

Please see https://dynamictimewarping.github.io/faq/#why-do-changes-in-distmethod-appear-to-have-no-effect . Your timeseries are single-variate. The distance method is almost irrelevant.

To be totally clear, your code is equivalent to:

s1m=np.atleast_2d(s1).T  # A 100x1 matrix
s2m=np.atleast_2d(s2).T
L = scipy.spatial.distance.cdist(s1m,s2m,"jensenshannon")
d = dtw(L)

If you inspect the matrix L, it's probably not what you want.

https://colab.research.google.com/drive/1hrwcClmGRiW_PKWO4z2ENP_chNP-vT3Q?usp=sharing

CNelias commented 1 year ago

Oh I see. So it's not equivalent to matlab 'symkl' function then... Thanks for clarifying that.

tonigi commented 1 year ago

I'm not familiar with symkl, nor i find documentation, so I can't comment.