gpt4 book ai didi

r - 了解动态时间扭曲

转载 作者:行者123 更新时间:2023-11-30 08:52:39 34 4
gpt4 key购买 nike

我们想使用dtw R 库,用于将某些时间序列数据收缩和扩展至标准长度。

考虑具有等效列的三个时间序列。 moref 的长度(行)为 105,mobig 为 130,mosmall 为 100。我们想要投影 mobigmosmall 的长度为 105。

moref <- good_list[[2]]
mobig <- good_list[[1]]
mosmall <- good_list[[3]]

因此,我们计算两个比对。

ali1 <- dtw(mobig, moref)
ali2 <- dtw(mosmall, moref)

如果我们打印出对齐结果,结果是:

DTW alignment object
Alignment size (query x reference): 130 x 105
Call: dtw(x = mobig, y = moref)
DTW alignment object
Alignment size (query x reference): 100 x 105
Call: dtw(x = mosmall, y = moref)

那么我们到底想要什么?根据我的理解,我们需要使用扭曲函数 ali1$index1ali1$index2 来缩小或扩大时间序列。但是,如果我们调用以下命令

length(ali1$index1)
length(ali2$index1)
length(ali1$index2)
length(ali2$index2)

结果是

[1] 198
[1] 162
[1] 198
[1] 162

这些是带有索引的向量(可能指其他向量)。我们可以使用其中哪一项来进行映射?是不是都太长了?

最佳答案

首先,我们需要同意 index1index2 是两个长度相同的向量,将查询/输入数据映射到引用/存储数据,反之亦然.

由于您没有提供任何数据。这里有一些虚拟数据,可以让人们有一个想法。

# Reference data is the template that we use as reference. 
# say perfect pronunciation from CNN
data_reference <- 1:10
# Query data is the input data that we want to map to our reference
# say random youtube audio
data_query <- seq(1,10,0.5) + rnorm(19)
library(dtw)
alignment <- dtw(x=data_query, y=data_reference, keep=TRUE)
alignment$index1
alignment$index2
lcm <- alignment$costMatrix
image(x=1:nrow(lcm), y=1:ncol(lcm), lcm)
plot(alignment, type="threeway")

以下是输出:

enter image description here enter image description here

> alignment$index1
[1] 1 2 3 4 5 6 7 7 8 9 10 11 12 13 13 14 14 15 16 17 18 19
> alignment$index2
[1] 1 1 1 2 2 3 3 4 5 6 6 6 6 6 7 8 9 9 9 9 10 10

基本上,从索引1到索引2的映射就是如何将输入数据映射到引用数据。

即输入数据的第 10 个数据点已与模板中的第 6 个数据点匹配。

index1: Warping function φx(k) for the query

index2: Warping function φy(k) for the reference

-- Toni Giorgino

根据你的问题,“索引的长度是怎么回事”,因为它基本上是最佳路径的坐标,它可能只要m+n(真的浅)或 min(m,n) (完美对角线)。显然,这不是一对一的映射,这可能会让人有点困扰,我想你可以从这里做更多的研究,如何选择你想要的映射。

<小时/>

我不知道是否有一些内置函数功能可以获取最佳的一对一映射。但这是一种方法。

library(plyr)
mapping <- data.frame(index1=alignment$index1, index2=alignment$index2)
mapping <- ddply(mapping, .(index1), summarize, index2_new = max(index2))

现在映射包含从查询到引用的一对一映射。然后,您可以将查询映射到引用,并以您想要的任何方式缩放映射的输入。

我不太确定下面的内容,非常欢迎任何人对映射和缩放的工作方式进行任何改进。

引用文献:1 , 2

关于r - 了解动态时间扭曲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25735766/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com