【yyddjtc】DTW算法--python实现

【yyddjtc】DTW算法--python实现,第1张

import numpy as np


def dtw2(a,b):
    x=len(a)
    y=len(b)
    dist =[[0 for i in range(x)] for j in range(y)]
    G =[[0 for i in range(x)] for j in range(y)]
    for j in range(y):
        for i in range(x):
            dist[j][i] = abs(a[i] - b[j])
    G[0][0] = dist[0][0]*2
    for j in range(y-1):
        G[j+1][0] = G[j][0] + dist[j+1][0]
    for i in range(x-1):
        G[0][i+1] = G[0][i] + dist[0][i+1]
    for j in range(y-1):
        for i in range(x-1):
            G[j+1][i+1] = min((G[j][i+1]+dist[j+1][i+1]),(G[j+1][i]+dist[j+1][i+1]),(G[j][i] +2*dist[j+1][i+1]))
    return G[y-1][x-1]

输入值为两个不同矩阵,输出值为矩阵距离,当矩阵相同时输出为0.

原理来自:

https://blog.csdn.net/qq_39516859/article/details/81705010https://blog.csdn.net/qq_39516859/article/details/81705010

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/868307.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-13
下一篇 2022-05-13

发表评论

登录后才能评论

评论列表(0条)

保存