Comments (8)
Hi caioodantas,
The problem is that when declaring parameters, you have to use Float64 for all of the numbers. For example, the parameter gamma is currently initialized as
m <= parameter(:γ, 1, (1e-3, 10), (1e-3, 10), ModelConstructors.Exponential(), RootInverseGamma(1, 0.75), fixed=false,
description="γ: Risk aversion.",
tex_label="\\gamma")
but the parameter value should be 1.
, or 1.0
. Using 1
gives the parameter an Int64
, which does not satisfy the type restrictions of a Parameter
type (we need Float64 everywhere to ensure type stability for MH or SMC sampling). Similarly, the bounds should be (1e-3, 10.)
, the transform parameterization should be (1e-3, 10.)
, and the prior should be RootInverseGamma(1., 0.75)
. Additionally note that the second tuple is not a value bound but a transform parameterization, i.e. it parameterizes the Exponential
transform applied when finding the mode using csminwel
. If the transform applied was either the SquareRoot
or Untransformed
transformations, then the parameters are actually just the value bounds, but in the Exponential
case, the parameters are not the value bounds (I understand this may be a confusing point. I've added this subtlety to the docket for things to add to our documentation). However, it is typically fine to use the same parameters as the value bounds (it just works out that way), but you should still see the docstring for transform_to_model_space
here.
You should also make sure to copy the observables.jl
, pseudo_observables.jl
, and init_subspec.jl
files from AnSchorfheide
and replace the type assertions to XGabaix
in those files. Otherwise, your XGabaix
will not instantiate without error. Once you do these four things, it should work (or at least it did on my machine).
Cool idea by the way! Would be interesting to see a full-blown Bayesian estimation of Gabaix's behavioral model. Definitely let us know if you make headway on estimating this model, and we can try to highlight it as an interesting application of the package.
Best,
William
from dsge.jl.
Ah right, you'll want to set the transform parameterization to (1e-2, 1e-5) so that you don't accidentally hit any bounds due to numerical imprecision. The issue is happening b/c after making a new guess in R, csminwel then transforms the guess back into model space. Depending on the transform's parameterization, you'll get values that are outside the permissible value bounds. An alternative you could try to ensure you don't run into this problem is the SquareRoot transform, whose transformation parameters are just the value bounds, which makes it straightforward to ensuring you don't hit the value bounds.
As an example, if you use (0., 0.), then log(-Inf) = 0.
, which is below the lower bound of 1e-3. So you want a >= 1e-3.
from dsge.jl.
Can you show me the entire gabaix.jl script please? It'll be easier for me to diagnose what's going on that way.
from dsge.jl.
Thank you very much.
https://github.com/caioodantas/Behavioral-New-Keynesian-Model/blob/main/gabaix.jl
from dsge.jl.
Thanks William, your suggestion did fix the issue with init_parameters
. I'm now having trouble with the transform parametrization.
ERROR: LoadError: New value of γ (11.000045391546594) is out of bounds ((0.0010454453523997807, 11.0))
I tried to fix it after reading the transform_to_model_space
docstring, as you suggested, but I seem to have gotten something wrong.
m <= parameter(:γ, 1., (1e-3, 10.), (1e-3 + exp(1e-3 - 10.), 10. + exp(10. - 10.)), ModelConstructors.Exponential(), RootInverseGamma(1., 0.75), fixed=false, description="γ: Risk aversion.", tex_label="\\gamma")
from dsge.jl.
When are you getting this error? Also the transform parameterization for the exponential takes the form (a, b)
, where a
and b
DO NOT correspond to the value bounds at all. They are now just parameters for taking x in (0., Inf)
and mapping to R
, namely f(x; a, b) = a + exp( x - b)
. So the standard exponential transform has parameters (0., 0.)
, corresponding to f(x; 0., 0.) = exp(x)
.
from dsge.jl.
The error occurs right after
Recalculating Hessian... Hessian element: (1, 1)
I tried using parameters (0., 0.)
, but the error persists.
ERROR: LoadError: New value of γ (10.000045399205783) is out of bounds ((0.001, 10.0))
Stacktrace: [1] parameter(::UnscaledParameter{Float64,Exponential}, ::Float64) at C:\Users\Samsung\.julia\packages\ModelConstructors\6QJpO\src\parameters.jl:553 [2] map!(::typeof(parameter), ::Array{AbstractParameter{Float64},1}, ::Array{AbstractParameter{Float64},1}, ::Array{Float64,1}) at .\abstractarray.jl:2197 [3] update!(::Array{AbstractParameter{Float64},1}, ::Array{Float64,1}; change_value_type::Bool) at C:\Users\Samsung\.julia\packages\ModelConstructors\6QJpO\src\parameters.jl:1024 [4] update! at C:\Users\Samsung\.julia\packages\ModelConstructors\6QJpO\src\parameters.jl:1013 [inlined] [5] update! at C:\Users\Samsung\.julia\packages\DSGE\tJSkz\src\abstractdsgemodel.jl:417 [inlined] [6] posterior!(::XGabaix{Float64}, ::Array{Float64,1}, ::Array{Float64,2}; sampler::Bool, ϕ_smc::Float64, catch_errors::Bool) at C:\Users\Samsung\.julia\packages\DSGE\tJSkz\src\estimate\posterior.jl:88 [7] posterior! at C:\Users\Samsung\.julia\packages\DSGE\tJSkz\src\estimate\posterior.jl:76 [inlined] [8] (::DSGE.var"#f_hessian#294"{XGabaix{Float64},Array{Float64,2},Array{Float64,1}})(::Array{Float64,1}) at C:\Users\Samsung\.julia\packages\DSGE\tJSkz\src\estimate\hessian.jl:37 [9] hess_diag_element(::DSGE.var"#f_hessian#294"{XGabaix{Float64},Array{Float64,2},Array{Float64,1}}, ::Array{Float64,1}, ::Int64; ndx::Int64, check_neg_diag::Bool, verbose::Symbol) at C:\Users\Samsung\.julia\packages\DSGE\tJSkz\src\estimate\hessizero.jl:112 [10] hessizero(::Function, ::Array{Float64,1}; check_neg_diag::Bool, verbose::Symbol, distr::Bool) at C:\Users\Samsung\.julia\packages\DSGE\tJSkz\src\estimate\hessizero.jl:32 [11] hessian!(::XGabaix{Float64}, ::Array{Float64,1}, ::Array{Float64,2}; check_neg_diag::Bool, verbose::Symbol) at C:\Users\Samsung\.julia\packages\DSGE\tJSkz\src\estimate\hessian.jl:41 [12] estimate(::XGabaix{Float64}, ::Array{Float64,2}; verbose::Symbol, proposal_covariance::Array{Any,2}, mle::Bool, sampling::Bool, filestring_addl::Array{String,1}, continue_intermediate::Bool, intermediate_stage_start::Int64, intermediate_stage_increment::Int64, save_intermediate::Bool, tempered_update_prior_weight::Float64, run_csminwel::Bool) at C:\Users\Samsung\.julia\packages\DSGE\tJSkz\src\estimate\estimate.jl:187 [13] estimate(::XGabaix{Float64}, ::Array{Float64,2}) at C:\Users\Samsung\.julia\packages\DSGE\tJSkz\src\estimate\estimate.jl:105 [14] macro expansion at C:\Users\Samsung\.julia\packages\DSGE\tJSkz\docs\examples\run_default.jl:46 [inlined] [15] top-level scope at .\timing.jl:174 [inlined] [16] top-level scope at C:\Users\Samsung\.julia\packages\DSGE\tJSkz\docs\examples\run_default.jl:0 [17] include(::String) at .\client.jl:457 [18] top-level scope at none:1 in expression starting at C:\Users\Samsung\.julia\packages\DSGE\tJSkz\docs\examples\run_default.jl:43
from dsge.jl.
Thanks again, William. Even though the (1e-2, 1e-5) parametrization didn't work, the SquareRoot did.
You have been very helpful.
from dsge.jl.
Related Issues (20)
- metropolis_hastings() running too slow HOT 6
- metropolis-hastings draws fixed at the mode for some free parameters HOT 4
- Eval can be replaced by getfield in smooth HOT 1
- TagBot trigger issue HOT 3
- Docker file error HOT 1
- Plots error
- Policy Simulation Library Catalog Criteria HOT 6
- ZLB handling method HOT 2
- Is it possible to update Performance Comparison? HOT 2
- The package doesn't work with GR.jl above v.53 HOT 2
- Installation hangs with Julia 1.6.3 HOT 1
- AnSchorfheide HOT 16
- make_packet.jl HOT 1
- run_default.jl HOT 1
- Can't Get Simple Example To Xqt HOT 3
- run_default.jl HOT 1
- mhsave_vint HOT 2
- After 2020 Q3.
- Installation on Julia 1.9.4 HOT 1
- Failed installation on Julia 1.10 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dsge.jl.