- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 R 中的 dtw 包来对齐时间序列数据。我可以很容易地获得对齐,但无法弄清楚如何显示来自两个时间序列匹配(拉伸(stretch)/压缩对齐)的峰值的最佳对齐。绘制对齐结果会导致相应的峰在它们之间显示虚线,而不是显示拉伸(stretch)版本。如何同时显示两个波形的拉伸(stretch)版本。
这是我正在使用的代码:
library(dtw)
p149 <- c(-13.000,-20.637,-19.000,-11.000,2.604,10.000,44.000,57.327,44.000,10.000,2.313,-11.000,-20.000,-6.545,1.000,52.000,70.082,57.000,17.000,18.593,0.000,5.000,4.754,4.000,-3.000,-1.204,-1.000,10.000,26.964,25.000,43.000,57.435,40.000,17.000,12.874,-2.000,-16.000,-27.441,-23.000,-24.000,-31.418,-20.000,-11.000,-13.463,-6.000,-3.000,-4.643,-2.000,-2.000,-4.643,-3.000,-6.000,7.727,10.000,44.000,53.049,40.000,-3.000,-14.796,-24.000,-24.000,-31.708,-20.000,-11.000,-14.598,-7.000,-7.000,-10.321,-7.000,-7.000,-10.321,-7.000,-7.000,6.591,10.000,44.000,57.327,44.000,10.000,7.727,-6.000,-3.000,6.056,8.000,30.000,38.152,29.000,5.000,-2.474,-11.000,-19.000,-30.548,-23.000,-24.000,-31.418,-20.000,-11.000,-14.598,-7.000,-7.000,6.591,10.000,44.000,57.327,44.000,10.000,8.388,-5.000,-1.000,-3.134,-1.000,-5.000,-12.802,-11.000,-20.000,-27.431,-20.000,-11.000,-8.966,-1.000,10.000,12.209,10.000)
p547 <- c(-2.000,7.554,-2.000,40.000,49.062,40.000,-3.000,-14.796,-24.000,-24.000,-29.912,-18.000,-6.000,18.559,24.000,73.000,93.119,69.000,12.000,23.458,3.000,41.000,51.912,41.000,2.000,-0.353,-11.000,1.000,15.803,18.000,41.000,47.903,33.000,-5.000,-12.677,-20.000,-11.000,-18.876,-11.000,-20.000,-28.646,-21.000,-15.000,-23.738,-15.000,-21.000,-25.161,-16.000,-1.000,2.826,7.000,7.000,12.736,9.000,14.000,11.417,6.000,-14.000,-24.368,-22.000,-19.000,-28.863,-19.000,-21.000,-33.117,-23.000,-24.000,-35.696,-24.000,-24.000,-26.076,-14.000,6.000,3.654,6.000,-14.000,-9.964,-8.000,24.000,28.462,24.000,-8.000,-14.461,-19.000,-8.000,-8.920,-2.000,-2.000,-7.212,-6.000,-13.000,-23.740,-19.000,-22.000,-18.166,-8.000,24.000,38.372,34.000,22.000,25.179,11.000,2.000,-2.715,-6.000,-13.000,-2.550,2.000,41.000,66.592,56.000,46.000,49.651,24.000,-8.000,-9.964,-14.000,6.000,3.654,6.000,-14.000,-20.663,-19.000)
alignment<-dtw(p149,p547,keep=TRUE);
## Display the warping curve, i.e. the alignment curve
plot(alignment,type="twoway")
## Align and plot with the Rabiner-Juang type VI-c unsmoothed recursion
plot(
dtw(p149,p547,keep=TRUE,
step=rabinerJuangStepPattern(6,"c")),
type="twoway",offset=-2)
最佳答案
我想出了如何做到这一点,我正在分享它以帮助任何可能最终在这里寻找 future 相同功能的人。
seqA <-c(-11.742,-1.551,1.308,27.407,35.801,28.623,4.954,-2.764,-11.158,-19.713,-23.946,-16.228,-0.704,2.448,6.681,5.925,6.727,3.576,-0.367,14.088,13.286,44.535,69.689,55.234,45.382,52.561,27.407,1.308,17.538,10.359,54.563,67.731,51.501,1.173,-9.114,-22.282,-18.866,-8.115,2.172,40.83,57.634,46.884,20.334,17.809,1.004,-11.104,-0.201,2.324,41.286,63.263,52.361,35.548,36.336,14.359,-11.207,1.961,1.173,51.501,70.743,57.575,19.396,20.859,1.617,4.237,15.738,14.274,31.729,61.01,49.509,67.613,82.489,53.209,6.298,5.921,-8.956,7.448,13.125,13.502,9.206,8.035,2.358,-7.042,9.188,10.359,54.563,77.641,61.411,30.903,34.231,11.153,2.159,11.689,8.361,29.758,50.607,41.077,42.317,56.964,36.116,22.472,50.634,35.987,76.662,96.623,68.461,11.382,4.157,-15.804,-13.096,-19.99,-12.765,-14.809,-21.703,-14.809,-12.765,-0.66,6.233,42.184,56.639,44.535,13.286,8.412,-6.043,-13.453,-10.957,-6.083,16.067,32.967,30.471,37.128,51.155,34.255,21.852,17.266,3.239,-21.581,-19.345,-14.759,23.705,33.855,31.619,8.981,18.511,8.361,29.758,55.064,45.534,55.689,81.615,56.309,47.395,53.84,27.914,-2.134,-7.008,-13.453,-6.043,-2.715,2.159,11.153)
seqB <-c(-11.742,-1.551,1.308,27.407,47.636,40.457,40.457,44.574,24.345,-7.879,-14.461,-18.577,-7.751,-8.259,-1.677,-0.355,-8.776,-8.268,-25.417,-23.801,-15.38,21.845,42.073,40.457,40.457,47.636,27.407,1.308,17.538,10.359,54.563,67.731,51.501,1.173,-9.114,-22.282,-18.866,-8.115,2.172,40.83,57.634,46.884,20.334,17.809,1.004,-11.104,-0.201,2.324,41.286,63.263,52.361,35.548,70.743,57.575,19.396,20.859,1.617,4.237,15.738,14.274,31.729,61.01,49.509,67.613,82.489,53.209,6.298,5.921,-8.956,7.448,13.125,13.502,9.206,7.013,1.336,-10.109,5.099,7.293,53.541,66.709,51.501,1.173,-5.409,-18.577,-7.751,1.779,8.361,29.758,50.607,41.077,42.317,56.964,36.116,22.472,50.634,35.987,76.662,102.299,74.137,28.41,26.861,1.225,-7.42,-14.313,-12.765,-14.809,-22.725,-15.832,-15.832,-4.75,3.166,41.162,55.617,44.535,13.286,8.412,-6.043,-13.453,-10.957,-6.083,16.067,32.967,30.471,37.128,51.155,34.255,21.852,17.266,3.239,-21.581,-19.345,-14.759,23.705,33.855,31.619,8.981,18.511,8.361,29.758,55.064,45.534,55.689,81.615,56.309,47.395,53.84,27.914,-2.134,-7.008,-13.453,-6.043,-4.863,0.011)
## Find the best match with dynamic time warping
library(dtw);
alignment<-dtw(seqA,seqB,keep=TRUE,dist.method="Euclidean");
##Extract just the warped version of seqA from the alignment
seqAindex<-dput(as.double(alignment$index1s));
stretchedseqA<-(seqA[c(seqAindex)]);
##Extract just the warped version of seqB from the alignment
seqBindex<-dput(as.double(alignment$index2s));
stretchedseqB<-(seqB[c(seqBindex)]);
##Plot the vectors after warping
plot(stretchedseqA, type="l", col="red",xlab="Position", ylab="Peak Height", main="Warped Vectors-The Alignment")
lines(stretchedseqB, type="l", col="blue")
legend(1, 95, legend=c("SeqA", "SeqB"),col=c("red", "blue"), lty=1:1, cex=0.8)
关于r - 在 R 中查看最佳 dtw 对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60209673/
我正在从 Stata 迁移到 R(plm 包),以便进行面板模型计量经济学。在 Stata 中,面板模型(例如随机效应)通常报告组内、组间和整体 R 平方。 I have found plm 随机效应
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 6年前关闭。 Improve this qu
我想要求用户输入整数值列表。用户可以输入单个值或一组多个值,如 1 2 3(spcae 或逗号分隔)然后使用输入的数据进行进一步计算。 我正在使用下面的代码 EXP <- as.integer(rea
当 R 使用分类变量执行回归时,它实际上是虚拟编码。也就是说,省略了一个级别作为基础或引用,并且回归公式包括所有其他级别的虚拟变量。但是,R 选择了哪一个作为引用,以及我如何影响这个选择? 具有四个级
这个问题基本上是我之前问过的问题的延伸:How to only print (adjusted) R-squared of regression model? 我想建立一个线性回归模型来预测具有 15
我在一台安装了多个软件包的 Linux 计算机上安装了 R。现在我正在另一台 Linux 计算机上设置 R。从他们的存储库安装 R 很容易,但我将不得不使用 安装许多包 install.package
我正在阅读 Hadley 的高级 R 编程,当它讨论字符的内存大小时,它说: R has a global string pool. This means that each unique strin
我们可以将 Shiny 代码写在两个单独的文件中,"ui.R"和 "server.R" , 或者我们可以将两个模块写入一个文件 "app.R"并调用函数shinyApp() 这两种方法中的任何一种在性
我正在使用 R 通过 RGP 包进行遗传编程。环境创造了解决问题的功能。我想将这些函数保存在它们自己的 .R 源文件中。我这辈子都想不通怎么办。我尝试过的一种方法是: bf_str = print(b
假设我创建了一个函数“function.r”,在编辑该函数后我必须通过 source('function.r') 重新加载到我的全局环境中。无论如何,每次我进行编辑时,我是否可以避免将其重新加载到我的
例如,test.R 是一个单行文件: $ cat test.R # print('Hello, world!') 我们可以通过Rscript test.R 或R CMD BATCH test.R 来
我知道我可以使用 Rmd 来构建包插图,但想知道是否可以更具体地使用 R Notebooks 来制作包插图。如果是这样,我需要将 R Notebooks 编写为包小插图有什么不同吗?我正在使用最新版本
我正在考虑使用 R 包的共享库进行 R 的站点安装。 多台计算机将访问该库,以便每个人共享相同的设置。 问题是我注意到有时您无法更新包,因为另一个 R 实例正在锁定库。我不能要求每个人都关闭它的 R
我知道如何从命令行启动 R 并执行表达式(例如, R -e 'print("hello")' )或从文件中获取输入(例如, R -f filename.r )。但是,在这两种情况下,R 都会运行文件中
我正在尝试使我当前的项目可重现,因此我正在创建一个主文档(最终是一个 .rmd 文件),用于调用和执行其他几个文档。这样我自己和其他调查员只需要打开和运行一个文件。 当前设置分为三层:主文件、2 个读
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 5年前关闭。 Improve this qu
我的 R 包中有以下描述文件 Package: blah Title: What the Package Does (one line, title case) Version: 0.0.0.9000
有没有办法更有效地编写以下语句?accel 是一个数据框。 accel[[2]]<- accel[[2]]-weighted.mean(accel[[2]]) accel[[3]]<- accel[[
例如,在尝试安装 R 包时 curl作为 usethis 的依赖项: * installing *source* package ‘curl’ ... ** package ‘curl’ succes
我想将一些软件作为一个包共享,但我的一些脚本似乎并不能很自然地作为函数运行。例如,考虑以下代码块,其中“raw.df”是一个包含离散和连续类型变量的数据框。函数“count.unique”和“squa
我是一名优秀的程序员,十分优秀!