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

ARIMA model #245

Closed
waynelapierre opened this issue Mar 4, 2021 · 9 comments
Closed

ARIMA model #245

waynelapierre opened this issue Mar 4, 2021 · 9 comments

Comments

@waynelapierre
Copy link

I am looking for an ARIMA package in Julia. I want to make sure fitting an ARIMA(1, 0, 1) is coded as

model = SARIMA(data, order = (1, 0, 1))

fit!(model)
@guilhermebodin
Copy link
Member

It is! 👍🏻 Also equivalent to an ARMA(1, 1)

@waynelapierre
Copy link
Author

I find it much slower than the R package forecast's ARIMA function. How can I increase it speed?

@guilhermebodin
Copy link
Member

Can you post both R and Julia codes?

@guilhermebodin guilhermebodin reopened this Mar 4, 2021
@waynelapierre
Copy link
Author

waynelapierre commented Mar 5, 2021

R

require(forecast)
data <- rnorm(1000000000)
system.time(arima(data, c(1, 0, 1)))


Julia

using StateSpaceModels
data = randn(1_000_000_000)
model = SARIMA(data, order = (1, 0, 1))
@time fit!(model)


@guilhermebodin
Copy link
Member

guilhermebodin commented Mar 5, 2021

I think the problem is the time to first plot issue, for more information please see https://discourse.julialang.org/t/roadmap-for-a-faster-time-to-first-plot/22956/16.

One possible solution is to make the first fit! with a small part of the time series. Also note that @time should be called twice to give the better idea of the code performance after compilation https://docs.julialang.org/en/v1/manual/performance-tips/#Measure-performance-with-[@time](@ref)-and-pay-attention-to-memory-allocation

julia> using StateSpaceModels

julia> data = randn(100);

julia> model = SARIMA(data, order = (1, 0, 1))
SARIMA(1, 0, 1)x(0, 0, 0, 0) model

julia> @time fit!(model)
 16.776509 seconds (56.96 M allocations: 2.864 GiB, 8.90% gc time)
SARIMA(1, 0, 1)x(0, 0, 0, 0) model

julia> @time fit!(model)
  0.002102 seconds (4.01 k allocations: 450.500 KiB)
SARIMA(1, 0, 1)x(0, 0, 0, 0) model

julia> data = randn(100_000);

julia> model = SARIMA(data, order = (1, 0, 1))
SARIMA(1, 0, 1)x(0, 0, 0, 0) model

julia> @time fit!(model)
  0.692014 seconds (5.93 k allocations: 23.525 MiB, 1.28% gc time)
SARIMA(1, 0, 1)x(0, 0, 0, 0) model
> require(forecast)
> data <- rnorm(100000)
> system.time(arima(data, c(1, 0, 1)))
  usuário   sistema decorrido 
    4.219     0.474     4.952 
Warning message:
In arima(data, c(1, 0, 1)) :
  possible convergence problem: optim gave code = 1

For 100000 observations the Julia code seems to be faster than forecast.

@waynelapierre
Copy link
Author

My understanding is that precompilation time is fixed. For computationally intensive tasks, there is no need to warm up a function with smaller data. You seem to suggest the precompilation time is not fixed.

@guilhermebodin
Copy link
Member

guilhermebodin commented Mar 5, 2021

Honestly I am not sure if the precompilation time is fixed, but it is a good practice to keep the results from the second time you run @time.

I think it is fairer to compare the times after the precompilation is done. To be even fairer we should benchmark the packages in the same data. StateSpaceModels.jl might also not be faster than R forecast in all cases, which uses C++ under the hood. In all cases the estimation times of the packages are comparable.

I ran for 10M observations this time

julia> data = randn(10_000_000);
er = (1, 0, 1))
@time fit!(model)

julia> model = SARIMA(data, order = (1, 0, 1))
SARIMA(1, 0, 1)x(0, 0, 0, 0) model

julia> @time fit!(model)
 32.786926 seconds (2.80 k allocations: 2.175 GiB, 2.53% gc time)
SARIMA(1, 0, 1)x(0, 0, 0, 0) model
> data <- rnorm(10000000)
system.time(arima(data, c(1, 0, 1)))
> system.time(arima(data, c(1, 0, 1)))
  usuário   sistema decorrido 
   35.186     1.274    38.186

@waynelapierre
Copy link
Author

waynelapierre commented Mar 5, 2021

Thanks for your explanation! I really like your great package. The name SpaceStateModels scared me off when I was trying to find an ARIMA modeling package in Julia. I have no idea what space state models mean. By reading the documents, I find it offers many common time series modeling functions. This package seems to be much more general than its name suggests.

@guilhermebodin
Copy link
Member

I agree that the name is not super accurate, it is closer to R forecast than from any control toolbox. Thank you for your feedback, I am always happy to see people using it :)

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