1 作用
用来辅助计算DTW的python模块
2 基本使用方法
2.1 数据
2.2 定义距离函数
我们首先要定义两个序列间任意两个点xi,yj之间的距离
manhattan_distance = lambda x, y: np.abs(x - y)
2.3 使用dtw
from dtw import dtw
d, cost_matrix, acc_cost_matrix, path = dtw(x, y, dist=manhattan_distance)
2.4 返回参数意义
d就是两个序列间dtw的值,算出来是2,和DTW _UQI-LIUWJ的博客 一致
path就是对应关系
path
#(array([0, 1, 2, 3, 4, 4]), array([0, 1, 1, 2, 3, 4]))
plt.imshow(cost_matrix.T,origin='lower',cmap='gray')
plt.plot(path[0],path[1])
plt.show()
每次沿着颜色最深的点走