我有一个时间序列列表:
ex <- list(ts1 = structure(c(15.33, 46.83, 69.93, 79.59, 85.785, 78.132,
61.812, 189.108, 188.904, 159.936, 35.175, 62.37, 77.49, 85.785,
87.36, 17.952, 198.696, 198.084, 159.936, 157.692), .Dim = 5:4, .Dimnames = list(
NULL, c("var1", "var2", "var3", "var4")), .Tsp = c(1, 5,
1), class = c("mts", "ts", "matrix")), ts2 = structure(c(34.65,
43.47, 34.125, 62.424, 10.2, 45.084, 43.575, 34.125, 27.72, 10.812,
48.756, 92.616), .Dim = 3:4, .Dimnames = list(NULL, c("var1",
"var2", "var3", "var4")), .Tsp = c(1, 3, 1), class = c("mts",
"ts", "matrix")), ts3 = structure(c(33.915, 59.325, 47.736, 8.772,
54.18, 80.115, 4.08, 61.2), .Dim = c(2L, 4L), .Dimnames = list(
NULL, c("var1", "var2", "var3", "var4")), .Tsp = c(1, 2,
1), class = c("mts", "ts", "matrix")))
我想计算列表中每对之间的 dtw 距离。由于读取dtw
包注册dtw
距离作为距离数据库中的距离函数proxy
,pr_DB
我可以使用它proxy::dist
来快速计算所有距离。问题是它proxy::dist
似乎返回了原始距离,而由于我的时间序列长度不同,我需要它来返回归一化距离。dtw::dtw
函数返回一个包含normalizedDistance
一个元素的列表。那么我怎样才能改变什么是 return byproxy::dist
并让它 returnnormalizedDistance
呢?或者也许有另一种方法来计算每对归一化距离?(当然,由于我的数据集很大,我需要避免遍历所有对)。
这是一个简短的代码,可帮助您查看问题:
> proxy::dist(ex, method = 'dtw')
ts1 ts2
ts2 822.2551
ts3 909.3705 195.2110
> dtw::dtw(ex[[1]], ex[[2]])$distance
[1] 822.2551
> dtw::dtw(ex[[1]], ex[[2]])$normalizedDistance
[1] 102.7819