Skip to content
Snippets Groups Projects
Commit 53907ffb authored by Johannes Pfeifer's avatar Johannes Pfeifer
Browse files

SMC: Add support for generate_trace_plots.m

Closes #1932
parent c320e6e6
Branches
No related tags found
No related merge requests found
Pipeline #10828 passed
...@@ -41,7 +41,11 @@ if ishssmc(options_) ...@@ -41,7 +41,11 @@ if ishssmc(options_)
% Load draws from the posterior distribution % Load draws from the posterior distribution
pfiles = dir(sprintf('%s/hssmc/particles-*.mat', dname)); pfiles = dir(sprintf('%s/hssmc/particles-*.mat', dname));
posterior = load(sprintf('%s/hssmc/particles-%u-%u.mat', dname, length(pfiles), length(pfiles))); posterior = load(sprintf('%s/hssmc/particles-%u-%u.mat', dname, length(pfiles), length(pfiles)));
draws = transpose(posterior.particles(column,:)); if column==0
draws = posterior.tlogpostkernel;
else
draws = transpose(posterior.particles(column,:));
end
elseif isdime(options_) elseif isdime(options_)
posterior = load(sprintf('%s%s%s%schains.mat', dname, filesep(), 'dime', filesep())); posterior = load(sprintf('%s%s%s%schains.mat', dname, filesep(), 'dime', filesep()));
tune = posterior.tune; tune = posterior.tune;
......
...@@ -30,15 +30,21 @@ function generate_trace_plots(chain_number) ...@@ -30,15 +30,21 @@ function generate_trace_plots(chain_number)
global M_ options_ estim_params_ global M_ options_ estim_params_
if issmc(options_) if ~issmc(options_)
error('generate_trace_plots:: SMC methods do not support trace plots') % Get informations about the posterior draws:
end MetropolisFolder = CheckPath('metropolis', M_.dname);
record=load_last_mh_history_file(MetropolisFolder, M_.fname);
% Get informations about the posterior draws: if max(chain_number)>record.Nblck
MetropolisFolder = CheckPath('metropolis', M_.dname); error('generate_trace_plots:: chain number is bigger than existing number of chains')
record=load_last_mh_history_file(MetropolisFolder, M_.fname); end
if max(chain_number)>record.Nblck else
error('generate_trace_plots:: chain number is bigger than existing number of chains') if ishssmc(options_)
if max(chain_number)>1
error('generate_trace_plots:: HSSMC only has one chain')
end
elseif isdime(options_)
error('generate_trace_plots:: DIME does not support generate_trace_plots')
end
end end
trace_plot(options_, M_, estim_params_, 'PosteriorDensity', chain_number) trace_plot(options_, M_, estim_params_, 'PosteriorDensity', chain_number)
......
...@@ -52,22 +52,35 @@ if isempty(column) ...@@ -52,22 +52,35 @@ if isempty(column)
return return
end end
% Get informations about the posterior draws: if ~issmc(options_)
MetropolisFolder = CheckPath('metropolis',M_.dname); % Get informations about the posterior draws:
record=load_last_mh_history_file(MetropolisFolder, M_.fname); MetropolisFolder = CheckPath('metropolis',M_.dname);
record=load_last_mh_history_file(MetropolisFolder, M_.fname);
FirstMhFile = 1;
FirstLine = 1; FirstMhFile = 1;
TotalNumberOfMhFiles = sum(record.MhDraws(:,2)); FirstLine = 1;
TotalNumberOfMhDraws = sum(record.MhDraws(:,1)); TotalNumberOfMhFiles = sum(record.MhDraws(:,2));
[mh_nblck] = size(record.LastParameters,2); TotalNumberOfMhDraws = sum(record.MhDraws(:,1));
clear record; [mh_nblck] = size(record.LastParameters,2);
clear record;
n_nblocks_to_plot=length(blck);
n_nblocks_to_plot=length(blck);
else
if ishssmc(options_)
n_nblocks_to_plot=1;
elseif isdime(options_)
error('trace_plot:: DIME does not support the trace_plot command')
end
end
if n_nblocks_to_plot==1 if n_nblocks_to_plot==1
% Get all the posterior draws: % Get all the posterior draws:
PosteriorDraws = GetAllPosteriorDraws(options_, M_.dname,M_.fname,column, FirstMhFile, FirstLine, TotalNumberOfMhFiles, TotalNumberOfMhDraws, mh_nblck, blck); if ishssmc(options_)
PosteriorDraws = GetAllPosteriorDraws(options_, M_.dname,[],column);
TotalNumberOfMhDraws=length(PosteriorDraws);
else
PosteriorDraws = GetAllPosteriorDraws(options_, M_.dname,M_.fname,column, FirstMhFile, FirstLine, TotalNumberOfMhFiles, TotalNumberOfMhDraws, mh_nblck, blck);
end
else else
PosteriorDraws=NaN(TotalNumberOfMhDraws,n_nblocks_to_plot); PosteriorDraws=NaN(TotalNumberOfMhDraws,n_nblocks_to_plot);
save_string=''; save_string='';
......
...@@ -91,3 +91,5 @@ estimation(order=1, datafile='../fsdat_simul.m', nobs=192, loglinear, ...@@ -91,3 +91,5 @@ estimation(order=1, datafile='../fsdat_simul.m', nobs=192, loglinear,
'target', .25), 'target', .25),
bayesian_irf, smoother, moments_varendo,consider_all_endogenous bayesian_irf, smoother, moments_varendo,consider_all_endogenous
); );
generate_trace_plots(1);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment