Various cosmetic changes to functions

new-samplers
Johannes Pfeifer 2023-11-30 16:50:30 +01:00 committed by Sébastien Villemot
parent 709ef9230f
commit 6adf1c2639
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
8 changed files with 20 additions and 24 deletions

View File

@ -1,6 +1,5 @@
function oo_ = PlotPosteriorDistributions(estim_params_, M_, options_, bayestopt_, oo_)
% function PlotPosteriorDistributions()
% oo_ = PlotPosteriorDistributions(estim_params_, M_, options_, bayestopt_, oo_)
% plots posterior distributions
%
% INPUTS
@ -36,7 +35,6 @@ latexDirectoryName = CheckPath('latex',M_.dname);
graphDirectoryName = CheckPath('graphs',M_.dname);
TeX = options_.TeX;
nblck = options_.mh_nblck;
nvx = estim_params_.nvx;
nvn = estim_params_.nvn;
ncx = estim_params_.ncx;
@ -66,7 +64,7 @@ for i=1:npar
hh_fig=dyn_figure(options_.nodisplay, 'Name', figurename);
end
[nam,texnam] = get_the_name(i, TeX, M_, estim_params_, options_.varobs);
[x2, f2, abscissa, dens, binf2, bsup2] = draw_prior_density(i, bayestopt_);
[x2, f2, ~, ~, binf2, bsup2] = draw_prior_density(i, bayestopt_);
top2 = max(f2);
if i <= nvx
name = M_.exo_names{estim_params_.var_exo(i,1)};

View File

@ -1,10 +1,9 @@
function check_prior_bounds(xparam1,bounds,M_,estim_params_,options_,bayestopt_)
% function check_prior_bounds(xparam1,bounds,M_,estim_params_,options_)
% function check_prior_bounds(xparam1,bounds,M_,estim_params_,options_,bayestopt_)
% checks the parameter vector of violations of the prior bounds
% Inputs:
% -xparam1 [double] vector of parameters to be estimated (initial values)
% -bounds [vector] vector containing the lower and upper
% bounds
% -bounds [vector] vector containing the lower and upper bounds
% -M_ [structure] characterizing the model.
% -estim_params_ [structure] characterizing parameters to be estimated
% -options_ [structure] characterizing the options

View File

@ -1,5 +1,5 @@
function fjac = fjaco(f,x,varargin)
% fjac = fjaco(f,x,varargin)
% FJACO Computes two-sided finite difference Jacobian
% USAGE
% fjac = fjaco(f,x,P1,P2,...)

View File

@ -1,10 +1,9 @@
function mh_autocorrelation_function(options_,M_,estim_params_,type,blck,name1,name2)
% mh_autocorrelation_function(options_,M_,estim_params_,type,blck,name1,name2)
% This function plots the autocorrelation of the sampled draws in the
% posterior distribution.
%
%
% INPUTS
%
% options_ [structure] Dynare structure.
% M_ [structure] Dynare structure (related to model definition).
% estim_params_ [structure] Dynare structure (related to estimation).
@ -63,7 +62,7 @@ clear record;
PosteriorDraws = GetAllPosteriorDraws(M_.dname, M_.fname, column, FirstMhFile, FirstLine, TotalNumberOfMhFiles, NumberOfDraws, nblck, blck);
% Compute the autocorrelation function:
[autocov,autocor] = sample_autocovariance(PosteriorDraws,options_.mh_autocorrelation_function_size);
[~,autocor] = sample_autocovariance(PosteriorDraws,options_.mh_autocorrelation_function_size);
% Plot the posterior draws:
@ -101,7 +100,7 @@ axis tight
if ~exist(M_.dname, 'dir')
mkdir('.',M_.dname);
end
if ~exist([M_.dname filesep 'graphs'])
if ~exist([M_.dname filesep 'graphs'],'dir')
mkdir(M_.dname,'graphs');
end

View File

@ -1,5 +1,5 @@
function plot_priors(bayestopt_,M_,estim_params_,options_,optional_title)
% function plot_priors
% plot_priors(bayestopt_,M_,estim_params_,options_,optional_title)
% plots prior density
%
% INPUTS
@ -41,7 +41,7 @@ else
figurename = optional_title;
end
npar = length(bayestopt_.p1);
[nbplt,nr,nc,lr,lc,nstar] = pltorg(npar);
[nbplt,nr,nc,~,~,nstar] = pltorg(npar);
if TeX && any(strcmp('eps',cellstr(options_.graph_format)))
fidTeX = fopen([latexDirectoryName filesep M_.fname '_Priors.tex'],'w');
@ -59,7 +59,7 @@ for plt = 1:nbplt
for index=1:nstar0
names = [];
i = (plt-1)*nstar + index;
[x,f,abscissa,dens,binf,bsup] = draw_prior_density(i,bayestopt_);
[x,f] = draw_prior_density(i,bayestopt_);
[nam,texnam] = get_the_name(i,TeX,M_,estim_params_,options_.varobs);
subplot(nr,nc,index)
hh_plt = plot(x,f,'-k','linewidth',2);

View File

@ -52,7 +52,7 @@ options_.prior_trunc = prior_trunc_backup ;
RESIZE = false;
for i=1:size(bayestopt_.name,1)
[Name,tmp] = get_the_name(i,1,M_,estim_params_,options_.varobs);
[Name,~] = get_the_name(i,1,M_,estim_params_,options_.varobs);
if length(Name)>size(T1,2)
resize = true;
else

View File

@ -133,7 +133,7 @@ if ncn
bayestopt_.p4 = [ bayestopt_.p4; estim_params_.corrn(:,10)]; %take generalized distribution into account
bayestopt_.jscale = [ bayestopt_.jscale; estim_params_.corrn(:,11)];
baseid = length(bayestopt_.name);
bayestopt_.name = [bayestopt_.name; cell(ncn, 1)];;
bayestopt_.name = [bayestopt_.name; cell(ncn, 1)];
for i=1:ncn
k1 = estim_params_.corrn(i,1);
k2 = estim_params_.corrn(i,2);
@ -163,8 +163,8 @@ bayestopt_.p7 = bayestopt_.p6 ;
%% check for point priors and disallow them as they do not work with MCMC
if any(bayestopt_.p2 ==0)
error(sprintf(['Error in prior for %s: you cannot use a point prior in estimation. Either increase the prior standard deviation',...
' or fix the parameter completely.'], bayestopt_.name{bayestopt_.p2 ==0}))
error('Error in prior for %s: you cannot use a point prior in estimation. Either increase the prior standard deviation',...
' or fix the parameter completely.', bayestopt_.name{bayestopt_.p2 ==0})
end
% generalized location parameters by default for beta distribution
@ -285,7 +285,7 @@ end
CheckPath('prior',M_.dname);
% I save the prior definition if the prior has changed.
if exist([ M_.dname '/prior/definition.mat'])
if exist([ M_.dname '/prior/definition.mat'],'file')
old = load([M_.dname '/prior/definition.mat'],'bayestopt_');
prior_has_changed = 0;
if length(bayestopt_.p1)==length(old.bayestopt_.p1)

View File

@ -28,7 +28,7 @@ function write_latex_prior_table
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
global M_ options_ bayestopt_ estim_params_
global M_ options_ estim_params_
if ~isbayes(estim_params_)
fprintf('\nwrite_latex_prior_table:: No prior distributions detected. Skipping table creation.\n')
@ -39,13 +39,13 @@ if (size(estim_params_.var_endo,1) || size(estim_params_.corrn,1))
% Prior over measurement errors are defined...
if ((isfield(options_,'varobs') && isempty(options_.varobs)) || ~isfield(options_,'varobs'))
% ... But the list of observed variabled is not yet defined.
fprintf(['\nwrite_latex_prior_table:: varobs should be declared before. Skipping table creation.\n'])
fprintf('\nwrite_latex_prior_table:: varobs should be declared before. Skipping table creation.\n')
return
end
end
% Fill or update bayestopt_ structure
[xparam1, estim_params_, BayesOptions, lb, ub, M_] = set_prior(estim_params_, M_, options_);
[~, estim_params_, BayesOptions, ~, ~, M_] = set_prior(estim_params_, M_, options_);
% Get untruncated bounds
bounds = prior_bounds(BayesOptions, options_.prior_trunc);
@ -112,7 +112,7 @@ fprintf(fidTeX,'\\endlastfoot\n');
% Column 8: the upper bound of the interval containing 90% of the prior mass.
PriorIntervals = prior_bounds(BayesOptions,(1-options_.prior_interval)/2) ;
for i=1:size(BayesOptions.name,1)
[tmp,TexName] = get_the_name(i, 1, M_, estim_params_, options_.varobs);
[~,TexName] = get_the_name(i, 1, M_, estim_params_, options_.varobs);
PriorShape = PriorNames{ BayesOptions.pshape(i) };
PriorMean = BayesOptions.p1(i);
PriorMode = BayesOptions.p5(i);