From f583add550016aa045655a152cb7b38bb85a3f4b Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 14 Oct 2015 11:13:20 +0200 Subject: [PATCH] prior_posterior_function: save results to different structures, depending on which command was called --- doc/dynare.texi | 5 +++-- matlab/execute_prior_posterior_function.m | 12 ++++++++++-- .../fs2000_prior_posterior_function.mod | 8 ++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 4e64d1c24..16166a5ae 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -12826,7 +12826,7 @@ Baseline New Keynesian Model estimated in @cite{Fernández-Villaverde (2010)}. I Executes a user-defined function on parameter draws from the prior distribution. Dynare returns the results of the computations for all draws in an -@math{ndraws} by @math{n} cell array named @var{oo_.prior_posterior_function_results}. +@math{ndraws} by @math{n} cell array named @var{oo_.prior_function_results}. @optionshead @@ -12850,7 +12850,8 @@ Number of draws used for sampling. Default: 500. @deffn Command posterior_function(@var{OPTIONS}) ; -Same as the @ref{prior_function} command but for the posterior distribution. +Same as the @ref{prior_function} command but for the posterior +distribution. Results returned in @var{oo_.posterior_function_results} @optionshead diff --git a/matlab/execute_prior_posterior_function.m b/matlab/execute_prior_posterior_function.m index c1a4cd921..378d2237f 100644 --- a/matlab/execute_prior_posterior_function.m +++ b/matlab/execute_prior_posterior_function.m @@ -47,6 +47,7 @@ end %Create function handle functionhandle=str2func(posterior_function_name); +prior = true; n_draws=options_.sampling_draws; % Get informations about the _posterior_draws files. if strcmpi(type,'posterior') @@ -59,6 +60,7 @@ if strcmpi(type,'posterior') error('EXECUTE_POSTERIOR_FUNCTION: The draws could not be initialized') end n_draws=options_.sub_draws; + prior = false; elseif strcmpi(type,'prior') prior_draw(1); else @@ -82,10 +84,16 @@ catch err end %initialize cell with number of columns -oo_.prior_posterior_function_results=cell(n_draws,size(junk,2)); +results_cell=cell(n_draws,size(junk,2)); %% compute function on draws for draw_iter = 1:n_draws M_ = set_all_parameters(parameter_mat(draw_iter,:),estim_params_,M_); - [oo_.prior_posterior_function_results(draw_iter,:)]=functionhandle(parameter_mat(draw_iter,:),M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info); + [results_cell(draw_iter,:)]=functionhandle(parameter_mat(draw_iter,:),M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info); +end + +if prior + oo_.prior_function_results = results_cell; +else + oo_.posterior_function_results = results_cell; end diff --git a/tests/prior_posterior_function/fs2000_prior_posterior_function.mod b/tests/prior_posterior_function/fs2000_prior_posterior_function.mod index a6d3998e0..e10481dfd 100644 --- a/tests/prior_posterior_function/fs2000_prior_posterior_function.mod +++ b/tests/prior_posterior_function/fs2000_prior_posterior_function.mod @@ -119,11 +119,11 @@ estimation(order=1,datafile='../fs2000/fsdat_simul', nobs=192, loglinear, mh_rep posterior_function(function='posterior_function_demo', sampling_draws=500); % read out the contents of the cell and put them into ndraws by ncolumns -posterior_params=cell2mat(oo_.prior_posterior_function_results(:,1)); -posterior_steady_states=cell2mat(oo_.prior_posterior_function_results(:,2)); +posterior_params=cell2mat(oo_.posterior_function_results(:,1)); +posterior_steady_states=cell2mat(oo_.posterior_function_results(:,2)); prior_function(function='posterior_function_demo'); % read out the contents of the cell and put them into ndraws by ncolumns -prior_params=cell2mat(oo_.prior_posterior_function_results(:,1)); -prior_steady_states=cell2mat(oo_.prior_posterior_function_results(:,2)); +prior_params=cell2mat(oo_.prior_function_results(:,1)); +prior_steady_states=cell2mat(oo_.prior_function_results(:,2));