DTW(Dynamic Time Warping)
Python
wiki/Dynamic_time_warpingのImplementationをPythonに書き換えただけです。
def DTW(s, t): S = len(s) T = len(t) dtw = np.full((S + 1, T + 1), np.inf) dtw[0, 0] = 0 for i in range(1, S + 1): for j in range(1, T + 1): cost = np.sqrt((s[i - 1] - t[i - 1]) ** 2) dtw[i, j] = cost + min(dtw[i - 1, j], dtw[i, j - 1], dtw[i - 1, j - 1]) return dtw[S-1, T-1]