Removed globals from prior_draw routine.

When initializing the persistent variables, bayestopt_ and
options_.prior_trunc need to be passed as input arguments.
time-shift
Stéphane Adjemian (Charybdis) 2015-12-14 15:33:51 +01:00
parent 88858a1fde
commit 29a0765a48
5 changed files with 14 additions and 14 deletions

View File

@ -34,7 +34,7 @@ switch type
case 'posterior'
[xparams, logpost] = metropolis_draw(0);
case 'prior'
xparams = prior_draw(0);
xparams = prior_draw();
if nargout>1
logpost = evaluate_posterior_kernel(xparams');
end

View File

@ -149,9 +149,9 @@ options_ident.analytic_derivation_mode = options_.analytic_derivation_mode;
if prior_exist
if any(bayestopt_.pshape > 0)
if options_ident.prior_range
prior_draw(1,1);
prior_draw(bayestopt_, options_.prior_trunc, true);
else
prior_draw(1);
prior_draw(bayestopt_, options_.prior_trunc, false);
end
else
options_ident.prior_mc=1;

View File

@ -62,7 +62,7 @@ if strcmpi(type,'posterior')
n_draws=options_.sub_draws;
prior = false;
elseif strcmpi(type,'prior')
prior_draw(1);
prior_draw(bayestopt_, options_.prior_trunc);
else
error('EXECUTE_POSTERIOR_FUNCTION: Unknown type!')
end

View File

@ -1,4 +1,4 @@
function pdraw = prior_draw(init,uniform) % --*-- Unitary tests --*--
function pdraw = prior_draw(BayesInfo, prior_trunc, uniform) % --*-- Unitary tests --*--
% This function generate one draw from the joint prior distribution and
% allows sampling uniformly from the prior support (uniform==1 when called with init==1)
@ -47,19 +47,19 @@ persistent p6 p7 p3 p4 lb ub
persistent uniform_index gaussian_index gamma_index beta_index inverse_gamma_1_index inverse_gamma_2_index weibull_index
persistent uniform_draws gaussian_draws gamma_draws beta_draws inverse_gamma_1_draws inverse_gamma_2_draws weibull_draws
if nargin>0 && init
p6 = evalin('base', 'bayestopt_.p6');
p7 = evalin('base', 'bayestopt_.p7');
p3 = evalin('base', 'bayestopt_.p3');
p4 = evalin('base', 'bayestopt_.p4');
bounds = evalin('base', 'prior_bounds(bayestopt_, options_.prior_trunc)');
if nargin>0
p6 = BayesInfo.p6;
p7 = BayesInfo.p7;
p3 = BayesInfo.p3;
p4 = BayesInfo.p4;
bounds = prior_bounds(BayesInfo, prior_trunc);
lb = bounds.lb;
ub = bounds.ub;
number_of_estimated_parameters = length(p6);
if nargin>1 && uniform
if nargin>2 && uniform
prior_shape = repmat(5,number_of_estimated_parameters,1);
else
prior_shape = evalin('base', 'bayestopt_.pshape');
prior_shape = BayesInfo.pshape;
end
beta_index = find(prior_shape==1);
if isempty(beta_index)

View File

@ -31,7 +31,7 @@ function results = prior_sampler(drsave,M_,bayestopt_,options_,oo_,estim_params_
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
% Initialization.
prior_draw(1);
prior_draw(bayestopt_, options_.prior_trunc);
PriorDirectoryName = CheckPath('prior/draws',M_.dname);
work = ~drsave;
iteration = 0;