ezdtw.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:ezdtw 作者: kylerbrown 项目源码 文件源码
def dtw(a, b, distance_metric='euclidean'):
    '''perform dynamic time warping on two matricies a and b
    first dimension must be time, second dimension shapes must be equal

    distance_metric: a string that matches a valid option for the 'metric' argument in
            scipy.spatial.distance.cdist, such as 'euclidean' 'cosine' 'correlaton'

    returns:
        trace_x, trace_y -- the warp path as two lists of indicies. Suitable for use in
        an iterpolation function such as numpy.interp

        to warp values from a to b, use: numpy.interp(warpable_values, trace_x, trace_y)
        to warp values from b to a, use: numpy.interp(warpable_values, trace_y, trace_x)
    '''
    distance = cdist(a, b, distance_metric)
    cum_min_dist = dtw_distance(distance)
    trace_x, trace_y = backtrack(cum_min_dist)
    return trace_x, trace_y
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号