From 3b85fea02e96c30416d088f78edfa583ac29c9b1 Mon Sep 17 00:00:00 2001
From: Johannes Pfeifer <jpfeifer@gmx.de>
Date: Fri, 17 Jul 2020 13:18:39 +0200
Subject: [PATCH] Move setting of parameters out of
 check_bounds_and_definiteness_estimation.m

Increases transparency
---
 matlab/check_bounds_and_definiteness_estimation.m          | 7 ++-----
 matlab/dsge_likelihood.m                                   | 3 ++-
 matlab/dsge_var_likelihood.m                               | 4 +++-
 .../method_of_moments_objective_function.m                 | 4 +++-
 matlab/non_linear_dsge_likelihood.m                        | 4 +++-
 5 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/matlab/check_bounds_and_definiteness_estimation.m b/matlab/check_bounds_and_definiteness_estimation.m
index 88b3f84605..8876664dd2 100644
--- a/matlab/check_bounds_and_definiteness_estimation.m
+++ b/matlab/check_bounds_and_definiteness_estimation.m
@@ -1,11 +1,10 @@
-function [fval,info,exit_flag,M_,Q,H]=check_bounds_and_definiteness_estimation(xparam1, M_, options_, estim_params_, bayestopt_)
-% function [fval,info,exit_flag]=check_bounds_and_definiteness_estimation(xparam1, M_, options_, estim_params_, bayestopt_)
+function [fval,info,exit_flag,Q,H]=check_bounds_and_definiteness_estimation(xparam1, M_, estim_params_, bayestopt_)
+% function [fval,info,exit_flag]=check_bounds_and_definiteness_estimation(xparam1, M_, estim_params_, bayestopt_)
 % Checks whether parameter vector satisfies 
 %
 % INPUTS
 % - xparam1                 [double]              n by 1 vector, estimated parameters.
 % - M_                      [struct]              Matlab's structure describing the Model.
-% - options_                [struct]              Matlab's structure describing the options.
 % - estim_params_           [struct]              Matlab's structure describing the estimated_parameters.
 % - bayestopt_              [struct]              Matlab's structure specifying the bounds on the paramater values (initialized by dynare,aka bayesopt_).
 %
@@ -58,8 +57,6 @@ if any(xparam1>bayestopt_.ub)
     return
 end
 
-M_ = set_all_parameters(xparam1,estim_params_,M_);
-
 Q = M_.Sigma_e;
 H = M_.H;
 
diff --git a/matlab/dsge_likelihood.m b/matlab/dsge_likelihood.m
index d43988af66..917ef8bfb3 100644
--- a/matlab/dsge_likelihood.m
+++ b/matlab/dsge_likelihood.m
@@ -180,8 +180,9 @@ end
 %------------------------------------------------------------------------------
 % 1. Get the structural parameters & define penalties
 %------------------------------------------------------------------------------
+Model = set_all_parameters(xparam1,EstimatedParameters,Model);
 
-[fval,info,exit_flag,Model,Q,H]=check_bounds_and_definiteness_estimation(xparam1, Model, DynareOptions, EstimatedParameters, BoundsInfo);
+[fval,info,exit_flag,Q,H]=check_bounds_and_definiteness_estimation(xparam1, Model, EstimatedParameters, BoundsInfo);
 if info(1)
     return
 end
diff --git a/matlab/dsge_var_likelihood.m b/matlab/dsge_var_likelihood.m
index 69e64899c1..596136ce86 100644
--- a/matlab/dsge_var_likelihood.m
+++ b/matlab/dsge_var_likelihood.m
@@ -101,7 +101,9 @@ mYX = evalin('base', 'mYX');
 mXY = evalin('base', 'mXY');
 mXX = evalin('base', 'mXX');
 
-[fval,info,exit_flag,Model,Q]=check_bounds_and_definiteness_estimation(xparam1, Model, DynareOptions, EstimatedParameters, BoundsInfo);
+Model = set_all_parameters(xparam1,EstimatedParameters,Model);
+
+[fval,info,exit_flag,Q]=check_bounds_and_definiteness_estimation(xparam1, Model, EstimatedParameters, BoundsInfo);
 if info(1)
     return
 end
diff --git a/matlab/method_of_moments/method_of_moments_objective_function.m b/matlab/method_of_moments/method_of_moments_objective_function.m
index e4f6714aaf..90e04c92fb 100644
--- a/matlab/method_of_moments/method_of_moments_objective_function.m
+++ b/matlab/method_of_moments/method_of_moments_objective_function.m
@@ -65,7 +65,9 @@ junk2        = [];
 % 1. Get the structural parameters & define penalties
 %--------------------------------------------------------------------------
 
-[fval,info,exit_flag,M_]=check_bounds_and_definiteness_estimation(xparam1, M_, options_mom_, estim_params_, Bounds);
+M_ = set_all_parameters(xparam1, estim_params_, M_);
+
+[fval,info,exit_flag]=check_bounds_and_definiteness_estimation(xparam1, M_, estim_params_, Bounds);
 if info(1)
     if options_mom_.vector_output == 1 % lsqnonlin requires vector output
        fval = ones(size(oo_.mom.data_moments,1),1)*options_mom_.huge_number;
diff --git a/matlab/non_linear_dsge_likelihood.m b/matlab/non_linear_dsge_likelihood.m
index 1c4694af9e..2af54fac8e 100644
--- a/matlab/non_linear_dsge_likelihood.m
+++ b/matlab/non_linear_dsge_likelihood.m
@@ -63,7 +63,9 @@ end
 % 1. Get the structural parameters & define penalties
 %------------------------------------------------------------------------------
 
-[fval,info,exit_flag,Model,Q,H]=check_bounds_and_definiteness_estimation(xparam1, Model, DynareOptions, EstimatedParameters, BoundsInfo);
+Model = set_all_parameters(xparam1,EstimatedParameters,Model);
+
+[fval,info,exit_flag,Q,H]=check_bounds_and_definiteness_estimation(xparam1, Model, EstimatedParameters, BoundsInfo);
 if info(1)
     return
 end
-- 
GitLab