From 4480f5b4943d9e2bf5678d065a8e508456022ad4 Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Wed, 30 May 2012 11:22:59 +0200 Subject: [PATCH 1/3] Fixes around latex output: use of longtable for parameter estimates and various fixes for posterior analysis, also for parallel execution. --- matlab/GetPosteriorParametersStatistics.m | 40 +++-- matlab/McMCDiagnostics.m | 6 +- matlab/PlotPosteriorDistributions.m | 2 +- matlab/dynare_estimation_1.m | 180 ++++++++-------------- matlab/pm3.m | 94 ++++++----- matlab/prior_posterior_statistics.m | 21 +-- 6 files changed, 168 insertions(+), 175 deletions(-) diff --git a/matlab/GetPosteriorParametersStatistics.m b/matlab/GetPosteriorParametersStatistics.m index 3df62968b..eeddf67c1 100644 --- a/matlab/GetPosteriorParametersStatistics.m +++ b/matlab/GetPosteriorParametersStatistics.m @@ -57,7 +57,7 @@ FirstMhFile = record.KeepedDraws.FirstMhFile; NumberOfDraws = TotalNumberOfMhDraws-floor(options_.mh_drop*TotalNumberOfMhDraws); clear record; -pnames=[' ';'beta ';'gamm ';'norm ';'invg ';'unif ';'invg2']; +pnames=[' ';'beta ';'gamma';'norm ';'invg ';'unif ';'invg2']; header_width = row_header_width(M_,estim_params_,bayestopt_); tit2 = sprintf('%-*s %10s %10s %16s %6s %10s\n',header_width+2,' ','prior mean','post. mean','conf. interval','prior','pstdev'); pformat = '%-*s %10.3f %10.4f %10.4f %8.4f %6s %10.4f'; @@ -103,6 +103,8 @@ if np pnames(bayestopt_.pshape(ip)+1,:), ... bayestopt_.p2(ip))); if TeX + k = estim_params_.param_vals(i,1); + name = deblank(M_.param_names_tex(k,:)); TeXCore(fid,name,deblank(pnames(bayestopt_.pshape(ip)+1,:)),bayestopt_.p1(ip),... bayestopt_.p2(ip),post_mean,sqrt(post_var),hpd_interval); end @@ -147,7 +149,8 @@ if nvx end disp(sprintf(pformat,header_width,name,bayestopt_.p1(ip),post_mean,hpd_interval,... pnames(bayestopt_.pshape(ip)+1,:),bayestopt_.p2(ip))); - if TeX + if TeX, + name = deblank(M_.exo_names_tex(k,:)); TeXCore(fid,name,deblank(pnames(bayestopt_.pshape(ip)+1,:)),bayestopt_.p1(ip),... bayestopt_.p2(ip),post_mean,sqrt(post_var),hpd_interval); end @@ -188,6 +191,8 @@ if nvn disp(sprintf(pformat,header_width,name,bayestopt_.p1(ip),post_mean,hpd_interval, ... pnames(bayestopt_.pshape(ip)+1,:),bayestopt_.p2(ip))); if TeX + k = estim_params_.var_endo(i,1); + name = deblank(M_.endo_names_tex(k,:)); TeXCore(fid,name,deblank(pnames(bayestopt_.pshape(ip)+1,:)),bayestopt_.p1(ip),... bayestopt_.p2(ip),post_mean,sqrt(post_var),hpd_interval); end @@ -241,6 +246,7 @@ if ncx disp(sprintf(pformat, header_width,name,bayestopt_.p1(ip),post_mean,hpd_interval, ... pnames(bayestopt_.pshape(ip)+1,:),bayestopt_.p2(ip))); if TeX + name = ['(',deblank(M_.exo_names_tex(k1,:)) ',' deblank(M_.exo_names_tex(k2,:)),')']; TeXCore(fid,name,deblank(pnames(bayestopt_.pshape(ip)+1,:)),bayestopt_.p1(ip),... bayestopt_.p2(ip),post_mean,sqrt(post_var),hpd_interval); end @@ -291,7 +297,8 @@ if ncn end disp(sprintf(pformat, header_width,name,bayestopt_.p1(ip),post_mean,hpd_interval, ... pnames(bayestopt_.pshape(ip)+1,:),bayestopt_.p2(ip))); - if TeX + if TeX, + name = ['(',deblank(M_.endo_names_tex(k1,:)) ',' deblank(M_.endo_names_tex(k2,:)),')']; TeXCore(fid,name,deblank(pnames(bayestopt_.pshape(ip)+1,:)),bayestopt_.p1(ip),... bayestopt_.p2(ip),post_mean,sqrt(post_var),hpd_interval); end @@ -314,13 +321,25 @@ fprintf(fidTeX,['%% RESULTS FROM METROPOLIS HASTINGS (' title ')\n']); fprintf(fidTeX,['%% ' datestr(now,0)]); fprintf(fidTeX,' \n'); fprintf(fidTeX,' \n'); -fprintf(fidTeX,'\\begin{table}\n'); -fprintf(fidTeX,'\\centering\n'); -fprintf(fidTeX,'\\begin{tabular}{l|lcccccc} \n'); +fprintf(fidTeX,'\\begin{center}\n'); +fprintf(fidTeX,'\\begin{longtable}{l|lcccccc} \n'); +fprintf(fidTeX,['\\caption{Results from Metropolis-Hastings (' title ')}\n ']); +fprintf(fidTeX,['\\label{Table:MHPosterior:' int2str(fnum) '}\\\\\n']); fprintf(fidTeX,'\\hline\\hline \\\\ \n'); fprintf(fidTeX,[' & Prior distribution & Prior mean & Prior ' ... 's.d. & Posterior mean & Posterior s.d. & HPD inf & HPD sup\\\\ \n']); -fprintf(fidTeX,'\\hline \\\\ \n'); +fprintf(fidTeX,'\\hline \\endfirsthead \n'); +fprintf(fidTeX,['\\caption{(continued)}']); +fprintf(fidTeX,['\\label{Table:MHPosterior:' int2str(fnum) '}\\\\\n']); +fprintf(fidTeX,'\\hline\\hline \\\\ \n'); +fprintf(fidTeX,[' & Prior distribution & Prior mean & Prior ' ... + 's.d. & Posterior mean & Posterior s.d. & HPD inf & HPD sup\\\\ \n']); +fprintf(fidTeX,'\\hline \\endhead \n'); + +fprintf(fidTeX,'\\hline \\multicolumn{8}{r}{(Continued on next page)} \\\\ \\hline \\endfoot \n'); +fprintf(fidTeX,'\\hline \\hline \\endlastfoot \n'); + + fid = fidTeX; @@ -337,11 +356,8 @@ fprintf(fid,['$%s$ & %s & %7.3f & %6.4f & %7.3f& %6.4f & %7.4f & %7.4f \\\\ \n'] function TeXEnd(fid,fnum,title) -fprintf(fid,'\\hline\\hline \n'); -fprintf(fid,'\\end{tabular}\n '); -fprintf(fid,['\\caption{Results from Metropolis-Hastings (' title ')}\n ']); -fprintf(fid,['\\label{Table:MHPosterior:' int2str(fnum) '}\n']); -fprintf(fid,'\\end{table}\n'); +fprintf(fid,'\\end{longtable}\n '); +fprintf(fid,'\\end{center}\n'); fprintf(fid,'%% End of TeX file.\n'); fclose(fid); diff --git a/matlab/McMCDiagnostics.m b/matlab/McMCDiagnostics.m index 9e3582b43..8ac86e44d 100644 --- a/matlab/McMCDiagnostics.m +++ b/matlab/McMCDiagnostics.m @@ -175,7 +175,7 @@ for i = 1:pages fprintf(fidTeX,'\\psfrag{%s}[1][][0.5][0]{%s}\n',deblank(NAMES(jj,:)),deblank(TEXNAMES(jj,:))); end fprintf(fidTeX,'\\centering \n'); - fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_udiag%s}\n',M_.fname,int2str(i)); + fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_udiag%s}\n',[DirectoryName '/' M_.fname],int2str(i)); fprintf(fidTeX,'\\caption{Univariate convergence diagnostics for the Metropolis-Hastings.\n'); fprintf(fidTeX,'The first, second and third columns are respectively the criteria based on\n'); fprintf(fidTeX,'the eighty percent interval, the second and third moments.}'); @@ -238,7 +238,7 @@ if reste fprintf(fidTeX,'\\psfrag{%s}[1][][0.5][0]{%s}\n',deblank(NAMES(jj,:)),deblank(TEXNAMES(jj,:))); end fprintf(fidTeX,'\\centering \n'); - fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_udiag%s}\n',M_.fname,int2str(pages+1)); + fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_udiag%s}\n',[DirectoryName '/' M_.fname],int2str(pages+1)); if reste == 2 fprintf(fidTeX,'\\caption{Univariate convergence diagnostics for the Metropolis-Hastings.\n'); fprintf(fidTeX,'The first, second and third columns are respectively the criteria based on\n'); @@ -348,7 +348,7 @@ if TeX fprintf(fidTeX,'\\psfrag{%s}[1][][0.5][0]{%s}\n',deblank(NAMES(jj,:)),' '); end fprintf(fidTeX,'\\centering \n'); - fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_mdiag}\n',M_.fname); + fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_mdiag}\n',[DirectoryName '/' M_.fname]); fprintf(fidTeX,'\\caption{Multivariate convergence diagnostics for the Metropolis-Hastings.\n'); fprintf(fidTeX,'The first, second and third rows are respectively the criteria based on\n'); fprintf(fidTeX,'the eighty percent interval, the second and third moments. The different \n'); diff --git a/matlab/PlotPosteriorDistributions.m b/matlab/PlotPosteriorDistributions.m index 12dad4b00..dbbe3d3b6 100644 --- a/matlab/PlotPosteriorDistributions.m +++ b/matlab/PlotPosteriorDistributions.m @@ -159,7 +159,7 @@ for i=1:npar fprintf(fidTeX,'\\psfrag{%s}[1][][0.5][0]{%s}\n',deblank(NAMES(j,:)),deblank(TeXNAMES(j,:))); end fprintf(fidTeX,'\\centering\n'); - fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_PriorsAndPosteriors%s}\n',M_.fname,int2str(figunumber)); + fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s/%s_PriorsAndPosteriors%s}\n',OutputDirectoryName,M_.fname,int2str(figunumber)); fprintf(fidTeX,'\\caption{Priors and posteriors.}'); fprintf(fidTeX,'\\label{Fig:PriorsAndPosteriors:%s}\n',int2str(figunumber)); fprintf(fidTeX,'\\end{figure}\n'); diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index 172022550..e4e899392 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -630,15 +630,20 @@ if any(bayestopt_.pshape > 0) && options_.TeX %% Bayesian estimation (posterior fprintf(fidTeX,['%% ' datestr(now,0)]); fprintf(fidTeX,' \n'); fprintf(fidTeX,' \n'); - fprintf(fidTeX,'{\\tiny \n'); - fprintf(fidTeX,'\\begin{table}\n'); - fprintf(fidTeX,'\\centering\n'); + fprintf(fidTeX,'\\begin{center}\n'); + fprintf(fidTeX,'\\begin{longtable}{l|lcccc} \n'); fprintf(fidTeX,'\\caption{Results from posterior maximization (parameters)}\n '); - fprintf(fidTeX,'\\label{Table:Posterior:1}\n'); - fprintf(fidTeX,'\\begin{tabular}{l|lcccc} \n'); + fprintf(fidTeX,'\\label{Table:Posterior:1}\\\\\n'); fprintf(fidTeX,'\\hline\\hline \\\\ \n'); fprintf(fidTeX,' & Prior distribution & Prior mean & Prior s.d. & Posterior mode & s.d. \\\\ \n'); - fprintf(fidTeX,'\\hline \\\\ \n'); + fprintf(fidTeX,'\\hline \\endfirsthead \n'); + fprintf(fidTeX,'\\caption{(continued)}\n '); + fprintf(fidTeX,'\\label{Table:Posterior:1}\\\\\n'); + fprintf(fidTeX,'\\hline\\hline \\\\ \n'); + fprintf(fidTeX,' & Prior distribution & Prior mean & Prior s.d. & Posterior mode & s.d. \\\\ \n'); + fprintf(fidTeX,'\\hline \\endhead \n'); + fprintf(fidTeX,'\\hline \\multicolumn{6}{r}{(Continued on next page)} \\\\ \\hline \\endfoot \n'); + fprintf(fidTeX,'\\hline \\hline \\endlastfoot \n'); ip = nvx+nvn+ncx+ncn+1; for i=1:np fprintf(fidTeX,'$%s$ & %s & %7.3f & %6.4f & %8.4f & %7.4f \\\\ \n',... @@ -649,24 +654,9 @@ if any(bayestopt_.pshape > 0) && options_.TeX %% Bayesian estimation (posterior xparam1(ip),... stdh(ip)); ip = ip + 1; - if ~mod(i,50) && i 0) && options_.TeX %% Bayesian estimation (posterior fprintf(fidTeX,['%% ' datestr(now,0)]); fprintf(fidTeX,' \n'); fprintf(fidTeX,' \n'); - fprintf(fidTeX,'{\\tiny \n'); - fprintf(fidTeX,'\\begin{table}\n'); - fprintf(fidTeX,'\\centering\n'); + fprintf(fidTeX,'\\begin{center}\n'); + fprintf(fidTeX,'\\begin{longtable}{l|lcccc} \n'); fprintf(fidTeX,'\\caption{Results from posterior maximization (standard deviation of structural shocks)}\n '); - fprintf(fidTeX,'\\label{Table:Posterior:2}\n'); - fprintf(fidTeX,'\\begin{tabular}{l|lcccc} \n'); + fprintf(fidTeX,'\\label{Table:Posterior:2}\\\\\n'); fprintf(fidTeX,'\\hline\\hline \\\\ \n'); fprintf(fidTeX,' & Prior distribution & Prior mean & Prior s.d. & Posterior mode & s.d. \\\\ \n'); - fprintf(fidTeX,'\\hline \\\\ \n'); + fprintf(fidTeX,'\\hline \\endfirsthead \n'); + fprintf(fidTeX,'\\caption{(continued)}\n '); + fprintf(fidTeX,'\\label{Table:Posterior:2}\\\\\n'); + fprintf(fidTeX,'\\hline\\hline \\\\ \n'); + fprintf(fidTeX,' & Prior distribution & Prior mean & Prior s.d. & Posterior mode & s.d. \\\\ \n'); + fprintf(fidTeX,'\\hline \\endhead \n'); + fprintf(fidTeX,'\\hline \\multicolumn{6}{r}{(Continued on next page)} \\\\ \\hline \\endfoot \n'); + fprintf(fidTeX,'\\hline \\hline \\endlastfoot \n'); ip = 1; for i=1:nvx k = estim_params_.var_exo(i,1); @@ -698,24 +693,9 @@ if any(bayestopt_.pshape > 0) && options_.TeX %% Bayesian estimation (posterior xparam1(ip), ... stdh(ip)); ip = ip+1; - if ~mod(i,50) && i 0) && options_.TeX %% Bayesian estimation (posterior fprintf(fidTeX,['%% ' datestr(now,0)]); fprintf(fidTeX,' \n'); fprintf(fidTeX,' \n'); - fprintf(fidTeX,'\\begin{table}\n'); - fprintf(fidTeX,'\\centering\n'); + fprintf(fidTeX,'\\begin{center}\n'); + fprintf(fidTeX,'\\begin{longtable}{l|lcccc} \n'); fprintf(fidTeX,'\\caption{Results from posterior maximization (standard deviation of measurement errors)}\n '); - fprintf(fidTeX,'\\label{Table:Posterior:3}\n'); - fprintf(fidTeX,'\\begin{tabular}{l|lcccc} \n'); + fprintf(fidTeX,'\\label{Table:Posterior:3}\\\\\n'); fprintf(fidTeX,'\\hline\\hline \\\\ \n'); - fprintf(fidTeX,' & Prior distribution & Prior mean & Prior s.d. & Posterior mode & s.d. \\\\ \n') - fprintf(fidTeX,'\\hline \\\\ \n'); + fprintf(fidTeX,' & Prior distribution & Prior mean & Prior s.d. & Posterior mode & s.d. \\\\ \n'); + fprintf(fidTeX,'\\hline \\endfirsthead \n'); + fprintf(fidTeX,'\\caption{(continued)}\n '); + fprintf(fidTeX,'\\label{Table:Posterior:3}\\\\\n'); + fprintf(fidTeX,'\\hline\\hline \\\\ \n'); + fprintf(fidTeX,' & Prior distribution & Prior mean & Prior s.d. & Posterior mode & s.d. \\\\ \n'); + fprintf(fidTeX,'\\hline \\endhead \n'); + fprintf(fidTeX,'\\hline \\multicolumn{6}{r}{(Continued on next page)} \\\\ \\hline \\endfoot \n'); + fprintf(fidTeX,'\\hline \\hline \\endlastfoot \n'); ip = nvx+1; for i=1:nvn idx = strmatch(options_.varobs(estim_params_.var_endo(i,1),:),M_.endo_names); @@ -746,23 +732,9 @@ if any(bayestopt_.pshape > 0) && options_.TeX %% Bayesian estimation (posterior xparam1(ip),... stdh(ip)); ip = ip+1; - if ~mod(i,50) && i 0) && options_.TeX %% Bayesian estimation (posterior fprintf(fidTeX,['%% ' datestr(now,0)]); fprintf(fidTeX,' \n'); fprintf(fidTeX,' \n'); - fprintf(fidTeX,'\\begin{table}\n'); - fprintf(fidTeX,'\\centering\n'); + fprintf(fidTeX,'\\begin{center}\n'); + fprintf(fidTeX,'\\begin{longtable}{l|lcccc} \n'); fprintf(fidTeX,'\\caption{Results from posterior parameters (correlation of structural shocks)}\n '); - fprintf(fidTeX,'\\label{Table:Posterior:4}\n'); - fprintf(fidTeX,'\\begin{tabular}{l|lcccc} \n'); + fprintf(fidTeX,'\\label{Table:Posterior:4}\\\\\n'); fprintf(fidTeX,'\\hline\\hline \\\\ \n'); - fprintf(fidTeX,' & Prior distribution & Prior mean & Prior s.d. & Posterior mode & s.d. \\\\ \n') - fprintf(fidTeX,'\\hline \\\\ \n'); + fprintf(fidTeX,' & Prior distribution & Prior mean & Prior s.d. & Posterior mode & s.d. \\\\ \n'); + fprintf(fidTeX,'\\hline \\endfirsthead \n'); + fprintf(fidTeX,'\\caption{(continued)}\n '); + fprintf(fidTeX,'\\label{Table:Posterior:4}\\\\\n'); + fprintf(fidTeX,'\\hline\\hline \\\\ \n'); + fprintf(fidTeX,' & Prior distribution & Prior mean & Prior s.d. & Posterior mode & s.d. \\\\ \n'); + fprintf(fidTeX,'\\hline \\endhead \n'); + fprintf(fidTeX,'\\hline \\multicolumn{6}{r}{(Continued on next page)} \\\\ \\hline \\endfoot \n'); + fprintf(fidTeX,'\\hline \\hline \\endlastfoot \n'); ip = nvx+nvn+1; for i=1:ncx k1 = estim_params_.corrx(i,1); @@ -794,23 +772,9 @@ if any(bayestopt_.pshape > 0) && options_.TeX %% Bayesian estimation (posterior xparam1(ip), ... stdh(ip)); ip = ip+1; - if ~mod(i,50) && i 0) && options_.TeX %% Bayesian estimation (posterior fprintf(fidTeX,['%% ' datestr(now,0)]); fprintf(fidTeX,' \n'); fprintf(fidTeX,' \n'); - fprintf(fidTeX,'\\begin{table}\n'); - fprintf(fidTeX,'\\centering\n'); + fprintf(fidTeX,'\\begin{center}\n'); + fprintf(fidTeX,'\\begin{longtabe}{l|lcccc} \n'); fprintf(fidTeX,'\\caption{Results from posterior parameters (correlation of measurement errors)}\n '); - fprintf(fidTeX,'\\label{Table:Posterior:5}\n'); - fprintf(fidTeX,'\\begin{tabular}{l|lcccc} \n'); + fprintf(fidTeX,'\\label{Table:Posterior:5}\\\\\n'); fprintf(fidTeX,'\\hline\\hline \\\\ \n'); - fprintf(fidTeX,' & Prior distribution & Prior mean & Prior s.d. & Posterior mode & s.d. \\\\ \n') - fprintf(fidTeX,'\\hline \\\\ \n'); + fprintf(fidTeX,' & Prior distribution & Prior mean & Prior s.d. & Posterior mode & s.d. \\\\ \n'); + fprintf(fidTeX,'\\hline \\endfirsthead \n'); + fprintf(fidTeX,'\\caption{(continued)}\n '); + fprintf(fidTeX,'\\label{Table:Posterior:5}\\\\\n'); + fprintf(fidTeX,'\\hline\\hline \\\\ \n'); + fprintf(fidTeX,' & Prior distribution & Prior mean & Prior s.d. & Posterior mode & s.d. \\\\ \n'); + fprintf(fidTeX,'\\hline \\endhead \n'); + fprintf(fidTeX,'\\hline \\multicolumn{6}{r}{(Continued on next page)} \\\\ \\hline \\endfoot \n'); + fprintf(fidTeX,'\\hline \\hline \\endlastfoot \n'); ip = nvx+nvn+ncx+1; for i=1:ncn k1 = estim_params_.corrn(i,1); @@ -842,23 +812,9 @@ if any(bayestopt_.pshape > 0) && options_.TeX %% Bayesian estimation (posterior xparam1(ip), ... stdh(ip)); ip = ip+1; - if ~mod(i,50) && i 10^(-6) - subplotnum = subplotnum+1; - name = deblank(varlist(i,:)); - NAMES = name; - texname = deblank(varlist_TeX(i,:)); - TEXNAMES = ['$' texname '$']; - end - if subplotnum == MaxNumberOfPlotsPerFigure || i == nvar - fprintf(fidTeX,'\\begin{figure}[H]\n'); - for jj = 1:size(TEXNAMES,1) - fprintf(fidTeX,['\\psfrag{%s}[1][][0.5][0]{%s}\n'],deblank(NAMES(jj,:)),deblank(TEXNAMES(jj,:))); - end - fprintf(fidTeX,'\\centering \n'); - fprintf(fidTeX,['\\includegraphics[scale=0.5]{%s_' name3 '_%s}\n'],M_.fname,deblank(tit3(i,:))); - fprintf(fidTeX,'\\label{Fig:%s:%s}\n',name3,deblank(tit3(i,:))); - fprintf(fidTeX,'\\end{figure}\n'); - fprintf(fidTeX,' \n'); - subplotnum = 0; - end - end - fprintf(fidTeX,'%% End of TeX file.\n'); - fclose(fidTeX); -end % Store the variable mandatory for local/remote parallel computing. @@ -146,7 +116,7 @@ localVars.name3=name3; localVars.tit3=tit3; localVars.Mean=Mean; % Like sequential execution! - +nvar0=nvar; if ~exist('OCTAVE_VERSION') % Commenting for testing! @@ -165,7 +135,7 @@ if ~exist('OCTAVE_VERSION') globalVars = struct('M_',M_, ... 'options_', options_, ... 'oo_', oo_); - [fout, nBlockPerCPU, totCPU] = masterParallel(options_.parallel, 1, nvar, [],'pm3_core', localVars,globalVars, options_.parallel_info); + [fout, nvar0, totCPU] = masterParallel(options_.parallel, 1, nvar, [],'pm3_core', localVars,globalVars, options_.parallel_info); end end else @@ -175,6 +145,54 @@ else fout = pm3_core(localVars,1,nvar,0); end +subplotnum = 0; + +if options_.TeX, + fidTeX = fopen([M_.dname '/Output/' M_.fname '_' name3 '.TeX'],'w'); + fprintf(fidTeX,'%% TeX eps-loader file generated by Dynare.\n'); + fprintf(fidTeX,['%% ' datestr(now,0) '\n']); + fprintf(fidTeX,' \n'); + nvar0=cumsum(nvar0); + + i=0; + for j=1:length(nvar0), + + NAMES = []; + TEXNAMES = []; + nvar=nvar0(j); + while i 10^(-6) + subplotnum = subplotnum+1; + name = deblank(varlist(i,:)); + texname = deblank(varlist_TeX(i,:)); + if subplotnum==1 + NAMES = name; + TEXNAMES = ['$' texname '$']; + else + NAMES = char(NAMES,name); + TEXNAMES = char(TEXNAMES,['$' texname '$']); + end + end + if subplotnum == MaxNumberOfPlotsPerFigure || i == nvar + fprintf(fidTeX,'\\begin{figure}[H]\n'); + for jj = 1:size(TEXNAMES,1) + fprintf(fidTeX,['\\psfrag{%s}[1][][0.5][0]{%s}\n'],deblank(NAMES(jj,:)),deblank(TEXNAMES(jj,:))); + end + fprintf(fidTeX,'\\centering \n'); + fprintf(fidTeX,['\\includegraphics[scale=0.5]{%s/Output/%s_' name3 '_%s}\n'],M_.dname,M_.fname,deblank(tit3(i,:))); + fprintf(fidTeX,'\\label{Fig:%s:%s}\n',name3,deblank(tit3(i,:))); + fprintf(fidTeX,'\\end{figure}\n'); + fprintf(fidTeX,' \n'); + subplotnum = 0; + NAMES = []; + TEXNAMES = []; + end + end + end + fprintf(fidTeX,'%% End of TeX file.\n'); + fclose(fidTeX); +end fprintf(['MH: ' tit1 ', done!\n']); diff --git a/matlab/prior_posterior_statistics.m b/matlab/prior_posterior_statistics.m index a492b80f7..588ab9e29 100644 --- a/matlab/prior_posterior_statistics.m +++ b/matlab/prior_posterior_statistics.m @@ -221,13 +221,16 @@ if isnumeric(options_.parallel), % Parallel execution! else [nCPU, totCPU, nBlockPerCPU] = distributeJobs(options_.parallel, 1, B); + ifil=zeros(7,totCPU); for j=1:totCPU-1, - nfiles = ceil(nBlockPerCPU(j)/MAX_nsmoo); - ifil(1,j+1) =ifil(1,j)+nfiles; - nfiles = ceil(nBlockPerCPU(j)/MAX_ninno); - ifil(2,j+1) =ifil(2,j)+nfiles; - nfiles = ceil(nBlockPerCPU(j)/MAX_nerro); - ifil(3,j+1) =ifil(3,j)+nfiles; + if run_smoother + nfiles = ceil(nBlockPerCPU(j)/MAX_nsmoo); + ifil(1,j+1) =ifil(1,j)+nfiles; + nfiles = ceil(nBlockPerCPU(j)/MAX_ninno); + ifil(2,j+1) =ifil(2,j)+nfiles; + nfiles = ceil(nBlockPerCPU(j)/MAX_nerro); + ifil(3,j+1) =ifil(3,j)+nfiles; + end if naK nfiles = ceil(nBlockPerCPU(j)/MAX_naK); ifil(4,j+1) =ifil(4,j)+nfiles; @@ -274,16 +277,16 @@ if ~isnumeric(options_.parallel), leaveSlaveOpen = options_.parallel_info.leaveSlaveOpen; if options_.parallel_info.leaveSlaveOpen == 0, % Commenting for testing!!! - % options_.parallel_info.leaveSlaveOpen = 1; % Force locally to leave open remote matlab sessions (repeated pm3 calls) + options_.parallel_info.leaveSlaveOpen = 1; % Force locally to leave open remote matlab sessions (repeated pm3 calls) end end if options_.smoother pm3(endo_nbr,gend,ifil(1),B,'Smoothed variables',... - '',M_.endo_names(1:M_.orig_endo_nbr, :),'tit_tex',M_.endo_names,... + '',M_.endo_names(1:M_.orig_endo_nbr, :),M_.endo_names_tex,M_.endo_names,... varlist,'SmoothedVariables',DirectoryName,'_smooth'); pm3(exo_nbr,gend,ifil(2),B,'Smoothed shocks',... - '',M_.exo_names,'tit_tex',M_.exo_names,... + '',M_.exo_names,M_.exo_names_tex,M_.exo_names,... M_.exo_names,'SmoothedShocks',DirectoryName,'_inno'); if nvn % needs to be fixed From a070f5cb2627d5c4b9f7faac0d3322bd6f73ae9a Mon Sep 17 00:00:00 2001 From: Marco Ratto Date: Wed, 30 May 2012 11:24:35 +0200 Subject: [PATCH 2/3] Fixed initialization of matrices for posterior irfs. --- matlab/PosteriorIRF.m | 1 + matlab/PosteriorIRF_core1.m | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/matlab/PosteriorIRF.m b/matlab/PosteriorIRF.m index c70b05f82..ec7cdf173 100644 --- a/matlab/PosteriorIRF.m +++ b/matlab/PosteriorIRF.m @@ -172,6 +172,7 @@ localVars.IRUN = IRUN; localVars.irun = irun; localVars.irun2=irun2; localVars.nosaddle=nosaddle; +localVars.npar = npar; localVars.type=type; if strcmpi(type,'posterior') diff --git a/matlab/PosteriorIRF_core1.m b/matlab/PosteriorIRF_core1.m index 55beeafcd..d89308db9 100644 --- a/matlab/PosteriorIRF_core1.m +++ b/matlab/PosteriorIRF_core1.m @@ -53,20 +53,12 @@ IRUN = myinputs.IRUN; irun =myinputs.irun; irun2=myinputs.irun2; nosaddle=myinputs.nosaddle; +npar=myinputs.npar; type=myinputs.type; if ~strcmpi(type,'prior'), x=myinputs.x; end -if options_.dsge_var - gend=myinputs.gend; - nvobs=myinputs.nvobs; - NumberOfParametersPerEquation = myinputs.NumberOfParametersPerEquation; - NumberOfLags = myinputs.NumberOfLags; - NumberOfLagsTimesNvobs = myinputs.NumberOfLagsTimesNvobs; - Companion_matrix = myinputs.Companion_matrix; -end - nvar=myinputs.nvar; IndxVariables=myinputs.IndxVariables; MAX_nirfs_dsgevar=myinputs.MAX_nirfs_dsgevar; @@ -77,6 +69,17 @@ NumberOfIRFfiles_dsge=myinputs.NumberOfIRFfiles_dsge; NumberOfIRFfiles_dsgevar=myinputs.NumberOfIRFfiles_dsgevar; ifil2=myinputs.ifil2; +if options_.dsge_var + gend=myinputs.gend; + nvobs=myinputs.nvobs; + NumberOfParametersPerEquation = myinputs.NumberOfParametersPerEquation; + NumberOfLags = myinputs.NumberOfLags; + NumberOfLagsTimesNvobs = myinputs.NumberOfLagsTimesNvobs; + Companion_matrix = myinputs.Companion_matrix; + stock_irf_bvardsge = zeros(options_.irf,nvobs,M_.exo_nbr,MAX_nirfs_dsgevar); +end + + if whoiam Parallel=myinputs.Parallel; end @@ -129,7 +132,8 @@ if whoiam end % Parallel 'while' very good!!! - +stock_param=zeros(MAX_nruns,npar); +stock_irf_dsge=zeros(options_.irf,nvar,M_.exo_nbr,MAX_nirfs_dsge); while fpar Date: Wed, 30 May 2012 11:26:07 +0200 Subject: [PATCH 3/3] Fixed output list of objective function (to cope with new list for analytic derivatives). --- matlab/mode_check.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/mode_check.m b/matlab/mode_check.m index ef780f66a..e827c4b2d 100644 --- a/matlab/mode_check.m +++ b/matlab/mode_check.m @@ -124,7 +124,7 @@ for plt = 1:nbplt, end for i=1:length(z) xx(kk) = z(i); - [fval, exit_flag] = feval(fun,xx,DynareDataset,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults); + [fval, junk1, junk2, exit_flag] = feval(fun,xx,DynareDataset,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults); if exit_flag y(i,1) = fval; else