Code Monkey home page Code Monkey logo

Comments (8)

chenwilliam77 avatar chenwilliam77 commented on May 14, 2024 1

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.

chenwilliam77 avatar chenwilliam77 commented on May 14, 2024 1

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.

chenwilliam77 avatar chenwilliam77 commented on May 14, 2024

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.

caioodantas avatar caioodantas commented on May 14, 2024

Thank you very much.
https://github.com/caioodantas/Behavioral-New-Keynesian-Model/blob/main/gabaix.jl

from dsge.jl.

caioodantas avatar caioodantas commented on May 14, 2024

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.

chenwilliam77 avatar chenwilliam77 commented on May 14, 2024

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.

caioodantas avatar caioodantas commented on May 14, 2024

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.

caioodantas avatar caioodantas commented on May 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.