Home > . > mode_check.m

mode_check

PURPOSE ^

SYNOPSIS ^

function mode_check(x,fval,hessian,gend,data,lb,ub)

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function mode_check(x,fval,hessian,gend,data,lb,ub)
0002 global bayestopt_ M_ options_
0003 
0004 TeX = options_.TeX;
0005 [s_min,k] = min(diag(hessian))
0006   
0007 disp('\nMODE CHECK\n')
0008 disp(sprintf('Fval obtained by fmincon: %f', fval))
0009 disp(bayestopt_.name)
0010 cname = bayestopt_.name{k};
0011 disp(sprintf('Most negative variance %f for parameter %d (%s = %f)',s_min,k,cname,x(k)))
0012 
0013 [nbplt,nr,nc,lr,lc,nstar] = pltorg(length(x));
0014 
0015 if TeX
0016     fidTeX = fopen([M_.fname '_CheckPlots.TeX'],'w');
0017     fprintf(fidTeX,'%% TeX eps-loader file generated by mode_check.m (Dynare).\n');
0018     fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
0019     fprintf(fidTeX,' \n');
0020 end
0021 
0022 
0023 if nbplt == 1
0024     if TeX
0025         NAMES = [];
0026         TeXNAMES = [];
0027     end    
0028     hh = figure('Name','Check plots');
0029     for k=1:length(x)
0030         subplot(nr,nc,k)
0031         [name,texname] = get_the_name(k,TeX);
0032         if TeX
0033             NAMES = strvcat(NAMES,name);
0034             TeXNAMES = strvcat(TeXNAMES,texname);
0035         end    
0036         xx = x;
0037         l1 = max(lb(k),0.8*x(k)); % kk -> k
0038         l2 = min(ub(k),1.2*x(k)); % kk -> k
0039         z = [l1:(l2-l1)/20:l2];
0040         y = zeros(length(z),1);
0041         for i=1:length(z)
0042             xx(k) = z(i); % kk -> k
0043             y(i) = DsgeLikelihood(xx,gend,data);
0044         end
0045         plot(z,y)
0046         hold on
0047         yl=get(gca,'ylim');
0048         plot([x(k) x(k)],yl,'c','LineWidth', 1);% kk -> k
0049         title(name,'interpreter','none');
0050         hold off
0051         drawnow
0052     end
0053     eval(['print -depsc2 ' M_.fname '_CheckPlots' int2str(1)]);
0054     eval(['print -dpdf ' M_.fname '_CheckPlots' int2str(1)]);
0055     saveas(hh,[M_.fname '_CheckPlots' int2str(1) '.fig']);
0056     if options_.nograph, close(hh), end  
0057     % TeX eps loader file
0058     if TeX
0059         fprintf(fidTeX,'\\begin{figure}[H]\n');
0060         for jj = 1:length(x)
0061             fprintf(fidTeX,'\\psfrag{%s}[1][][0.5][0]{%s}\n',deblank(NAMES(jj,:)),deblank(TeXNAMES(jj,:)));
0062         end    
0063         fprintf(fidTeX,'\\centering \n');
0064         fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_CheckPlots%s}\n',M_.fname,int2str(1));
0065         fprintf(fidTeX,'\\caption{Priors.}');
0066         fprintf(fidTeX,'\\label{Fig:CheckPlots:%s}\n',int2str(1));
0067         fprintf(fidTeX,'\\end{figure}\n');
0068         fprintf(fidTeX,'\n');
0069         fprintf(fidTeX,'%% End of TeX file.\n');
0070         fclose(fidTeX);
0071     end    
0072 else
0073     for plt = 1:nbplt-1
0074         if TeX
0075             NAMES = [];
0076             TeXNAMES = [];
0077         end    
0078         hh = figure('Name','Check plots');
0079         for k=1:nstar
0080             subplot(nr,nc,k)
0081             kk = (plt-1)*nstar+k;
0082             [name,texname] = get_the_name(kk,TeX);
0083             if TeX
0084                 NAMES = strvcat(NAMES,name);
0085                 TeXNAMES = strvcat(TeXNAMES,texname);
0086             end    
0087             xx = x;
0088             l1 = max(lb(kk),0.8*x(kk));
0089             l2 = min(ub(kk),1.2*x(kk));
0090             z = [l1:(l2-l1)/20:l2];
0091             y = zeros(length(z),1);
0092             for i=1:length(z)
0093                 xx(kk) = z(i);
0094                 y(i) = DsgeLikelihood(xx,gend,data);
0095             end
0096             plot(z,y);
0097             hold on
0098             yl=get(gca,'ylim');
0099             plot( [x(kk) x(kk)], yl, 'c', 'LineWidth', 1)
0100             title(name,'interpreter','none')
0101             hold off
0102             drawnow
0103         end    
0104         eval(['print -depsc2 ' M_.fname '_CheckPlots' int2str(plt)]);
0105         eval(['print -dpdf ' M_.fname '_CheckPlots' int2str(plt)]);
0106         saveas(hh,[M_.fname '_CheckPlots' int2str(plt) '.fig']);
0107         if options_.nograph, close(hh), end
0108         if TeX
0109             % TeX eps loader file
0110             fprintf(fidTeX,'\\begin{figure}[H]\n');
0111             for jj = 1:nstar
0112                 fprintf(fidTeX,'\\psfrag{%s}[1][][0.5][0]{%s}\n',deblank(NAMES(jj,:)),deblank(TeXNAMES(jj,:)));
0113             end    
0114             fprintf(fidTeX,'\\centering \n');
0115             fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_CheckPlots%s}\n',M_.fname,int2str(plt));
0116             fprintf(fidTeX,'\\caption{Check plots.}');
0117             fprintf(fidTeX,'\\label{Fig:CheckPlots:%s}\n',int2str(plt));
0118             fprintf(fidTeX,'\\end{figure}\n');
0119             fprintf(fidTeX,' \n');
0120         end
0121     end
0122     hh = figure('Name','Check plots');
0123     k = 1;
0124     if TeX
0125         NAMES = [];
0126         TeXNAMES = [];
0127     end
0128     while (nbplt-1)*nstar+k <= length(x)
0129         kk = (nbplt-1)*nstar+k;
0130         [name,texname] = get_the_name(kk,TeX);
0131         if TeX
0132             NAMES = strvcat(NAMES,name);
0133             TeXNAMES = strvcat(TeXNAMES,texname);
0134         end    
0135         if lr ~= 0
0136             subplot(lr,lc,k)
0137         else
0138             subplot(nr,nc,k)
0139         end    
0140         xx = x;
0141         l1 = max(lb(kk),0.8*x(kk));
0142         l2 = min(ub(kk),1.2*x(kk));
0143         z = [l1:(l2-l1)/20:l2];
0144         y = zeros(length(z),1);
0145         for i=1:length(z)
0146             xx(kk) = z(i);
0147             y(i) = DsgeLikelihood(xx,gend,data);
0148         end
0149         plot(z,y)
0150         hold on
0151         yl=get(gca,'ylim');
0152         plot( [x(kk) x(kk)], yl, 'c', 'LineWidth', 1)
0153         title(name,'interpreter','none')
0154         hold off
0155         k = k + 1;
0156         drawnow
0157     end
0158     eval(['print -depsc2 ' M_.fname '_CheckPlots' int2str(nbplt)]);
0159     eval(['print -dpdf ' M_.fname '_CheckPlots' int2str(nbplt)]);
0160     saveas(hh,[M_.fname '_CheckPlots' int2str(nbplt) '.fig']);
0161     if options_.nograph, close(hh), end
0162     if TeX
0163         fprintf(fidTeX,'\\begin{figure}[H]\n');
0164         for jj = 1:lr*lc
0165             fprintf(fidTeX,'\\psfrag{%s}[1][][0.5][0]{%s}\n',deblank(NAMES(jj,:)),deblank(TeXNAMES(jj,:)));
0166         end    
0167         fprintf(fidTeX,'\\centering \n');
0168         fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_CheckPlots%s}\n',M_.fname,int2str(nbplt));
0169         fprintf(fidTeX,'\\caption{Check plots.}');
0170         fprintf(fidTeX,'\\label{Fig:CheckPlots:%s}\n',int2str(nbplt));
0171         fprintf(fidTeX,'\\end{figure}\n');
0172         fprintf(fidTeX,' \n');
0173         fprintf(fidTeX,'%% End of TeX file.\n');
0174         fclose(fidTeX);
0175     end
0176 end
0177 
0178 % SA 07-31-2004        * New default : no more than nine plots per figure.
0179 %                    * Figures are automatically saved in eps, pdf and fig formats.
0180 %                    * Figures are automatically closed (this should be an option).
0181 %                    * Creation of a TeX-loader file for the postcript file.

Generated on Fri 16-Jun-2006 09:09:06 by m2html © 2003