zoukankan      html  css  js  c++  java
  • 使用dtaidistance实现dtw算法

    # dtaidistance!!!优选
    from dtaidistance import dtw
    
    # x
    
    query = [1, 1, 2, 3, 2, 0]
    
    # y
    template = [0, 1, 1, 2, 3, 2, 1]
    
    dtw.distance(query, template)
    

    1.4142135623730951

    s1 = np.array([1, 1, 2, 3, 2, 0], dtype=np.double)
    s2 = np.array([0, 1, 1, 2, 3, 2, 1], dtype=np.double)
    dtw.distance_fast(s1, s2, use_pruning=True)
    

    1.4142135623730951

    print(dtw.distance.__doc__)
    
    from dtaidistance import dtw
    s1 = [1, 1, 2, 3, 2, 0]
    s2 = [0, 1, 1, 2, 3, 2, 1]
    distance, paths = dtw.warping_paths(s1, s2)
    print(distance)
    print(paths)
    
    from dtaidistance import dtw
    from dtaidistance import dtw_visualisation as dtwvis
    import random
    import numpy as np
    
    s1 = np.array([1, 1, 2, 3, 2, 0], dtype=np.double)
    s2 = np.array([0, 1, 1, 2, 3, 2, 1], dtype=np.double)
    
    
    distance, paths = dtw.warping_paths(s1, s2
                                        #, window=25
                                        #, psi=2
                                       )
    print(distance)
    best_path = dtw.best_path(paths)# 最短路径
    dtwvis.plot_warpingpaths(s1, s2, paths, best_path)# 制图
    

    image-20211019221703301

  • 相关阅读:
    day 03
    day 02
    day 02 作业
    day 01
    day 10 预科
    day 09作业 预科
    day 09 预科
    day 08作业 预科
    The word 'localhost' is not correctly spelled 这个问题怎么解决
    不能够连接到主机(名称为localhost)上的MySQL服务”
  • 原文地址:https://www.cnblogs.com/Cookie-Jing/p/15427277.html
Copyright © 2011-2022 走看看