eval(dir) ==> dir
git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@657 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
58cb6e42b6
commit
3d5b975836
|
@ -3,7 +3,8 @@ function McmcDiagnostic
|
|||
|
||||
global options_ estim_params_ M_
|
||||
|
||||
DirectoryName = CheckPath('Plots/Diagnostics');
|
||||
DirectoryName = CheckPath('Output');
|
||||
MhDirectoryName = CheckPath('metropolis');
|
||||
|
||||
TeX = options_.TeX;
|
||||
nblck = options_.mh_nblck;
|
||||
|
@ -18,7 +19,14 @@ npar = npar + estim_params_.ncn;
|
|||
npar = npar + estim_params_.np ;
|
||||
MAX_nruns = ceil(options_.MaxNumberOfBytes/(npar+2)/8);
|
||||
|
||||
load(['./' M_.dname '/metropolis/' M_.fname '_mh_history.mat'])
|
||||
load([MhDirectoryName '/' M_.fname '_mh_history.mat'])
|
||||
|
||||
mcfiles = [];
|
||||
for blck = 1:nblck
|
||||
mcfiles = cat(3,mcfiles,dir([MhDirectoryName '/' M_.fname '_mh*_blck' int2str(blck) '.mat']));
|
||||
end
|
||||
NumberOfMcFilesPerBlock = size(mcfiles,1);
|
||||
|
||||
|
||||
PastDraws = sum(record.MhDraws,1);
|
||||
LastFileNumber = PastDraws(2);
|
||||
|
@ -33,30 +41,36 @@ xx = Origin:StepSize:NumberOfDraws;
|
|||
NumberOfLines = length(xx);
|
||||
tmp = zeros(NumberOfDraws*nblck,3);
|
||||
UDIAG = zeros(NumberOfLines,6,npar);
|
||||
|
||||
if NumberOfDraws < Origin
|
||||
disp('MCMC Diagnostics :: The number of simulations is to small to compute the MCMC convergence diagnostics.')
|
||||
return
|
||||
end
|
||||
|
||||
if TeX
|
||||
fidTeX = fopen([M_.dname '\TeX\' M_.fname '_UnivariateDiagnostics.TeX'],'w');
|
||||
fidTeX = fopen([DirectoryName '/' M_.fname '_UnivariateDiagnostics.TeX'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by McmcDiagnostics.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
|
||||
fprintf(fidTeX,' \n');
|
||||
end
|
||||
|
||||
|
||||
disp('MCMC Diagnostics: Univariate convergence diagnostic, Brooks and Gelman (1998):')
|
||||
for j=1:npar
|
||||
fprintf(' Parameter %d... ',j);
|
||||
for b = 1:nblck
|
||||
startline = 0;
|
||||
for n = 1:LastFileNumber-1
|
||||
eval(['load ' M_.dname '/metropolis/' M_.fname '_mh' int2str(n) '_blck' int2str(b)]);
|
||||
clear logpo2 post2;
|
||||
for n = 1:NumberOfMcFilesPerBlock-1
|
||||
%eval(['load ' M_.dname '/metropolis/' M_.fname '_mh' int2str(n) '_blck' int2str(b)]);
|
||||
load([MhDirectoryName '/' mcfiles(n,1,b).name],'x2');
|
||||
%clear logpo2 post2;
|
||||
tmp((b-1)*NumberOfDraws+startline+1:(b-1)*NumberOfDraws+MAX_nruns*n,1) = x2(:,j);
|
||||
clear x2;
|
||||
startline = startline + MAX_nruns;
|
||||
end
|
||||
eval(['load ' M_.dname '/metropolis/' M_.fname '_mh' int2str(LastFileNumber) '_blck' int2str(b)]);
|
||||
clear logpo2 post2;
|
||||
load([MhDirectoryName '/' mcfiles(NumberOfMcFilesPerBlock,1,b).name],'x2');
|
||||
% eval(['load ' M_.dname '/metropolis/' M_.fname '_mh' int2str(LastFileNumber) '_blck' int2str(b)]);
|
||||
% clear logpo2 post2;
|
||||
tmp((b-1)*NumberOfDraws+startline+1:(b-1)*NumberOfDraws+MAX_nruns*(LastFileNumber-1)+LastLineNumber,1) = x2(:,j);
|
||||
clear x2;
|
||||
startline = startline + LastLineNumber;
|
||||
|
@ -94,7 +108,11 @@ clear pmet temp moyenne CSUP CINF csup cinf n linea iter tmp;
|
|||
pages = floor(npar/3);
|
||||
k = 0;
|
||||
for i = 1:pages
|
||||
if options_.nograph
|
||||
h = figure('Name','MCMC univariate diagnostic (Brooks and Gelman,1998)','Visible','off');
|
||||
else
|
||||
h = figure('Name','MCMC univariate diagnostic (Brooks and Gelman,1998)');
|
||||
end
|
||||
boxplot = 1;
|
||||
if TeX
|
||||
NAMES = [];
|
||||
|
@ -163,7 +181,11 @@ if reste
|
|||
NAMES = [];
|
||||
TEXNAMES = [];
|
||||
end
|
||||
if options_.nograph
|
||||
h = figure('Name','MCMC univariate diagnostic (Brooks and Gelman, 1998)','Visible','off');
|
||||
else
|
||||
h = figure('Name','MCMC univariate diagnostic (Brooks and Gelman, 1998)');
|
||||
end
|
||||
boxplot = 1;
|
||||
for j = 1:reste
|
||||
k = k+1;
|
||||
|
@ -228,7 +250,7 @@ clear UDIAG;
|
|||
%% Multivariate diagnostic.
|
||||
%%
|
||||
if TeX
|
||||
fidTeX = fopen([M_.dname '/TeX/' M_.fname '_MultivariateDiagnostics.TeX'],'w');
|
||||
fidTeX = fopen([DirectoryName '/' M_.fname '_MultivariateDiagnostics.TeX'],'w');
|
||||
fprintf(fidTeX,'%% TeX eps-loader file generated by McmcDiagnostics.m (Dynare).\n');
|
||||
fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
|
||||
fprintf(fidTeX,' \n');
|
||||
|
@ -238,14 +260,16 @@ tmp = zeros(NumberOfDraws*nblck,3);
|
|||
MDIAG = zeros(NumberOfLines,6);
|
||||
for b = 1:nblck
|
||||
startline = 0;
|
||||
for n = 1:LastFileNumber-1
|
||||
eval(['load ' M_.dname '/metropolis/' M_.fname '_mh' int2str(n) '_blck' int2str(b)]);
|
||||
clear x2 post2;
|
||||
for n = 1:NumberOfMcFilesPerBlock-1
|
||||
% eval(['load ' M_.dname '/metropolis/' M_.fname '_mh' int2str(n) '_blck' int2str(b)]);
|
||||
% clear x2 post2;
|
||||
load([MhDirectoryName '/' mcfiles(n,1,b).name],'logpo2');
|
||||
tmp((b-1)*NumberOfDraws+startline+1:(b-1)*NumberOfDraws+MAX_nruns*n,1) = logpo2;
|
||||
startline = startline+MAX_nruns;
|
||||
end
|
||||
eval(['load ' M_.dname '/metropolis/' M_.fname '_mh' int2str(LastFileNumber) '_blck' int2str(b)]);
|
||||
clear x2 post2;
|
||||
load([MhDirectoryName '/' mcfiles(NumberOfMcFilesPerBlock,1,b).name],'logpo2');
|
||||
% eval(['load ' M_.dname '/metropolis/' M_.fname '_mh' int2str(LastFileNumber) '_blck' int2str(b)]);
|
||||
% clear x2 post2;
|
||||
tmp((b-1)*NumberOfDraws+startline+1:(b-1)*NumberOfDraws+ MAX_nruns*(LastFileNumber-1)+LastLineNumber,1) = logpo2;
|
||||
end
|
||||
clear logpo2;
|
||||
|
@ -275,7 +299,11 @@ for iter = Origin:StepSize:NumberOfDraws
|
|||
end
|
||||
end
|
||||
MDIAG(:,[2 4 6],:) = MDIAG(:,[2 4 6],:)/nblck;
|
||||
if options_.nograph
|
||||
h = figure('Name','Multivatiate diagnostic','Visible','off');
|
||||
else
|
||||
h = figure('Name','Multivatiate diagnostic');
|
||||
end
|
||||
boxplot = 1;
|
||||
for crit = 1:3
|
||||
if crit == 1
|
||||
|
|
|
@ -99,7 +99,7 @@ if options_.load_mh_file == 0
|
|||
record.LastLogLiK = zeros(nblck,1);
|
||||
record.LastFileNumber = AnticipatedNumberOfFiles+1;
|
||||
record.LastLineNumber = AnticipatedNumberOfLinesInTheLastFile;
|
||||
save([DirectoryName '/' M_.fname '_mh_history'],'record');
|
||||
save([MhDirectoryName '/' M_.fname '_mh_history'],'record');
|
||||
elseif options_.load_mh_file == 1% Here we consider previous mh files (previous mh did not crash).
|
||||
disp('MH: I''m loading past metropolis-hastings simulations...')
|
||||
file = dir([ MhDirectoryName '/' M_.fname '_mh_history.mat' ]);
|
||||
|
|
Loading…
Reference in New Issue