Closed Vishuddha closed 5 years ago
There is many parameters in the implementation of DTW. In particular, the cost for adding/removing elements or the distance normalisation (using sequence length for instance). They make comparing distance results hard. DTW should only be used as a relative distance measurement not as an absolute one.
BTW, when using numpy norm, you should wrap it as such:
dist, cost, acc, path = dtw(v1, v2, dist=lambda x, y: norm(x - y))
Otherwise, you'll get very different results. For instance:
v1 = np.array([0])
v2 = np.array([3])
norm(v1, v2)
>>> array([3])
norm(v1 - v2)
>>> 3
I calculated the dtw of the following vectors in matlab:
`v1 = [0.188920000000000,0.374040000000000,0.475340000000000,0.533000000000000,0.512370000000000,0.407970000000000,0.302600000000000,0.246150000000000,0.253710000000000,0.259290000000000,0.263580000000000,0.244050000000000,0.266720000000000,0.307670000000000,0.292210000000000,0.277760000000000,0.341390000000000,0.459630000000000,0.627800000000000,0.800240000000000,0.918510000000000,0.956360000000000,0.928950000000000,0.957970000000000,0.977330000000000,0.996920000000000,1.06092000000000,1.09155000000000,1.02333000000000,1.13333000000000,1.30598000000000,1.51047000000000,1.65202000000000,1.77398000000000,1.80780000000000,1.83943000000000,1.91170000000000,1.98254000000000,2.11222000000000,2.27801000000000,2.43857000000000,2.63078000000000,2.74151000000000,2.87500000000000,3.03449000000000,3.34735000000000,3.72940000000000,3.97465000000000,4.07998000000000,4.12125000000000,4.19081000000000,4.31723000000000,4.57329000000000,4.88914000000000,5.22250000000000,5.35281000000000,5.47228000000000,5.63479000000000,5.78064000000000,5.86085000000000,5.90618000000000,6.01840000000000,6.12933000000000,6.20901000000000,6.05646000000000,5.98920000000000,6.06569000000000,6.04827000000000,5.93742000000000,5.61611000000000,5.05997000000000,4.43839000000000,3.91407000000000,3.50155000000000,3.40417000000000,3.40722000000000,3.48959000000000,3.45272000000000,3.38947000000000,3.18416000000000,3.01354000000000,2.86543000000000,2.72751000000000,2.60656000000000,2.60653000000000,2.52645000000000,2.31048000000000,2.19951000000000,2.06875000000000,1.86361000000000,1.67055000000000,1.39603000000000,1.30123000000000,1.18884000000000,1.21669000000000,1.20688000000000,1.28473000000000,1.39773000000000,1.33148000000000,1.31266000000000,1.34883000000000,1.24372000000000,1.12070000000000,1.02620000000000,0.967690000000000,0.923500000000000,0.826740000000000,0.730070000000000,0.562350000000000,0.363570000000000,0.287070000000000,0.160360000000000,0.0180400000000000,-0.152870000000000,-0.205000000000000,-0.185640000000000,-0.288340000000000,-0.395300000000000,-0.459250000000000,-0.487600000000000,-0.555340000000000,-0.591990000000000,-0.604040000000000,-0.600200000000000,-0.632190000000000,-0.762050000000000,-0.884570000000000,-0.952940000000000,-1.05157000000000,-1.17938000000000,-1.31063000000000,-1.43334000000000,-1.51990000000000,-1.62652000000000,-1.74324000000000,-1.85254000000000,-2.07515000000000,-2.44438000000000,-2.91229000000000,-3.43957000000000,-4.10041000000000,-4.96290000000000,-6.11609000000000,-7.55787000000000,-9.28694000000000,-11.2354800000000,-12.8483100000000,-13.3931800000000,-13.1156300000000,-11.4611500000000,-9.57552000000000,-8.61771000000000,-13.4576700000000,-19.7714300000000,-25.1203200000000,-32.3106200000000,-31.9191000000000,-35.4034800000000,-22.1963600000000,-10.8390700000000,-4.90095000000000,-3.36312000000000,-2.70830000000000,-0.498060000000000,4.45787000000000,8.33272000000000,10.1187600000000,10.2836400000000,10.1326300000000,10.1289500000000,10.5406200000000,10.6819000000000,10.5473300000000,10.4898600000000,10.3997000000000,10.0776900000000,9.89943000000000,10.1427500000000,10.5413800000000,10.7724700000000,10.7867300000000,10.6159200000000,10.2735700000000,9.88413000000000,9.59865000000000,9.51017000000000,9.39271000000000,9.16591000000000,8.84678000000000,8.59101000000000,8.45692000000000,8.27694000000000,7.99775000000000,7.58808000000000,7.14221000000000,6.75419000000000,6.39763000000000,6.07260000000000,5.68011000000000,5.32350000000000,5.02207000000000,4.53240000000000,4.20408000000000,3.89949000000000,3.61511000000000,3.34292000000000,3.24694000000000,3.15468000000000,2.88688000000000,2.42131000000000,2.14873000000000,1.87972000000000,1.59830000000000,1.40339000000000,1.26594000000000,1.11341000000000,1.01131000000000,0.840810000000000,0.649300000000000,0.519010000000000]; v2 = [0.172190000000000,0.183850000000000,0.140950000000000,0.124780000000000,0.120430000000000,0.119600000000000,0.0934800000000000,0.0900300000000000,0.0235400000000000,0.0637200000000000,0.446220000000000,0.994590000000000,1.42781000000000,1.68248000000000,1.74495000000000,1.58854000000000,1.42296000000000,1.39401000000000,1.53864000000000,1.61368000000000,1.48482000000000,1.55669000000000,1.78322000000000,1.91022000000000,1.89990000000000,1.67274000000000,1.51963000000000,1.39933000000000,1.40903000000000,1.50344000000000,1.47615000000000,1.28588000000000,1.21687000000000,1.39741000000000,1.56799000000000,1.80233000000000,2.06685000000000,2.14694000000000,2.12543000000000,2.15747000000000,2.22453000000000,2.26919000000000,2.18031000000000,2.08126000000000,1.95087000000000,1.83460000000000,1.95396000000000,1.95825000000000,1.85928000000000,1.89796000000000,1.91726000000000,1.78281000000000,1.55493000000000,1.34871000000000,1.18645000000000,1.29396000000000,1.48854000000000,1.80546000000000,2.09418000000000,2.25531000000000,2.25869000000000,2.02703000000000,1.64870000000000,1.33342000000000,1.17083000000000,1.12854000000000,1.08169000000000,1.04123000000000,1.03051000000000,0.948310000000000,1.00077000000000,0.946430000000000,0.883910000000000,0.930570000000000,1.02310000000000,0.992460000000000,0.803750000000000,0.608970000000000,0.418720000000000,0.122440000000000,-0.0441000000000000,-0.0955500000000000,-0.158140000000000,-0.247990000000000,-0.227000000000000,-0.261870000000000,-0.325670000000000,-0.389170000000000,-0.412000000000000,-0.128000000000000,0.0447800000000000,0.0156700000000000,-0.171850000000000,-0.471630000000000,-0.663620000000000,-0.812920000000000,-0.761030000000000,-0.623730000000000,-0.320340000000000,-0.122160000000000,-0.0488800000000000,-0.0699800000000000,-0.150240000000000,-0.366810000000000,-0.679180000000000,-0.884930000000000,-0.891200000000000,-0.652210000000000,-0.411230000000000,-0.550700000000000,-0.997270000000000,-1.23023000000000,-1.10687000000000,-1.16260000000000,-1.27119000000000,-1.51755000000000,-1.86312000000000,-1.89248000000000,-1.43688000000000,-1.11052000000000,-0.991740000000000,-1.15689000000000,-1.31163000000000,-0.479530000000000,0.606620000000000,1.13675000000000,0.988150000000000,0.789260000000000,0.783010000000000,0.579910000000000,0.443940000000000,0.207690000000000,0.195230000000000,0.271300000000000,0.417440000000000,0.169780000000000,-0.128360000000000,-0.420960000000000,-0.346430000000000,-0.273350000000000,-0.248640000000000,-0.110550000000000,-0.00355000000000000,0.264170000000000,0.476580000000000,0.621370000000000,0.655180000000000,0.698600000000000,0.691000000000000,0.534970000000000,0.421630000000000,0.0813000000000000,-0.155090000000000,-0.278060000000000,-0.401110000000000,-0.496130000000000,-0.466990000000000,-0.0743000000000000,0.360610000000000,0.682450000000000,0.733570000000000,0.400130000000000,0.139960000000000,-0.0959700000000000,-0.159770000000000,-0.253960000000000,0.00920000000000000,0.0534600000000000,0.477080000000000,0.905120000000000,1.24407000000000,1.42882000000000,1.36261000000000,1.29641000000000,1.30843000000000,1.32917000000000,1.29890000000000,1.23874000000000,1.25595000000000,1.28893000000000,1.31694000000000,1.29161000000000,1.17625000000000,1.09849000000000,1.30325000000000,1.06873000000000,0.993960000000000,1.29602000000000,1.45716000000000,0.799980000000000,1.13135000000000,0.668080000000000,0.666340000000000,0.247790000000000,0.618250000000000,0.956130000000000,1.45986000000000,1.16283000000000,1.16934000000000,0.909140000000000,0.502390000000000,0.121920000000000,0.142810000000000,0.144640000000000,0.110460000000000,0.259030000000000,0.492010000000000,0.607240000000000,0.604710000000000,0.517210000000000,0.438660000000000,0.226780000000000,0.0457300000000000,-0.0892300000000000,-0.209990000000000,-0.325820000000000,-0.348550000000000,-0.360390000000000];
dtw(v1.',v2.')`
result in matlab is 729.6579
Matlab defaults to the euclidean norm
Result with your package: 0.4414261187214609
` from numpy.linalg import norm
dist, cost, acc, path = dtw(v1, v2, dist=norm)
print(dist) `