Skip to content

Commit

Permalink
remove debugging instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelJuillard committed Oct 18, 2023
1 parent 785c626 commit 80fc674
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/graphics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,8 @@ function plot_recursive_forecast(; variable, context=context, title=String(varia
x = row_labels(f)
y = Matrix(f[:, Symbol(variable)])
plot!(x, y, label="", linecolor=:black)
@show x
end
@show x[end]
xmax = 10*ceil(x[end]/10)
@show xmax
plot!(xtick = xmin:10:xmax)
graph_display(pl)
end
Expand Down
111 changes: 111 additions & 0 deletions src/initialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -669,3 +669,114 @@ function homotopy_setup!(context, field)
end
end

"""
initialize_from_other_models!(sources::String...; context::Context=context)
set parameter values and initval from the symbols found in the results of one or several models.
The first value found is used and following sources in the list are ignored.
# Keyword arguments
- `context::Context = context`: context in which the values are updated
"""
function initialize_from_other_models!(sources::String...; context::Context=context)
csources = []
for m in sources
c = deserialize(joinpath(m, "output", "$(m).jls"))
push!(csources, c)
end

allocate_initval!(context)
symboltable = context.symboltable
work = context.work

for p in get_parameter(symboltable)
index = symboltable[p].orderintype
work.params[index] = get_value(p, csources)
end
for v in get_endogenous(symboltable)
index = symboltable[v].orderintype
work.initval_endogenous[index] = get_value(v, csources)
end
for v in get_exogenous(symboltable)
index = symboltable[v].orderintype
work.initval_exogenous[index] = get_value(v, csources)
end
for v in get_exogenousdeterministic(symboltable)
index = symboltable[v].orderintype
work.initval_exogenous_determinstic[index] = get_value(v, csources)
end
return nothing
end

function allocate_initval!(context)
model = context.models[1]
work = context.work
work.initval_endogenous = zeros(model.endogenous_nbr,1)
work.initval_exogenous = zeros(model.exogenous_nbr,1)
work.initval_exogenous_deterministic = zeros(model.exogenous_deterministic_nbr, 1)
end

function allocate_endval!(context)
model = context.models[1]
work = context.work
work.endval_endogenous = zeros(model.endogenous_nbr)
work.endval_exogenous = zeros(model.exogenous_nbr)
work.endval_exogenous_deterministic = zeros(model.exogenous_deterministic_nbr)
end

"""
initialize_endval_from_other_models!(sources::String...; context::Context=context)
sets parameter values and endval from the symbols found in results from one or several models.
The first value found is used and following sources in the list are ignored.
# Keyword arguments
- `context::Context = context`: context in which the values are updated
"""
function initialize_endval_from_other_models!(sources::String...; context::Context=context)
allocate_endval!(contex)
symboltable = context.symboltable
work = context.work

for v in get_endogenous(symboltable)
index = symboltable[v].orderintype
work.endval_endogenous[index] = get_value(v, csources)
end
for v in get_exogenous(symboltable)
index = symboltable[v].orderintype
work.endval_exogenous[index] = get_value(v, csources)
end
for v in get_exogenousdeterministic(symboltable)
index = symboltable[v].orderintype
work.endval_exogenous_deterministic[index] = get_value(v, csources)
end
return nothing
end

function get_value(symbol, csources)
for context in csources
try
return get_symbol_value(context, symbol)
catch e
end
end
error("Symbol $symbol not found")
end

function get_symbol_value(context, s)
symboltable = context.symboltable
trends = context.results.model_results[1].trends
type = symboltable[s].symboltype
index = symboltable[s].orderintype
if type == Parameter
return context.work.params[index]
elseif type == Endogenous
return trends.endogenous_steady_state[index]
elseif type == Exogenous
return trends.exogenous_steady_state[index]
elseif type == ExogenousDeterministic
return trends.exogenous_det_steady_state[index]
else
error("Unknown type $type")
end
end

0 comments on commit 80fc674

Please sign in to comment.