-
Notifications
You must be signed in to change notification settings - Fork 24
/
auto_arima.R
51 lines (46 loc) · 1.32 KB
/
auto_arima.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#! /usr/bin/Rscript
################
### set path ###
################
path = "/home/student/.xiaoqian/darima"
setwd(path)
##################
### gefcom2017 ###
##################
load("data/gefcom2017.RData")
################
### packages ###
################
library(forecast)
library(magrittr)
library(polynom)
library(quantmod)
# parallel computation
library(parallel)
library(doParallel)
library(foreach)
###################################
### auto.arima (method = "CSS") ###
###################################
for (ncores in c(1,2,4,8,16,32)){
print(paste0("Begin: ncores = ", ncores))
t0_arima <- Sys.time()
f_arima <- lapply(gefcom2017, function(lentry){
t0 <- Sys.time()
fit <- forecast::auto.arima(lentry$x, method = "CSS",
stepwise = FALSE, parallel = TRUE,
approximation = FALSE,
num.cores = ncores)
forec <- forecast(fit, h = lentry$h)
t1 <- Sys.time()
tt <- t1 - t0
return(append(lentry, list(fit = fit, forec = forec, time = tt)))
})
assign(paste0("f_arima_NC", ncores), f_arima)
t1_arima <- Sys.time()
time_arima <- t1_arima - t0_arima
print(paste0("End: ncores = ", ncores))
print(time_arima)
rm(t0_arima, t1_arima, time_arima, f_arima)
}
save.image("data/auto_arima_result.RData")