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

Fix all parameters and calculate just the likelihood for a filter #328

Open
FelixNoessler opened this issue Jul 12, 2024 · 1 comment
Open

Comments

@FelixNoessler
Copy link

Hello,

is it possible to calculate the marginal log likelihood given the observations and the model parameters? I want to do thinks similar to this tutorial from PINTS with statsmodesl in python: https://github.com/pints-team/pints/blob/main/examples/interfaces/statsmodels-state-space.ipynb

A bit simplified, they do:

model = UnobservedComponents(endog = [...], level='llevel')
model.loglike(parameters)

I tried it with StateSpaceModels.jl, but I get just NaN from the loglike function:

model = LocalLevel(rand(100))
fix_hyperparameters!(model, Dict("sigma2_ε" => 5.0, "sigma2_η" => 2.0))
loglike(model)

Then, I manually set the unconstrained parameter and it worked:

model = LocalLevel(rand(100))
fix_hyperparameters!(model, Dict("sigma2_ε" => 5.0, "sigma2_η" => 2.0))
model.hyperparameters.unconstrained_values = [sqrt(5.0), sqrt(2.0)]
loglike(model)

Is this the right marginal likelihood that I can use to run a MCMC algorithm to infer the variance (and some model) parameters?

Best,
Felix

@raphaelsaavedra
Copy link
Member

Hey @FelixNoessler,

It's been a while since I looked at this code, but I think the reason the first try didn't work and the second did is that loglike looks for the unconstrainted values of the parameters in order to compute the loglikelihood. These unconstrained values should be populated when fitting a model.

Basically, when we implemented this, I think we didn't envision a use case where a user would want the loglikelihood without fitting a model. But yes, based on what you did, loglike will take those set values and run the Kalman iterations in order to compute the loglikelihood using the specified parameters.

Hope this helps!

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