From 84aae713a686a25ae920948282816ff95e1aee54 Mon Sep 17 00:00:00 2001 From: Michel Juillard Date: Sat, 6 Feb 2010 14:43:16 +0100 Subject: [PATCH] explicit initialization of persistent variables in priordens.m --- matlab/priordens.m | 21 ++++++++++----------- matlab/set_prior.m | 8 ++++++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/matlab/priordens.m b/matlab/priordens.m index 1b8920220..c1b64fe1e 100644 --- a/matlab/priordens.m +++ b/matlab/priordens.m @@ -1,19 +1,20 @@ -function logged_prior_density = priordens(x, pshape, p6, p7, p3, p4) +function logged_prior_density = priordens(x, pshape, p6, p7, p3, p4,initialization) % Computes a prior density for the structural parameters of DSGE models % % INPUTS -% x [double] vector with n elements. -% pshape [integer] vector with n elements (bayestopt_.pshape). -% p6: [double] vector with n elements, first parameter of the prior distribution (bayestopt_.p6). -% p7: [double] vector with n elements, second parameter of the prior distribution (bayestopt_.p7). -% p3: [double] vector with n elements, lower bounds. -% p4: [double] vector with n elements, upper bound. +% x [double] vector with n elements. +% pshape [integer] vector with n elements (bayestopt_.pshape). +% p6: [double] vector with n elements, first parameter of the prior distribution (bayestopt_.p6). +% p7: [double] vector with n elements, second parameter of the prior distribution (bayestopt_.p7). +% p3: [double] vector with n elements, lower bounds. +% p4: [double] vector with n elements, upper bound. +% initialization [integer] if 1: initialize persistent variables % % OUTPUTS % logged_prior_density [double] scalar, log of the prior density evaluated at x. % -% Copyright (C) 2003-2009 Dynare Team +% Copyright (C) 2003-2010 Dynare Team % % This file is part of Dynare. % @@ -30,12 +31,10 @@ function logged_prior_density = priordens(x, pshape, p6, p7, p3, p4) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . -persistent pflag persistent id1 id2 id3 id4 id5 id6 persistent tt1 tt2 tt3 tt4 tt5 tt6 -if isempty(pflag) - Number0fParameters = length(pshape); +if nargin > 6 && initialization == 1 % Beta indices. tt1 = 1; id1 = find(pshape==1); diff --git a/matlab/set_prior.m b/matlab/set_prior.m index 5f40e3ae3..f64c1e371 100644 --- a/matlab/set_prior.m +++ b/matlab/set_prior.m @@ -18,7 +18,7 @@ function [xparam1, estim_params_, bayestopt_, lb, ub, M_]=set_prior(estim_params % SPECIAL REQUIREMENTS % None -% Copyright (C) 2003-2009 Dynare Team +% Copyright (C) 2003-2010 Dynare Team % % This file is part of Dynare. % @@ -261,4 +261,8 @@ if exist([ M_.dname '/prior/definition.mat']) end else save([M_.dname '/prior/definition.mat'],'bayestopt_'); -end \ No newline at end of file +end + +% initialize persistent variables in priordens() +priordens(xparam1,bayestopt_.pshape,bayestopt_.p6,bayestopt_.p7, ... + bayestopt_.p3,bayestopt_.p4,1);