2
$\begingroup$

I am parallelizing the execution of auto.arima() to forecast 500 Route time series, initially I did setting up a parallel token in auto.arima to be TRUE and number of cores to be 10. It did not impact the execution time but just increased the processing calculations to 10 times more, hence taking more time. Then I did something like this:

modelsPetrol <- list()

registerDoParallel(cores=28)

start=Sys.time()

foreach(i=1:10, .packages=c("forecast"),.combine=cbind) %dopar% {

  filename <- paste("Model_P",temp[[i]],".rda",sep="") 

   t <- matrix(nrow = 750,ncol=10)

   y <- ts(Train_Petrol[,temp[[i]]], frequency = 6)

   t <- fourier(ts(Train_Petrol[,temp[[i]]], frequency=311.50), K=5)

   modelsPetrol[i] <- auto.arima(y,xreg=cbind(t,holi,wday,schl,weekn),approximation=FALSE,trace=FALSE,stepwise=TRUE,lambda = TRUE)

   save(modelsPetrol, file=filename)

    print(modelsPetrol)

   t<-NULL

   y<-NULL
}

The code works fine, with less time, but I am struggling to check models, like summary (modelsPetrol[[1]]) gives an error subscript out of bounds.

$\endgroup$
4
  • $\begingroup$ You should have modelsPetrol[[i]] instead of modelsPetrol[i]. $\endgroup$
    – mpiktas
    Commented Oct 29, 2015 at 7:35
  • $\begingroup$ Running auto.arima() as multicore processing yields slightly different coef. from the model ran without parallelizing ....which greatly impacts the forecasts. Can anyone suggest why this is happening. $\endgroup$ Commented Nov 2, 2015 at 4:25
  • $\begingroup$ Just for clarity, what is "temp" and how was it constructed? $\endgroup$ Commented May 28, 2017 at 10:34
  • $\begingroup$ For correct random generation you need to use doRNG library as doParallel does not handle random seeds. $\endgroup$
    – Tim
    Commented May 28, 2017 at 14:56

1 Answer 1

3
$\begingroup$

Finally cracked it... Sharing with all to have chunk of code that facilitates execution of auto.arima() for 500 Routes using parallel multi core processing:

parallel.arima<-function(data) {

library(forecast)

 t <- matrix(nrow = 750,ncol=10)

 y <- ts(data, frequency = 6)

 t <- fourier(ts(data, frequency=311.50), K=5)

 fit <-auto.arima(y,xreg=cbind(t,wday,weekn),approximation=FALSE,trace=FALSE,stepwise=TRUE)

 t<-NULL

 y<-NULL

 return(fit)
}

models <-list()

modelsP<-list()

registerDoParallel(cores=20)

start=Sys.time()

models <- foreach(i =1:length(temp)) %dopar% {

 modelsP[[i]] <- parallel.arima(Train_Petrol[,temp[[i]]])

}

end=Sys.time()

Works well..!!

$\endgroup$
5
  • 1
    $\begingroup$ Some advice. Don't use more cores than you have logical cores on your PC. Thus rarely more than 4 or 8 cores. $\endgroup$ Commented Oct 29, 2015 at 7:05
  • 2
    $\begingroup$ Thanks, Yes definitely... running this on 28 core machine... $\endgroup$ Commented Oct 29, 2015 at 7:10
  • 1
    $\begingroup$ Cross-posted: stackoverflow.com/questions/33405076/looping-and-auto-arima. Please avoid. $\endgroup$
    – user81847
    Commented Oct 29, 2015 at 8:12
  • $\begingroup$ @RachnaDhand could you figure out why auto.arima() doesn't improve automatically? $\endgroup$
    – RandomDude
    Commented Nov 11, 2015 at 19:40
  • $\begingroup$ @RachnaDhand could you explain what temp is here? $\endgroup$ Commented Feb 28 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.