Skip to content

Commit

Permalink
lower tol for faster obc calc
Browse files Browse the repository at this point in the history
  • Loading branch information
thorek1 committed Jan 5, 2024
1 parent a70d42d commit 9fbd6b7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
22 changes: 12 additions & 10 deletions src/get_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1085,15 +1085,17 @@ function get_irf(𝓂::β„³;
constraints_violated = any(𝓂.obc_violation_function(zeros(num_shocks*periods_per_shock), p) .> eps(Float32))

if constraints_violated
solved = false
# solved = false

for algo ∈ [NLopt.:LD_SLSQP, NLopt.:LN_COBYLA]
# check whether auglag is more reliable here (as in gives smaller shock size)
opt = NLopt.Opt(algo, num_shocks*periods_per_shock)

opt.min_objective = obc_objective_optim_fun

opt.xtol_rel = eps()
opt.xtol_abs = eps(Float32)
opt.ftol_abs = eps(Float32)
opt.maxeval = 500

# Adding constraints
# opt.upper_bounds = fill(eps(), num_shocks*periods_per_shock)
Expand All @@ -1106,13 +1108,13 @@ function get_irf(𝓂::β„³;

(minf,x,ret) = NLopt.optimize(opt, zeros(num_shocks*periods_per_shock))

solved = ret ∈ Symbol.([
NLopt.SUCCESS,
NLopt.STOPVAL_REACHED,
NLopt.FTOL_REACHED,
NLopt.XTOL_REACHED,
NLopt.ROUNDOFF_LIMITED,
])
# solved = ret ∈ Symbol.([
# NLopt.SUCCESS,
# NLopt.STOPVAL_REACHED,
# NLopt.FTOL_REACHED,
# NLopt.XTOL_REACHED,
# NLopt.ROUNDOFF_LIMITED,
# ])

present_shocks[contains.(string.(𝓂.timings.exo),"α΅’α΅‡αΆœ")] .= x

Expand All @@ -1123,7 +1125,7 @@ function get_irf(𝓂::β„³;
end
end

solved = solved && !constraints_violated
solved = !constraints_violated
else
solved = true
end
Expand Down
20 changes: 11 additions & 9 deletions src/plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,9 @@ function plot_irf(𝓂::β„³;
# check whether auglag is more reliable and efficient here
opt.min_objective = obc_objective_optim_fun

opt.xtol_rel = eps()
opt.xtol_abs = eps(Float32)
opt.ftol_abs = eps(Float32)
opt.maxeval = 500

# Adding constraints
# opt.upper_bounds = fill(eps(), num_shocks*periods_per_shock)
Expand All @@ -520,19 +522,19 @@ function plot_irf(𝓂::β„³;

(minf,x,ret) = NLopt.optimize(opt, zeros(num_shocks*periods_per_shock))

solved = ret ∈ Symbol.([
NLopt.SUCCESS,
NLopt.STOPVAL_REACHED,
NLopt.FTOL_REACHED,
NLopt.XTOL_REACHED,
NLopt.ROUNDOFF_LIMITED,
])
# solved = ret ∈ Symbol.([
# NLopt.SUCCESS,
# NLopt.STOPVAL_REACHED,
# NLopt.FTOL_REACHED,
# NLopt.XTOL_REACHED,
# NLopt.ROUNDOFF_LIMITED,
# ])

present_shocks[contains.(string.(𝓂.timings.exo),"α΅’α΅‡αΆœ")] .= x

constraints_violated = any(𝓂.obc_violation_function(x, p) .> eps(Float32))

solved = solved && !constraints_violated
solved = !constraints_violated
else
solved = true
end
Expand Down

0 comments on commit 9fbd6b7

Please sign in to comment.