prior_posterior_function: save results to different structures, depending on which command was called

time-shift
Houtan Bastani 2015-10-14 11:13:20 +02:00
parent fd5ce1366e
commit f583add550
3 changed files with 17 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -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));