2016-11-11 153 views
0

在下面的代碼中,我試圖在不同的核心上同時訓練兩個不同的auto.arima模型。當我嘗試運行代碼時,出現以下錯誤。我不確定我的問題是否與do.call或parLapply一起使用,我也是並行處理的新手,所以任何提示都非常有幫助。並行訓練多個Auto.Arima模型

Code: 
library("forecast") 
library("parallel") 

TList2<-list(x=tsd1, lambda = Tlambda, stepwise=TRUE, approximation = TRUE) 
DList2<-list(x=tsd2, lambda = Rlambda, stepwise=TRUE, approximation = TRUE) 

##Parallelizing ARIMA Model Training 

# Calculate the number of cores 
no_cores <- 1 

# Initiate cluster 
cl <- makeCluster(no_cores) 

ARIMA_List<-list(TList2,DList2) 

ARIMA_Models<-parLapply(cl, ARIMA_List, 
        function(x){do.call(auto.arima, args=x)}) 

stopCluster(cl) 


Error: 
Error in checkForRemoteErrors(val) : 
    one node produced an error: object 'auto.arima' not found 

Data: 

dput(TList2) 
structure(list(x = c(6, 15.5, 22, 16, NA, NA, 13, 13.5, 10, 6, 
14.5, 16, NA, 8, 11, NA, 2, 2, 10, NA, 9, NA, 11, 16, NA, 4, 
17, 7, 11.5, 22, 20.5, 10, 22, NA, 13, 17, 22, 9, 13, 19, 8, 
16, 18, 22, 21, 14, 7, 20, 21.5, 17), lambda = 0.999958829041611, 
    stepwise = TRUE, approximation = TRUE), .Names = c("x", "lambda", 
"stepwise", "approximation")) 

dput(DList2) 
structure(list(x = c(11, 4, 8, 11, 11, NA, 3, 2.5, 6, 11, 7, 
1, NA, 6, 6, NA, 6, 11, 3, NA, 11, NA, 10, 10, NA, NA, 9, 3, 
3, 11, 8, 10, NA, NA, 11, 10, 9, 3, 7, NA, 2, 4, 11, 2.5, 3, 
NA, 4, 7, 1, 5), lambda = 0.170065851742339, stepwise = TRUE, 
    approximation = TRUE), .Names = c("x", "lambda", "stepwise", 
"approximation")) 

回答

0

我覺得forecast::auto.arima應該可以在集羣,也因此使用clusterEvalQ這樣的嘗試,例如:

TList2 <- structure(list(x = c(6, 15.5, 22, 16, NA, NA, 13, 13.5, 10, 6, 
14.5, 16, NA, 8, 11, NA, 2, 2, 10, NA, 9, NA, 11, 16, NA, 4, 
17, 7, 11.5, 22, 20.5, 10, 22, NA, 13, 17, 22, 9, 13, 19, 8, 
16, 18, 22, 21, 14, 7, 20, 21.5, 17), lambda = 0.999958829041611, 
    stepwise = TRUE, approximation = TRUE), .Names = c("x", "lambda", 
"stepwise", "approximation")) 

DList2<- structure(list(x = c(11, 4, 8, 11, 11, NA, 3, 2.5, 6, 11, 7, 
1, NA, 6, 6, NA, 6, 11, 3, NA, 11, NA, 10, 10, NA, NA, 9, 3, 
3, 11, 8, 10, NA, NA, 11, 10, 9, 3, 7, NA, 2, 4, 11, 2.5, 3, 
NA, 4, 7, 1, 5), lambda = 0.170065851742339, stepwise = TRUE, 
    approximation = TRUE), .Names = c("x", "lambda", "stepwise", 
"approximation")) 

library("forecast") 
library("parallel") 
cl <- makeCluster(no_cores) 
clusterEvalQ(cl, library(forecast)) 
ARIMA_List<-list(TList2,DList2) 
ARIMA_Models<-parLapply(cl, ARIMA_List, 
        function(x){do.call(auto.arima, args=x)}) 
stopCluster(cl) 
+0

謝謝你,沒有的伎倆!我對並行處理相當陌生,是在兩個不同內核上同時訓練兩個模型的代碼?還有什麼添加clusterEvalQ(CL,庫(預測))呢? – user6183069

+0

我對平行計算也很陌生。並且我收藏了[this](http://stackoverflow.com/questions/18357788/parallel-parlapply-setup)帖子,這或多或少是你的副本。直覺上,我會說,如果你只使用1個內核,它沒有什麼區別。但如果你註冊更多,它應該做你期望的 - 並行運行arima。 – lukeA