-
Notifications
You must be signed in to change notification settings - Fork 17
Add quadrature algorithm for stochastic steady state calculation #158
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com>
Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com>
Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com>
Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com>
Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com>
…ing impulse response function plots and saving them to the documentation assets directory. This script was previously used to facilitate the regeneration of documentation plots.
…on! for combining multiple solutions (#153) * Initial plan * Refactor plot_solution to accept single algorithm and add plot_solution! Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com> * Update tests for new plot_solution API Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com> * Remove duplicate include of default_options.jl in MacroModelling.jl * Add relevant input differences table to plot_solution! for comparing multiple solutions Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com> * Fix plot_solution to handle single container case on first call Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com> * Implement legend with 2 columns and show relevant input difference for single difference case Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com> * Add support for multiple states with separate plot sets per state Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com> * order of legend items * Adjust layout heights in _plot_solution_from_container to accommodate varying input differences * fix plot solution * Enhance functionality tests by adding comprehensive plot_solution! tests for multiple algorithms and states --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com> Co-authored-by: thorek1 <thorek1@users.noreply.github.com> Co-authored-by: Thore Kockerols <Thore.Kockerols@ecb.europa.eu>
…977-682bd45f4534
thorek1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- use QuasiMonteCarlo.jl for the sobol samples
- write a function similar to write_ss_check_function! that generates a function using the dynamic equations and has as input the parameters, the variables in non stochastic steady state (if so defined in the model), the state (all variables which are then mapped to the the respective timings), and the exogenous shocks.
- the optimisation routine that takes the parameters, steady state values and shock samples as given and finds the state that minimizes the residuals across shock draws
Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com>
I've refactored the quadrature implementation per your feedback:
f(residual, parameters, NSSS_vars, state_past, state_present, state_future, shocks)The function is stored in
Changes in commit cfca4f4 (to be pushed). Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
This PR implements a new
:quadraturealgorithm option forget_steady_statethat calculates the stochastic steady state by integrating out shocks using the dynamic equations of the model.Overview
The quadrature method provides an alternative approach to finding the stochastic steady state that uses quasi-random sampling and numerical integration with the model's dynamic equations rather than relying solely on perturbation solution terms.
Implementation Details
Algorithm
New Features
write_quadrature_dynamic_function!()similar towrite_ss_check_function!()that generates a compiled function from model's dynamic equationsoptimize_quadrature_sss()that takes parameters, steady state values, and shock samples as inputsArchitecture
The implementation follows established patterns in the codebase:
write_quadrature_dynamic_function!()generates a function with signature:f(residual, parameters, NSSS_vars, state_past, state_present, state_future, shocks)𝓂.quadrature_dynamic_funcfield (similar toSS_check_func)Usage Example
Testing
Tested successfully with the FS2000 model:
Additional Changes
src/MacroModelling.jlto define constants before use (fixes compilation error whereDEFAULT_VARIABLES_EXCLUDING_OBCwas undefined)erfinvimport from SpecialFunctions for inverse error function needed in normal distribution transformationFiles Changed
src/quadrature_sss.jl(new): Core implementation of the quadrature algorithm with modular functionssrc/get_functions.jl: Integration withget_steady_statefunctionsrc/MacroModelling.jl: Include order fix, QuasiMonteCarlo import, and dynamic function field initializationsrc/structures.jl: Addedquadrature_dynamic_funcfield to model structsrc/macros.jl: Initializequadrature_dynamic_funcin model macroProject.toml: Added QuasiMonteCarlo.jl dependencyOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.