diff --git a/src/MacroModelling.jl b/src/MacroModelling.jl index 6f548f1e..efac1eb3 100644 --- a/src/MacroModelling.jl +++ b/src/MacroModelling.jl @@ -3036,6 +3036,28 @@ function block_solver(parameters_and_solved_vars::Vector{Float64}, ) # alternatively use .001)#, μ = μ, p = p)# catch e end sol_minimum = isnan(sum(abs2,info[4])) ? Inf : sum(abs2,info[4]) + + if sol_minimum > tol + function ss_solve_blocks_incl_params(guesses) + guess = guesses[1:length(guess)] + parameters_and_solved_vars_guess = guesses[length(guess)+1:end] + res = ss_solve_blocks(parameters_and_solved_vars, guess) + return vcat(res, parameters_and_solved_vars .- parameters_and_solved_vars_guess) + end + + sol_new, info = SS_optimizer( + ss_solve_blocks_incl_params, + vcat(previous_sol_init,parameters_and_solved_vars), + vcat(lbs,fill(-1e12,length(parameters_and_solved_vars))), + vcat(ubs,fill(1e12,length(parameters_and_solved_vars))), + parameters = parameters + ) # alternatively use .001)#, μ = μ, p = p)# catch e end + + sol_new = sol_new[1:length(guess)] + + sol_minimum = isnan(sum(abs2,info[4])) ? Inf : sum(abs2,info[4]) + end + sol_values = max.(lbs,min.(ubs, sol_new )) iters = info[1] @@ -3059,6 +3081,21 @@ function block_solver(parameters_and_solved_vars::Vector{Float64}, )# catch e end sol_minimum = isnan(sum(abs2,info[4])) ? Inf : sum(abs2,info[4]) + + if sol_minimum > tol + sol_new, info = SS_optimizer( + ss_solve_blocks_incl_params, + vcat(standard_inits,parameters_and_solved_vars), + vcat(lbs,fill(-1e12,length(parameters_and_solved_vars))), + vcat(ubs,fill(1e12,length(parameters_and_solved_vars))), + parameters = parameters + ) # alternatively use .001)#, μ = μ, p = p)# catch e end + + sol_new = sol_new[1:length(guess)] + + sol_minimum = isnan(sum(abs2,info[4])) ? Inf : sum(abs2,info[4]) + end + sol_values = max.(lbs,min.(ubs, sol_new)) iters = info[1]