我正在比较库dtaidistance、fastdtw和cdtw以进行 DTW 计算。这是我的代码:
from fastdtw import fastdtw
from cdtw import pydtw
import fastdtw
import array
from timeit import default_timer as timer
from dtaidistance import dtw, dtw_visualisation as dtwvis
s1 = mySampleSequences[0] # first sample sequence consisting of 3000 samples
s2 = mySampleSequences[1] # second sample sequence consisting of 3000 samples
start = timer()
distance1 = dtw.distance(s1, s2)
end = timer()
start2 = timer()
distance2 = dtw.distance_fast(array.array('d',s1),array.array('d',s2))
end2 = timer()
start3 = timer()
distance3, path3 = fastdtw(s1,s2)
end3 = timer()
start4 = timer()
distance4 = pydtw.dtw(s1,s2).get_dist()
end4 = timer()
print("dtw.distance(x,y) time: "+ str(end - start))
print("dtw.distance(x,y) distance: "+str(distance1))
print("dtw.distance_fast(x,y) time: "+ str(end2 - start2))
print("dtw.distance_fast(x,y) distance: " + str(distance2))
print("fastdtw(x,y) time: "+ str(end3 - start3))
print("fastdtw(x,y) distance: " + str(distance3))
print("pydtw.dtw(x,y) time: "+ str(end4 - start4))
print("pydtw.dtw(x,y) distance: " + str(distance4))
这是我得到的输出:
- dtw.distance(x,y) 时间:22.16925272245262
- dtw.distance(x,y) 距离:1888.8583853746156
- dtw.distance_fast(x,y) 时间:0.3889036471839056
- dtw.distance_fast(x,y) 距离:1888.8583853746156
- fastdtw(x,y) 时间:0.23296659641047412
- fastdtw(x,y) 距离:27238.0
- pydtw.dtw(x,y) 时间:0.13706478039556558
- pydtw.dtw(x,y) 距离:17330.0
我的问题是:为什么我会得到不同的表现和不同的距离?非常感谢您的意见。
// 编辑:时间测量的单位是秒。