Skip to content

Commit

Permalink
WIP fix estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelJuillard committed Nov 20, 2023
1 parent c885e6a commit 88e5a65
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
16 changes: 8 additions & 8 deletions src/estimation/estimated_parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions src/estimation/estimation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 88e5a65

Please sign in to comment.