tslearn.metrics.subsequence_path

tslearn.metrics.subsequence_path(acc_cost_mat, idx_path_end, be=None)[source]

计算通过累积成本矩阵的最优路径,给定序列的端点。

Parameters:
acc_cost_mat: array-like, shape=(sz1, sz2)

比较较长序列中子序列的累积成本矩阵。

idx_path_end: int

匹配子序列在较长序列中的结束位置。

beBackend object or string or None

后端。如果 be 是类 NumPyBackend 的实例或字符串 “numpy”,则使用 NumPy 后端。 如果 be 是类 PyTorchBackend 的实例或字符串 “pytorch”,则使用 PyTorch 后端。 如果 beNone,则后端由输入数组决定。 更多信息请参阅我们的 专用用户指南页面

Returns:
path: list of tuples of integer pairs

匹配路径表示为索引对的列表。在每一对中,第一个索引对应于subseq,第二个索引对应于longseq。路径的起点是\(P_0 = (0, ?)\),终点是\(P_L = (len(subseq)-1, idx\_path\_end)\)

另请参阅

dtw_subsequence_path

获取DTW的相似度分数

subsequence_cost_matrix

计算所需的成本矩阵

示例

>>> acc_cost_mat = numpy.array([[1., 0., 0., 1., 4.],
...                             [5., 1., 1., 0., 1.]])
>>> # calculate the globally optimal path
>>> optimal_end_point = numpy.argmin(acc_cost_mat[-1, :])
>>> path = subsequence_path(acc_cost_mat, optimal_end_point)
>>> path
[(0, 2), (1, 3)]

使用tslearn.metrics.subsequence_path的示例

sDTW 多路径匹配

sDTW multi path matching