簡體   English   中英

R 中的參數時間扭曲

[英]Parametric Time Warping in R

我正在處理 R 中的 PTW 示例,它運行良好。 但是,當我嘗試用我自己的數據替換示例中的數據時,我得到了錯誤。 我的數據格式與示例數據相同,所以我不知道我做錯了什么。

這有效:

data(gaschrom)
ref <- gaschrom[1:8,]
samp <- gaschrom[9:16,]
gaschrom.ptw <- ptw(ref, samp, warp.type = "individual",
optim.crit = "RMS", init.coef = c(0, 1, 0, 0))
plot(gaschrom.ptw)
plot(gaschrom.ptw, what = "signal")

但是,當我加載自己的數據(如下)時,它失敗了。 我的數據是包含 123 個變量的 3 個觀察值。 R 認識到,當我將數據導入 RStudio b

-13,-20.637,-19,-11,2.604,10,44,57.327,44,10,2.313,-11,-20,-6.545,1,52,70.082,57,17,18.593,0,5 ,4.754,4,-3,-1.204,-1,10,26.964,25,43,57.435,40,17,12.874,-2,-16,-27.441,-23,-24,-31.418,-20 ,-11,-13.463,-6,-3,-4.643,-2,-2,-4.643,-3,-6,7.727,10,44,53.049,40,-3,-14.796,-24, -24,-31.708,-20,-11,-14.598,-7,-7,-10.321,-7,-7,-10.321,-7,-7,6.591,10,44,57.327,44,10 ,7.727,-6,-3,6.056,8,30,38.152,29,5,-2.474,-11,-19,-30.548,-23,-24,-31.418,-20,-11,-14.598 ,-7,-7,6.591,10,44,57.327,44,10,8.388,-5,-1,-3.134,-1,-5,-12.802,-11,-20,-27.431,-20 ,-11,-8.966,-1,10,12.209,10 -2,7.554,-2,40,49.062,40,-3,-14.796,-24,-24,-29.912,-18,-6, 18.559,24,73,93.119,69,12,23.458,3,41,51.912,41,2,-0.353,-11,1,15.803,18,41,47.903,33,-5,-12.677,-20 ,-11,-18.876,-11,-20,-28.646,-21,-15,-23.738,-15,-21,-25.161,-16,-1,2.826,7,7,12.736,9, 14,11.417,6,-14,-24.368,-22,-19,-28.863,-19,-21,-33.117,-23,-24,-35.696,-24,-24,-26.076,-14 ,6,3.654,6,-14,-9.964,-8,24,28.462,24,-8,-14.461,-19,-8,-8.92,-2,-2,-7.212,-6,- 13,-23.74,-19,-22,-18.166,-8 ,24,38.372,34,22,25.179,11,2,-2.715,-6,-13,-2.55,2,41,66.592,56,46,49.651,24,-8,-9.964,-14, 6,3.654,6,-14,-20.663,-19 -19,-27.154,-17,-17,-22.032,-13,-6,-10.917,-6,-13,-22.032,-17, -17,-22.032,-13,-6,-10.917,-6,-13,-22.032,-17,-17,-22.032,-13,-6,-10.917,-6,-13,-2.702 ,2,41,55.285,45,13,16.614,2,11,14.481,11,2,-6.924,-10,-26,-23.842,-15,24,36.204,34,16,27.907,15, 32,46.134,34,22,21.475,7,-9,-17.535,-17,-17,-22.032,-13,-6,-4.863,0,5,5.889,5,0,-4.863,- 6,-13,-22.032,-17,-17,-25.736,-17,-17,-25.736,-17,-17,-25.736,-17,-17,-25.736,-17,-17, -25.736,-17,-17,-25.736,-17,-17,-25.736,-17,-17,-25.736,-17,-17,-25.736,-17,-17,-25.736,-17 ,-17,-25.736,-17,-17,-25.736,-17,-17,-25.736,-17,-17,-6.407,2,41,50.162,39,-2,-13.788,-23

我的數據是包含 123 個變量的 3 個觀察值。 R 認識到,當我將數據導入 RStudio 時,但當我嘗試如下運行分析時,它不起作用。

train <- read.csv(file="threesamps2.csv", header=FALSE, sep=",")#this works, the data is brought into "train" and shows to have 3 observations with 123 variables.

ref <- train[1,]# This works and shows 1 obs, 123 variables
samp <- train[2:3,]# This works and shows 2 obs, 123 variables
train.ptw <- ptw(ref, samp, warp.type = "individual",
          optim.crit = "RMS", init.coef = c(0, 1, 0, 0))#This seems to be what is failing.  Why?  It works fine with the sample data.
plot(train.ptw)
plot(train.ptw, what = "signal")

ref 和 samp 都正確加載,但我得到的錯誤是“繪圖錯誤(train.ptw,what = “signal”):object 'train.ptw' not found。” 如果我正確閱讀了代碼,應該創建 train.ptw,但找不到它。 任何想法,將不勝感激。

以防萬一您的問題仍然存在:

我認為問題在於如果您只有一個參考信號,ptw function 需要一個向量。 當我將ref轉換為向量時,它在我的系統(帶有 ptw_1.9-13 的 R 3.6.1)上工作:

train <- read.csv(file="threesamps2.csv", header=FALSE, sep=",")

ref <- as.numeric(train[1,])
samp <- train[2:3,]
train.ptw <- ptw(ref, samp, warp.type = "individual",
          optim.crit = "RMS", init.coef = c(0, 1, 0, 0))
plot(train.ptw)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM