def align_signal(s, t, w=5, has_time=True): """ every row of s or t is a time series every column is dimensions of signal at one time point w size is symmetric. w=5 means the window has size 11. """ if has_time: s = s[:, 1:] t = t[:, 1:] dist_fun = euclidean_distances dist, cost, acc, path = dtw(s, t, dist_fun) path = np.array(path) warped_t = t[path[1, :], :] new_t = np.zeros(s.shape) for i in range(warped_t.shape[0]): new_t[path[0, i], :] = warped_t[i, :] if has_time: Ts = np.arange(1, s.shape[0]+1) Ts = Ts.reshape(-1, 1) new_t = np.hstack((Ts, new_t)) return new_t
def dtw_distance(s, t): """ every row of s or t is a time series every column is dimensions of signal at one time point w size is symmetric. w=5 means the window has size 11. """ has_time = True if has_time: s = s[:, 1:] t = t[:, 1:] dist_fun = euclidean_distances dist, cost, acc, path = dtw(s, t, dist_fun) return dist