版本:dtw-python 1.3.0
dtw
函数功能:执行 DTW 算法,并计算两个时间序列 x 和 y 之间的最佳匹配(optimal alignment) 。
x | query vector 或 local cost matrix |
y | reference vector。如果 x 是 cost matrix,则 y 不使用。 |
dist_method | pointwise (local) 距离函数。 若该参数是一个 string:把 x、y 和给定方法一起传给 scipy.spatial.distance.cdist 函数。 若提供一个 n=length(x) 行、m=length(y) 列 的 local-distance matrix:该矩阵的元素 [i,j] 表示 x[i] 和 y[j] 之间的距离。这种方法可以处理多变量时序和其他任意距离矩阵。 |
step_pattern | 一个 stepPattern 对象,用于描述局部限制。 该参数支持许多常见的 DTW 变体。 |
window_type | windowing function。描述全局限制( the envelope of the warping path)。 可以是字符串,表示现有的限制方式: "none":No windowing (default) "itakura":Itakura parallelogram "sakoechiba":A band around main diagonal "slantedband":A band around slanted diagonal 也可以是一个用户自定义的函数。 更多细节可见 dtwWindowingFunctions()。 |
window_args | 传给 windowing function 的额外参数 |
keep_internals | 保留 cumulative cost matrix、inputs 以及其他内部结构 |
distance_only | 仅计算距离(没有backtrack,速度更快) |
open_end | 实施 open-ended alignments |
open_begin | 实施 open-ended alignments |
注: x 和 y 以数字向量(numeric vector)的形式给出。x 和 y 的长度可以不同。
最佳匹配 使得 aligned elements 之间的距离和最小。
不论是输入还是输出,在 代价矩阵(cost matrix)中,query 元素按行排列(first index)、reference 元素按列排列(second index);这些元素的打印习惯为下标向下和向右增加(原点在左上角)。
参考文献
Toni Giorgino. Computing and Visualizing Dynamic Time Warping Alignments in R: The dtw Package. Journal of Statistical Software, 31(7), 1-24. http://www.jstatsoft.org/v31/i07/
Tormene, P.; Giorgino, T.; Quaglini, S. & Stefanelli, M. Matching incomplete time series with dynamic time warping: an algorithm and an application to post-stroke rehabilitation. Artif Intell Med, 2009, 45, 11-34. http://dx.doi.org/10.1016/j.artmed.2008.11.007
Sakoe, H.; Chiba, S., Dynamic programming algorithm optimization for spoken word recognition, Acoustics, Speech, and Signal Processing, IEEE Transactions on , vol.26, no.1, pp. 43-49, Feb 1978. http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=1163055
Mori, A.; Uchida, S.; Kurazume, R.; Taniguchi, R.; Hasegawa, T. & Sakoe, H. Early Recognition and Prediction of Gestures Proc. 18th International Conference on Pattern Recognition ICPR 2006, 2006, 3, 560-563
Sakoe, H. Two-level DP-matching–A dynamic programming-based pattern matching algorithm for connected word recognition Acoustics, Speech, and Signal Processing, IEEE Transactions on, 1979, 27, 588-595
Rabiner L, Rosenberg A, Levinson S (1978). Considerations in dynamic time warping algorithms for discrete word recognition. IEEE Trans. Acoust., Speech, Signal Process., 26(6), 575-582. ISSN 0096-3518.
Muller M. Dynamic Time Warping in Information Retrieval for Music and Motion. Springer Berlin Heidelberg; 2007. p. 69-84. http://link.springer.com/chapter/10.1007/978-3-540-74048-3_4
DTW
class dtw.DTW(obj) 。DTW 类 的对象包含了由 dtw() 函数计算的 alignments。
distance | 最小全局距离(没有标准化) |
normalizedDistance | 若已知 chosen step pattern:根据 path length,对 distance 进行标准化。 |
N | query 的长度 |
M | reference 的长度 |
call | the function call that created the object(试了一下失败了) |
index1 | x(query) 中 匹配元素的 下标 |
index2 | y(reference) 中 被映射的 下标 |
stepPattern | 用于计算的 stepPattern 对象 |
jmin | 若 open.end=TRUE:reference 中被匹配的最后一个元素 |
directionMatrix | 若 keep.internals=TRUE:在每个 alignment pair 上 step 的方向(用于标记 chosen step pattern 产生规则的整数) |
stepsTaken | 从 alignment 的开始到结束,所走的 steps 的 一个 list(用于标记 chosen step pattern 的 整数)。 |
index1s | 与 index1、index2 一样, 但 排除了 multi-step patterns 中的中间步骤 |
index2s | |
costMatrix | 若 keep.internals=TRUE:cumulative cost matrix |
query | 若 keep.internals=TRUE 且 作为 x 和 y 参数传递: query 和 reference 时间序列 |
reference |
plot | 绘制 DTW 的结果 |
dtw.DTW.plot
plot(type='alignment', **kwargs) :将 dtw()函数 返回 的 DTW对象 绘制出来。
x | dtw object, usually result of call to [dtw()] |
d | dtw object, usually result of call to [dtw()] |
xlab | query 轴的标签 |
ylab | reference 轴的标签 |
type | 图(plot)的总体风格 alignment:plots the warping curve in d twoway:plots a point-by-point comparison, with matching lines。详见 dtwPlotTwoWay()。 threeway:vis-a-vis inspection of the timeseries and their warping curve。详见 dtwPlotThreeWay()。 density:displays the cumulative cost landscape with the warping path overimposed。详见 dtwPlotDensity() |
plot_type | 图中的线(line)的类型,type 的参数 |
... |