modify calling structure of execute_prior_posterior_function and update doc
parent
d3eca9338b
commit
c45a054c6f
|
@ -12808,32 +12808,32 @@ Baseline New Keynesian Model estimated in @cite{Fernández-Villaverde (2010)}. I
|
|||
@chapter Dynare misc commands
|
||||
|
||||
@anchor{prior_posterior_function}
|
||||
@deffn {MATLAB/Octave command} @var{output_cell_name}=prior_posterior_function('@var{function_name_string}','@var{prior_posterior_selector}',@var{OPTIONS})
|
||||
Executes a user-defined function on parameter draws from the prior or posterior distribution. The function
|
||||
provided using the @var{function_name_string} must have the following header
|
||||
@code{output_cell =FILENAME(xparam1,M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info)}.
|
||||
It allows read-only access to all Dynare structures. The only output argument allowed is a 1 by n cell array,
|
||||
which allows for storing any type of output/computations. Dynare returns the results of the
|
||||
computations for all draws in a ndraws by n cell array named @var{output_cell_name}.
|
||||
@deffn Command prior_posterior_function(@var{OPTIONS}) ;
|
||||
|
||||
Executes a user-defined function on parameter draws from the prior or posterior
|
||||
distribution. Dynare returns the results of the computations for all draws in an
|
||||
@math{ndraws} by @math{n} cell array named @var{oo_.posterior_function_results}.
|
||||
|
||||
@optionshead
|
||||
|
||||
@table @code
|
||||
|
||||
@item prior_posterior_selector
|
||||
@item function = @var{FUNCTION_NAME}
|
||||
The function must have the following header @code{output_cell =
|
||||
FILENAME(xparam1,M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info)},
|
||||
providing read-only access to all Dynare structures. The only output argument
|
||||
allowed is a @math{1} by @math{n} cell array, which allows for storing any type of
|
||||
output/computations. This option is required.
|
||||
|
||||
Available options are
|
||||
@table @code
|
||||
@anchor{prior}
|
||||
@item `prior'
|
||||
Executes the user-defined function on draws from the prior. Either this option or the @ref{posterior} option is required.
|
||||
|
||||
@item 'prior'
|
||||
Executes the user-defined function on draws from the prior
|
||||
@anchor{posterior}
|
||||
@item `posterior'
|
||||
Executes the user-defined function on draws from the posterior. Either this option or the @ref{prior} option is required.
|
||||
|
||||
@item 'posterior'
|
||||
Executes the user-defined function on draws from the posterior
|
||||
|
||||
@end table
|
||||
|
||||
@item prior_posterior_sampling_draws
|
||||
@item prior_posterior_sampling_draws = @var{INTEGER}
|
||||
Number of draws used for sampling. Default: 500.
|
||||
|
||||
@end table
|
||||
|
|
|
@ -1,24 +1,23 @@
|
|||
function [results_cell] = execute_prior_posterior_function(posterior_function_name,M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info,type)
|
||||
%[results_cell] = execute_prior_posterior_function(functionhandle,M_,options_,oo_,dataset_,estim_params_,bayestopt_,type)% This function executes a given function on draws of the posterior or prior distribution
|
||||
% Executes user provided function on prior or posterior draws
|
||||
%
|
||||
function oo_=execute_prior_posterior_function(posterior_function_name,M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info,type)
|
||||
%[oo_] = execute_prior_posterior_function(posterior_function_name,M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info,type)
|
||||
% This function executes a given function on draws of the posterior or prior distribution
|
||||
%
|
||||
% INPUTS
|
||||
% functionhandle Handle to the function to be executed
|
||||
% M_ [structure] Matlab's structure describing the Model (initialized by dynare, see @ref{M_}).
|
||||
% options_ [structure] Matlab's structure describing the options (initialized by dynare, see @ref{options_}).
|
||||
% oo_ [structure] Matlab's structure gathering the results (initialized by dynare, see @ref{oo_}).
|
||||
% estim_params_[structure] Matlab's structure describing the estimated_parameters (initialized by dynare, see @ref{estim_params_}).
|
||||
% bayestopt_ [structure] Matlab's structure describing the parameter options (initialized by dynare, see @ref{bayestopt_}).
|
||||
% dataset_ [structure] Matlab's structure storing the dataset
|
||||
% dataset_info [structure] Matlab's structure storing the information about the dataset
|
||||
% M_ [structure] Matlab/Octave structure describing the Model (initialized by dynare, see @ref{M_}).
|
||||
% options_ [structure] Matlab/Octave structure describing the options (initialized by dynare, see @ref{options_}).
|
||||
% oo_ [structure] Matlab/Octave structure gathering the results (initialized by dynare, see @ref{oo_}).
|
||||
% estim_params_[structure] Matlab/Octave structure describing the estimated_parameters (initialized by dynare, see @ref{estim_params_}).
|
||||
% bayestopt_ [structure] Matlab/Octave structure describing the parameter options (initialized by dynare, see @ref{bayestopt_}).
|
||||
% dataset_ [structure] Matlab/Octave structure storing the dataset
|
||||
% dataset_info [structure] Matlab/Octave structure storing the information about the dataset
|
||||
% type [string] 'prior' or 'posterior'
|
||||
%
|
||||
%
|
||||
% OUTPUTS
|
||||
% results_cell [cell] ndrawsx1 cell array storing the results
|
||||
% of the prior/posterior computations
|
||||
% oo_ [structure] Matlab/Octave structure gathering the results (initialized by dynare, see @ref{oo_}).
|
||||
|
||||
% Copyright (C) 2013 Dynare Team
|
||||
% Copyright (C) 2013-2015 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -83,10 +82,10 @@ catch err
|
|||
end
|
||||
|
||||
%initialize cell with number of columns
|
||||
results_cell=cell(n_draws,size(junk,2));
|
||||
oo_.prior_posterior_function_results=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_);
|
||||
[results_cell(draw_iter,:)]=functionhandle(parameter_mat(draw_iter,:),M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info);
|
||||
[oo_.prior_posterior_function_results(draw_iter,:)]=functionhandle(parameter_mat(draw_iter,:),M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info);
|
||||
end
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2004-2010 Dynare Team
|
||||
* Copyright (C) 2004-2015 Dynare Team
|
||||
*
|
||||
* This file is part of Dynare.
|
||||
*
|
||||
|
@ -116,14 +116,14 @@ varobs gp_obs gy_obs;
|
|||
|
||||
estimation(order=1,datafile='../fs2000/fsdat_simul', nobs=192, loglinear, mh_replic=2000, mh_nblocks=2, mh_jscale=0.8);
|
||||
|
||||
posterior_function_results=execute_prior_posterior_function('posterior_function_demo',M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info,'posterior')
|
||||
oo_=execute_prior_posterior_function('posterior_function_demo',M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info,'posterior');
|
||||
|
||||
% read out the contents of the cell and put them into ndraws by ncolumns
|
||||
posterior_params=cell2mat(posterior_function_results(:,1));
|
||||
posterior_steady_states=cell2mat(posterior_function_results(:,2));
|
||||
posterior_params=cell2mat(oo_.prior_posterior_function_results(:,1));
|
||||
posterior_steady_states=cell2mat(oo_.prior_posterior_function_results(:,2));
|
||||
|
||||
prior_function_results=execute_prior_posterior_function('posterior_function_demo',M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info,'prior')
|
||||
oo_=execute_prior_posterior_function('posterior_function_demo',M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info,'prior');
|
||||
|
||||
% read out the contents of the cell and put them into ndraws by ncolumns
|
||||
prior_params=cell2mat(posterior_function_results(:,1));
|
||||
prior_steady_states=cell2mat(posterior_function_results(:,2));
|
||||
prior_params=cell2mat(oo_.prior_posterior_function_results(:,1));
|
||||
prior_steady_states=cell2mat(oo_.prior_posterior_function_results(:,2));
|
||||
|
|
Loading…
Reference in New Issue