helske / KFAS

KFAS: R Package for Exponential Family State Space Models
64 stars 17 forks source link

daily time series data runs very slow on SSM #47

Closed suprajamalladi closed 3 years ago

suprajamalladi commented 4 years ago

Hello, i have tried analyzing data of all frequencies in KFAS and daily data runs extremely slow and almost takes about 3 hours most of the time to stop running. i have used frequency of 365 and 250 to exclude all the holidays when analyzing stock price data and it is the same. is there a way to get results faster?

helske commented 4 years ago

Hard to say based on what you write, how many data points do you have and how long is the state vector? Is your model gaussian or non-gaussian?

suprajamalladi commented 4 years ago

sorry I didn't give you the details earlier. The dataset has 1800 points. the model is gaussian and the model has 4 parameters: level, trend, seasonal, variance (H). Below is my model:

model <-SSModel(data.1~SSMtrend(2,Q=list(NA,NA))+ SSMseasonal(period=251,sea.type='dummy',Q=NA),data=data.1,H=NA)

ownupdatefn <- function(pars,model,...){ model$H[] <- exp(pars[1]) diag(model$Q[,,1])[1:3]<- exp(c(pars[2],pars[3],pars[4])) model }

kfasfit <-fitSSM(inits=rep(log(var(data.1)),4), model=model, updatefn=ownupdatefn,method='BFGS')

helske commented 4 years ago

Ok, the issue is in your seasonal component, you have 250+ states which will slow down the recursions. You could try this kind of approach: https://robjhyndman.com/hyndsight/longseasonality/ (you can find the fourier function from the forecast package). Another option would be to use cyclic component (`SSMcycle), but that is of course theoretically bit different thing than the seasonal component.

suprajamalladi commented 4 years ago

thank you for your response! I will try out your suggestions and check.