LAMPSPUC / StateSpaceModels.jl

StateSpaceModels.jl is a Julia package for time-series analysis using state-space models.
https://lampspuc.github.io/StateSpaceModels.jl/latest/
MIT License
272 stars 25 forks source link

LAPACKException for missing/NaN values #299

Closed mapi1 closed 2 years ago

mapi1 commented 2 years ago

I was experimenting with missing values when I ran into LAPACKExceptions for some models (namely LocalLinearTrend and DAR, which are the ones I tested). They seem to arise from the hessian being all NaN in the pinv call caused by the initial_hyperparameters! method missing the [findall(!isnan, model.system.y)] part. This is at least my guess for LocalLinearTrend.

MWE to reproduce:

using StateSpaceModels
input = LinRange(1, 100, 100) + rand(100)
input[10] = NaN
model = LocalLinearTrend(input)
# model = DAR(input, 10)
# model = LocalLevel(input) # works fine
fit!(model; optimizer = Optimizer(StateSpaceModels.Optim.NelderMead()))
guilhermebodin commented 2 years ago

Indeed! I am preparing a quick patch to solve the issue across models. Thank you for pointing it out

guilhermebodin commented 2 years ago

The case for DAR is a little different, since we need to lag the observations vector in the system matrices there are NaNs inside the system matrices. For now I am putting an error message stating that DAR does not accept missing values

guilhermebodin commented 2 years ago

Solved in #300