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

  • 相关阅读:
    JVM
    OLAP
    rocketMq学习
    redis的使用小记
    CRT配置端口转发
    冒泡排序
    spring AOP-切面编程
    linux下对jar包和war包进行重新打包
    oracle-sql性能优化
    遍历List,根据子项的某个属性分组
  • 原文地址:https://www.cnblogs.com/Cookie-Jing/p/15427277.html
Copyright © 2011-2022 走看看