From 88e5a6547ce2312126cc91459f45c3c5b3fcfdad Mon Sep 17 00:00:00 2001 From: MichelJuillard Date: Mon, 20 Nov 2023 15:20:38 +0100 Subject: [PATCH] WIP fix estimation --- src/estimation/estimated_parameters.jl | 16 ++++++++-------- src/estimation/estimation.jl | 13 ++++++++++--- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/estimation/estimated_parameters.jl b/src/estimation/estimated_parameters.jl index 991bbce1..855d1e97 100644 --- a/src/estimation/estimated_parameters.jl +++ b/src/estimation/estimated_parameters.jl @@ -53,22 +53,22 @@ end function parse_estimated_parameters!(context::Context, fields::Dict{String,Any}) parameters = context.work.estimated_parameters - symbol_table = context.symboltable + symboltable = context.symboltable for p in fields["params"] if "param" in keys(p) push!(parameters.name, p["param"]) - push!(parameters.index, symbol_table[p["param"]].orderintype) + push!(parameters.index, symboltable[p["param"]].orderintype) push!(parameters.parametertype, EstParameter) elseif "var" in keys(p) push!(parameters.name, p["var"]) - push!(parameters.index, symbol_table[p["var"]].orderintype) - is_endogenous(p["var"]) && push!(parameters.parametertype, EstSDMeasurement) - is_exogenous(p["var"]) && push!(parameters.parametertype, EstSDShock) + push!(parameters.index, symboltable[p["var"]].orderintype) + is_endogenous(p["var"], symboltable) && push!(parameters.parametertype, EstSDMeasurement) + is_exogenous(p["var"], symboltable) && push!(parameters.parametertype, EstSDShock) elseif "var1" in keys(p) push!(parameters.name, (p["var1"] => p["var2"])) - push!(parameters.index, (symbol_table[p["var1"]].orderintype => symbol_table[p["var2"]].orderintype)) - is_endogenous(p["var"]) && push!(parameters.parametertype, EstCorrMeasurement) - is_exogenous(p["var"]) && push!(parameters.parametertype, EstCorrShock) + push!(parameters.index, (symboltable[p["var1"]].orderintype => symbol_table[p["var2"]].orderintype)) + is_endogenous(p["var"], symboltable) && push!(parameters.parametertype, EstCorrMeasurement) + is_exogenous(p["var"], symboltable) && push!(parameters.parametertype, EstCorrShock) else error("Unrecognized parameter name") end diff --git a/src/estimation/estimation.jl b/src/estimation/estimation.jl index 7e548ca8..86f642b7 100644 --- a/src/estimation/estimation.jl +++ b/src/estimation/estimation.jl @@ -32,8 +32,8 @@ Base.@kwdef struct EstimationOptions diffuse_filter::Bool = false display::Bool = false fast_kalman_filter::Bool = true - first_obs::PeriodsSinceEpoch = Undated(1) - last_obs::PeriodsSinceEpoch = Undated(0) + first_obs::PeriodsSinceEpoch = Undated(typemin(Int)) + last_obs::PeriodsSinceEpoch = Undated(typemin(Int)) mcmc_chains::Int = 1 mcmc_init_scale::Float64 = 0 mcmc_jscale::Float64 = 0 @@ -50,7 +50,11 @@ end function translate_estimation_options(options) new_options = copy(options) for (k, v) in options - if k == "mh_jscale" + if k == "first_obs" + new_options["first_obs"] = v[1] + elseif k == "last_obs" + new_options["last_obs"] = v[1] + elseif k == "mh_jscale" new_options["mcmc_jscale"] = v delete!(new_options, "mh_jscale") elseif k == "mh_nblck" @@ -59,6 +63,8 @@ function translate_estimation_options(options) elseif k == "mh_replic" new_options["mcmc_replic"] = v delete!(new_options, "mh_replic") + elseif k == "plot_priors" + v == 0 && (options["plot_priors"] = false) end end return new_options @@ -87,6 +93,7 @@ end function estimation!(context, field::Dict{String, Any}) opt = translate_estimation_options(field["options"]) + @show opt ff = NamedTuple{Tuple(Symbol.(keys(opt)))}(values(opt)) options = EstimationOptions(; ff...) symboltable = context.symboltable