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

Filter free estimation #30

Open
wants to merge 87 commits into
base: filter-free
Choose a base branch
from

Conversation

matyasfarkas
Copy link

Implementation of the filter-free DSGE estimation in MacroModelling.jl

Implementation of the filter-free DSGE estimation in MacroModelling.jl
The file is a test suite for filter-free DSGE estimation. 
It:
-solves the RBC model using MacroModelling,
-draws structural shocks from a t-distribution, and initial conditions 
-simulates the data,
-Re-estimates the shocks using filter-free estimation.
Fixed simulation exercise
@codecov-commenter
Copy link

codecov-commenter commented May 25, 2023

Codecov Report

❗ No coverage uploaded for pull request base (filter-free@98ef5e5). Click here to learn what that means.
Patch has no changes to coverable lines.

Additional details and impacted files
@@              Coverage Diff               @@
##             filter-free      #30   +/-   ##
==============================================
  Coverage               ?   60.76%           
==============================================
  Files                  ?        7           
  Lines                  ?     3051           
  Branches               ?        0           
==============================================
  Hits                   ?     1854           
  Misses                 ?     1197           
  Partials               ?        0           

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

thorek1 and others added 10 commits May 26, 2023 15:19
Implementation of the filter-free DSGE estimation in MacroModelling.jl
The file is a test suite for filter-free DSGE estimation. 
It:
-solves the RBC model using MacroModelling,
-draws structural shocks from a t-distribution, and initial conditions 
-simulates the data,
-Re-estimates the shocks using filter-free estimation.
Fixed simulation exercise
@thorek1
Copy link
Owner

thorek1 commented May 26, 2023

@matyasfarkas
Check out the latest version of the filter free file. It works: recovers the shocks and true parameter values and is fast. It breaks down for other setups but let's work from this and generalise step by step.

Suggested next steps (with the setup that works):

  • make the filter free part inside the Turing model a function similar to the Kalman one
  • generalise that function to work with all solution methods (2nd, 3rd order)
  • include Kalman filter in that function

@thorek1
Copy link
Owner

thorek1 commented May 29, 2023

I continued playing around with it and there is an issue with the gradient size of the shocks relative to the parameters. You need the ones for the shocks big enough so that he gets the shocks right but if they are too big he doesn't move around for the parameters at all. Todos:

  • check how that works with the diffstatespacemodels implementation
  • check whether we can use abs(x)^n n>2 as a solution or if abs(x) < epsilon then 0 else abs(x)^n

@thorek1
Copy link
Owner

thorek1 commented May 29, 2023

diffstatespacemodels uses the MvNormal and they also do not recover the latent shocks up to high precision. using other loss functions instead of the MvNormal come down to the same thing and a re a dead end. the std is the key parameter balancing, converge (too small -> no convergence), speed (smaller -> slower), and accuracy (smaller -> more accurate estimates of latent shocks and shock size)

@thorek1
Copy link
Owner

thorek1 commented Aug 6, 2023

I wrote an issue for MuseInference to help us get it working agian. In the meantime, I would suggest to try Gibbs(hamiltonian sampler for model parameters, variational inference for latent states). I hope this brings down inference time, as it is now prohibitive.

The approach is suggested as an alternative in the MuseInference paper and easy to implement in Turing: sample(model, Gibbs(HMC(0.01, 5, :s), ADVI(10, 1000, :m)), 1000).

Here is some theory of combining samplers and some more info about variational inference. I think this could serve as a second best with the first best potentially being MuseInference.

@thorek1
Copy link
Owner

thorek1 commented Aug 6, 2023

in hindsight, maybe the trick is really to break the correlation structure between the latent states and the parameters because for small Omega that seems to be where he got stuck

@thorek1
Copy link
Owner

thorek1 commented Aug 9, 2023

after some investigation we figured that MuseInference works if Julia is single threaded. it errors with more than one thread

@thorek1
Copy link
Owner

thorek1 commented Aug 18, 2023

I experimented a bit with Turing and using a Gibbs sampler to separate the sampling of the latent states and the parameters. My experiments showed that this doesn't really help in making the sampling more efficient. While playing around I came up with another idea: instead of integrating out the latent states, minimise the square sum of the shock sizes which have the model fit the data exactly. another issue is the initial value. instead of figuring out the likelihood given the ergodic distribution I would add more shocks before the time series starts and have an initial value = NSSS at t - x plus x shocks which bring the system to the actual initial value . I think this is a neat trick but a minor issue with this technique is that additionally you need to take derivatives wrt shocks.

@thorek1
Copy link
Owner

thorek1 commented Aug 18, 2023

another thing I figured out is that any symmetric distribution is approximated by minimal sum of squares. in that sense estimating the degrees of freedom of the student T distribution with a uniform prior was at best confusing for the sampler.

@thorek1
Copy link
Owner

thorek1 commented Sep 7, 2023

after some thinking: easiest would be to use UKF. see an implementation here

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

Successfully merging this pull request may close these issues.

None yet

4 participants