Efficient pairwise DTW calculation using numpy or cython

前端 未结 2 1660
花落未央
花落未央 2021-02-19 11:20

I am trying to calculate the pairwise distances between multiple time-series contained in a numpy array. Please see the code below

print(type(sales))
print(sales         


        
2条回答
  •  暖寄归人
    2021-02-19 11:27

    To be honest, fastdtw is not fast at all

    from cdtw import pydtw
    from dtaidistance import dtw
    from fastdtw import fastdtw
    from scipy.spatial.distance import euclidean
    s1=np.array([1,2,3,4],dtype=np.double)
    s2=np.array([4,3,2,1],dtype=np.double)
    
    %timeit dtw.distance_fast(s1, s2)
    4.1 µs ± 28.6 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
    %timeit d2 = pydtw.dtw(s1,s2,pydtw.Settings(step = 'p0sym', window = 'palival', param = 2.0, norm = False, compute_path = True)).get_dist()
    45.6 µs ± 3.39 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
    %timeit d3,_=fastdtw(s1, s2, dist=euclidean)
    901 µs ± 9.95 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
    

    fastdtw is 219 times slower than dtaidistance lib and 20x slower than cdtw

    Consider changing. Here is dtaidistance git:

    https://github.com/wannesm/dtaidistance

    To install, just:

    pip install dtaidistance
    

提交回复
热议问题