Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto.arima runtime stepwise increase #877

Closed
Someone894 opened this issue Feb 16, 2021 · 1 comment
Closed

auto.arima runtime stepwise increase #877

Someone894 opened this issue Feb 16, 2021 · 1 comment

Comments

@Someone894
Copy link

Hello,

some time ago the runtime of the forecast we are using doubled from one (monthly) execution to the next. So I've wrote a small test script to analyze how the execution time of some of the forecasting method performs with different length timeseries:

start <- 1
end <- 100

# FROM: https://github.com/robjhyndman/M4metalearning/blob/61ddc7101680e9df7219c359587d0b509d2b50d6/R/forec_methods_list.R#L40
auto_arima_forec <- function(x, h) {
  model <- forecast::auto.arima(x, stepwise = FALSE, approximation = FALSE)
  forecast::forecast(model, h = h)$mean
}

generate_random_ts <- function(a = 1:1000, b = 0, c = 7) {
  sin(a * rnorm(1, b, c)) +
	sin(a * rnorm(1, b^2, c^2)) +
	sin(a * rnorm(1, b^3, c^3)) +
	sin(a * rnorm(1, b^4, c^4)) +
	seq(a) / runif(a, 1, 10)
}

set.seed(4711)
truex <- generate_random_ts()
#plot(truex, type = "l")

timeseries <- list()
for (i in start:end) {
  x <- ts(head(truex, i), frequency = 12)
  timeseries <- rlist::list.append(timeseries, x)
}

jobs <- lapply(
  timeseries[1:length(timeseries)],
  function(x) {
	local({
	  x <- x
	  bquote(auto_arima_forec(.(x), 24))
	})
  }
)

names(jobs) <- paste0(
  "Length ts: ",
  stringr::str_pad(start:end, 3, pad = "0")
)

mbm <- microbenchmark::microbenchmark(list = jobs)

save(mbm, file = "mbm.RData")

options(microbenchmark.unit = "eps")
print(mbm)

options(microbenchmark.unit = "relative")
print(mbm)

plot <- ggplot2::autoplot(mbm)
print(plot)

Most of them just (more or less) linearly increase in runtime for longer timeseries, which is to be expected. But the auto.arima method seems to be exploding (4-5 times more execution time) when the timeseries becomes longer then 71 month (=6 Years).

ARIMA_Plot_1-100_lin

Do you know why this is the case and is it possible to decrease the magnitude of this sudden jump?

In order to keep this Issue short I only posted code and image for the auto.arima case.

@ncooder
Copy link

ncooder commented Jan 7, 2025

@Someone894 If you look at these lines:

max.p <- min(max.p, floor(serieslength / 3))

For monthly data if you have exactly 71 months, then floor(71 / (3 * 12)) = floor(71 / 36) = 1.
So max.P and max.Q become 1.
If you have 72 months, then floor(72 / (3 * 12)) = floor(72 / 36) = 2.
So max.P and/or max.Q become 2.
This jump from 1 to 2 in the seasonal orders causes that significant increase the search space. The same is valid for 36 months.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants