Skip to content
/ blaze Public

A C++17 implementation of ARIMA following R

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

JSzitas/blaze

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

blazearima

Lifecycle: experimental R-CMD-check

An intentionally very fast (S)ARIMA(X) implementation. This intends to be as accurate as possible, overcoming both R and statsforecast implementation of arima, while hopefully also being faster, with a lower memory footprint.

On the roadmap is even more refinements to speed, python bindings, and auto arima functionality akin to R’s forecast::auto.arima.

Currently available functionality

A simple object oriented R interface exists:

# create a new object 
arima_obj <- new(BlazeArima, c(lynx[1:100]), c(4, 0, 1, 0, 0, 0, 1), list(), "Gardner", "CSS-ML", c(TRUE, FALSE, TRUE), 1000000)
# fit model
arima_obj$fit()
# create forecasts
arima_obj$forecast(14, list()) -> cpp_fcst
# showcase of fitted model - this is not a particularly great fit: 
plot.ts(c(lynx[91:114]))
lines(c(rep(NA,10), cpp_fcst$forecast), col = "red")
# we can compare this to the R arima implementation:
lines(c(rep(NA,10),predict(arima(c(lynx[1:100]),
                                 order = c(4,0,1), method = "CSS-ML"), 14)$pred),
      col = "blue")

There are some cases where our optimizer (we use cppNumericalSolvers) seems to be more accurate than the default R solver:

p <- 2
d <- 1
q <- 1
P <- 2
D <- 1
Q <- 1
season <- 10
use_mean <- TRUE

train <- c(lynx)[1:100]
test <- lynx[101:114]

arima_obj <- new(BlazeArima, train, c(p, d, q, P, D, Q, season), list(), "Gardner", "CSS-ML", c(use_mean, TRUE), 1000000)
arima_obj$fit()

arima_obj$forecast(14, list()) -> cpp_fcst

arima_mod <- arima(train,
  order = c(p, d, q), seasonal = list(order = c(P, D, Q), period = season),
  include.mean = use_mean,
  transform.pars = TRUE, kappa = 1000000, method = "CSS-ML"
)
predict(arima_mod, 14) -> r_fcst

plot.ts(c(lynx)[91:114])
lines(c( rep(NA, 10), cpp_fcst$forecast), col = "red")
lines(c( rep(NA, 10), r_fcst$pred), col = "green")

This could be attributed to numerous factors - R’s optim uses internal parameter scaling for optimizer line searches, whereas we standardize all inputs. optim uses, as far as I can tell, a version of Armijo line-search(TODO: add refs), whereas cppNumericalSolvers can (and is configured here) to use MoreThuente. There are some other differences in implementation, but these, I think, are most important.

Thanks, recognition

This package really follows the ‘I stand on the shoulders of giants’ idea. It would have never been possible without all the careful work put into R’s arima() implementation done by many member of the R Core Team and others over the years. I do believe professor Ripley is of particular note here, and deserves recognition for being one of the driving forces behind such an awesome project.

I further want to thank the authors of the awesome Eigen C++ template library. This library is one of the silent drivers of much of this computation, particularly the handling of external variables.

Finally, last but not least, I believe the many people who contributed to the great CppNumericalSolvers library deserve recognition. This is the library used for optimization in this package, and it’s relatively straightforward implementation has been a huge boon.

About

A C++17 implementation of ARIMA following R

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages