From 6b3bd9dd0bc2392e52c873891cef9b2451a5443c Mon Sep 17 00:00:00 2001
From: Michel Juillard <michel.juillard@mjui.fr>
Date: Thu, 2 Aug 2012 22:23:29 +0200
Subject: [PATCH] penalty is now passed as a field of bayestopt_ (or BayesInfo)

---
 matlab/DsgeVarLikelihood.m | 14 +++-----------
 matlab/dsge_likelihood.m   | 20 +-------------------
 2 files changed, 4 insertions(+), 30 deletions(-)

diff --git a/matlab/DsgeVarLikelihood.m b/matlab/DsgeVarLikelihood.m
index 840842cef8..c00c4e92cb 100644
--- a/matlab/DsgeVarLikelihood.m
+++ b/matlab/DsgeVarLikelihood.m
@@ -35,7 +35,9 @@ function [fval,grad,hess,exit_flag,info,PHI,SIGMAu,iXX,prior] = DsgeVarLikelihoo
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
 % Declaration of the persistent variables.
-persistent penalty dsge_prior_weight_idx
+persistent dsge_prior_weight_idx
+
+penalty = BayesInfo.penalty;
 
 grad=[];
 hess=[];
@@ -46,16 +48,6 @@ SIGMAu = [];
 iXX = [];
 prior = [];
 
-% Initialization of the penalty
-if ~nargin || isempty(penalty)
-    penalty = 1e8;
-    if ~nargin, return, end
-end
-if nargin==1
-    penalty = xparam1;
-    return
-end
-
 % Initialization of of the index for parameter dsge_prior_weight in Model.params.
 if isempty(dsge_prior_weight_idx)
     dsge_prior_weight_idx = strmatch('dsge_prior_weight',Model.param_names);
diff --git a/matlab/dsge_likelihood.m b/matlab/dsge_likelihood.m
index 3629c9e508..245eb66fdd 100644
--- a/matlab/dsge_likelihood.m
+++ b/matlab/dsge_likelihood.m
@@ -130,22 +130,7 @@ function [fval,DLIK,Hess,exit_flag,ys,trend_coeff,info,Model,DynareOptions,Bayes
 
 % AUTHOR(S) stephane DOT adjemian AT univ DASH lemans DOT FR
 
-% Declaration of the penalty as a persistent variable.
-
-% Persistent variable 'penalty' is used to compute an endogenous penalty to
-% the value 'fval' when various conditions are encountered. These conditions
-% set also 'exit_flag' equal to 0 instead of 1.  It is only when
-% dsge_likelihood() is called by an optimizer called by
-% dynare_estimation_1() that 'exit_flag' is ignored and penalized 'fval' is
-% actually used.
-% In that case, 'penalty' is properly initialized, at the very end of the
-% present function, by a call to dsge_likelihood() made in
-% initial_estimation_checks(). If a condition triggers exit_flag ==
-% 0, initial_estimation_checks() triggers an error.
-% In summary, an initial call to the present function, without triggering
-% any condition, guarantees that 'penalty' is properly initialized when needed.
-
-persistent penalty
+penalty = BayesInfo.penalty;
 
 % Initialization of the returned variables and others...
 fval        = [];
@@ -771,9 +756,6 @@ end
 % Update DynareOptions.kalman_algo.
 DynareOptions.kalman_algo = kalman_algo;
 
-% Update the penalty.
-penalty = fval;
-
 if analytic_derivation==0 && nargout==2,
     lik=lik(start:end,:);
     DLIK=[-lnprior; lik(:)];
-- 
GitLab