From 7e221e5d311a5c2b6853a165b5c7979acb8ea5f2 Mon Sep 17 00:00:00 2001 From: Michel Juillard <michel.juillard@mjui.fr> Date: Sun, 5 Aug 2012 15:27:14 +0200 Subject: [PATCH] factoring setting of bayestop_.penalty = Inf in Metropolis --- matlab/metropolis_hastings_initialization.m | 5 ++--- matlab/random_walk_metropolis_hastings.m | 6 ++++++ matlab/random_walk_metropolis_hastings_core.m | 3 --- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/matlab/metropolis_hastings_initialization.m b/matlab/metropolis_hastings_initialization.m index b248ad2542..5b5f255626 100644 --- a/matlab/metropolis_hastings_initialization.m +++ b/matlab/metropolis_hastings_initialization.m @@ -59,8 +59,6 @@ if ~isempty(M_.bvar) ModelName = [M_.fname '_bvar']; end -bayestopt_.penalty = Inf; - MhDirectoryName = CheckPath('metropolis',M_.dname); nblck = options_.mh_nblck; @@ -113,7 +111,8 @@ if ~options_.load_mh_file && ~options_.mh_recover if all(candidate(:) > mh_bounds(:,1)) && all(candidate(:) < mh_bounds(:,2)) ix2(j,:) = candidate; ilogpo2(j) = - feval(TargetFun,ix2(j,:)',dataset_,options_,M_,estim_params_,bayestopt_,oo_); - if ilogpo2(j) <= - bayestopt_.penalty+1e-6 + if ~isfinite(ilogpo2(j)) % if returned log-density is + % Inf or Nan (penalized value) validate = 0; else fprintf(fidlog,[' Blck ' int2str(j) ':\n']); diff --git a/matlab/random_walk_metropolis_hastings.m b/matlab/random_walk_metropolis_hastings.m index c5e982921c..6e5d782d44 100644 --- a/matlab/random_walk_metropolis_hastings.m +++ b/matlab/random_walk_metropolis_hastings.m @@ -56,6 +56,12 @@ function record=random_walk_metropolis_hastings(TargetFun,ProposalFun,xparam1,vv % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. + +% In Metropolis, we set penalty to Inf to as to reject all parameter sets +% triggering error in target density computation + +bayestopt_.penalty = Inf; + %%%% %%%% Initialization of the random walk metropolis-hastings chains. %%%% diff --git a/matlab/random_walk_metropolis_hastings_core.m b/matlab/random_walk_metropolis_hastings_core.m index 8bb4d44b1b..84f180c97d 100644 --- a/matlab/random_walk_metropolis_hastings_core.m +++ b/matlab/random_walk_metropolis_hastings_core.m @@ -103,9 +103,6 @@ if whoiam bayestopt_.p3,bayestopt_.p4,1); end -% (re)Set the penalty -bayestopt_.penalty = Inf; - MhDirectoryName = CheckPath('metropolis',M_.dname); options_.lik_algo = 1; -- GitLab