1function plot_identification(params, idemoments, idehess, idemodel, idelre, advanced, tittxt, name, IdentifDirectoryName, tit_TeX, name_tex)
2% function plot_identification(params,idemoments,idehess,idemodel, idelre, advanced, tittxt, name, IdentifDirectoryName)
3%
4% INPUTS
5%    o params               [array] parameter values for identification checks
6%    o idemoments           [structure] identification results for the moments
7%    o idehess              [structure] identification results for the Hessian
8%    o idemodel             [structure] identification results for the reduced form solution
9%    o idelre               [structure] identification results for the LRE model
10%    o advanced             [integer] flag for advanced identification checks
11%    o tittxt               [char] name of the results to plot
12%    o name                 [char] list of names
13%    o IdentifDirectoryName [char] directory name
14%    o tittxt               [char] TeX-name of the results to plot
15%    o name_tex             [char] TeX-names of the parameters
16% OUTPUTS
17%    None
18%
19% SPECIAL REQUIREMENTS
20%    None
21
22% Copyright (C) 2008-2017 Dynare Team
23%
24% This file is part of Dynare.
25%
26% Dynare is free software: you can redistribute it and/or modify
27% it under the terms of the GNU General Public License as published by
28% the Free Software Foundation, either version 3 of the License, or
29% (at your option) any later version.
30%
31% Dynare is distributed in the hope that it will be useful,
32% but WITHOUT ANY WARRANTY; without even the implied warranty of
33% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
34% GNU General Public License for more details.
35%
36% You should have received a copy of the GNU General Public License
37% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
38
39global M_ options_
40
41if nargin <10 || isempty(tit_TeX)
42    tit_TeX=tittxt;
43end
44
45if nargin <11
46    name_TeX=name;
47end
48
49[SampleSize, nparam]=size(params);
50si_dMOMENTSnorm = idemoments.si_dMOMENTSnorm;
51si_dTAUnorm = idemodel.si_dREDUCEDFORMnorm;
52si_dLREnorm = idelre.si_dDYNAMICnorm;
53
54tittxt1=regexprep(tittxt, ' ', '_');
55tittxt1=strrep(tittxt1, '.', '');
56if SampleSize == 1
57    si_dMOMENTS = idemoments.si_dMOMENTS;
58    hh = dyn_figure(options_.nodisplay,'Name',[tittxt, ' - Identification using info from observables']);
59    subplot(211)
60    mmm = (idehess.ide_strength_dMOMENTS);
61    [ss, is] = sort(mmm);
62    if ~all(isnan(idehess.ide_strength_dMOMENTS_prior))
63        bar(1:nparam,log([idehess.ide_strength_dMOMENTS(:,is)' idehess.ide_strength_dMOMENTS_prior(:,is)']))
64    else
65        bar(1:nparam,log([idehess.ide_strength_dMOMENTS(:,is)' ]))
66    end
67    hold on
68    plot((1:length(idehess.ide_strength_dMOMENTS(:,is)))-0.15,log([idehess.ide_strength_dMOMENTS(:,is)']),'o','MarkerSize',7,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor','none')
69    plot((1:length(idehess.ide_strength_dMOMENTS_prior(:,is)))+0.15,log([idehess.ide_strength_dMOMENTS_prior(:,is)']),'o','MarkerSize',7,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor','none')
70    if any(isinf(log(idehess.ide_strength_dMOMENTS(idehess.identified_parameter_indices))))
71        %-Inf, i.e. 0 strength
72        inf_indices=find(isinf(log(idehess.ide_strength_dMOMENTS(idehess.identified_parameter_indices))) & log(idehess.ide_strength_dMOMENTS(idehess.identified_parameter_indices))<0);
73        inf_pos=ismember(is,idehess.identified_parameter_indices(inf_indices));
74        plot(find(inf_pos)-0.15,zeros(sum(inf_pos),1),'o','MarkerSize',7,'MarkerFaceColor',[1 0 0],'MarkerEdgeColor',[0 0 0])
75        %+Inf, i.e. Inf strength
76        inf_indices=find(isinf(log(idehess.ide_strength_dMOMENTS(idehess.identified_parameter_indices))) & log(idehess.ide_strength_dMOMENTS(idehess.identified_parameter_indices))>0);
77        inf_pos=ismember(is,idehess.identified_parameter_indices(inf_indices));
78        plot(find(inf_pos)-0.15,zeros(sum(inf_pos),1),'o','MarkerSize',7,'MarkerFaceColor',[1 1 1],'MarkerEdgeColor',[0 0 0])
79    end
80    if any(isinf(log(idehess.ide_strength_dMOMENTS_prior(idehess.identified_parameter_indices))))
81        %-Inf, i.e. 0 strength
82        inf_indices=find(isinf(log(idehess.ide_strength_dMOMENTS_prior(idehess.identified_parameter_indices))) & log(idehess.ide_strength_dMOMENTS_prior(idehess.identified_parameter_indices))<0);
83        inf_pos=ismember(is,idehess.identified_parameter_indices(inf_indices));
84        plot(find(inf_pos)+0.15,zeros(sum(inf_pos),1),'o','MarkerSize',7,'MarkerFaceColor',[1 0 0],'MarkerEdgeColor',[0 0 0])
85        %+Inf, i.e. 0 strength
86        inf_indices=find(isinf(log(idehess.ide_strength_dMOMENTS_prior(idehess.identified_parameter_indices))) & log(idehess.ide_strength_dMOMENTS_prior(idehess.identified_parameter_indices))>0);
87        inf_pos=ismember(is,idehess.identified_parameter_indices(inf_indices));
88        plot(find(inf_pos)+0.15,zeros(sum(inf_pos),1),'o','MarkerSize',7,'MarkerFaceColor',[1 1 1],'MarkerEdgeColor',[0 0 0])
89    end
90    set(gca,'xlim',[0 nparam+1])
91    set(gca,'xticklabel','')
92    dy = get(gca,'ylim');
93    for ip=1:nparam
94        text(ip,dy(1),name{is(ip)},'rotation',90,'HorizontalAlignment','right','interpreter','none')
95    end
96    if ~all(isnan(idehess.ide_strength_dMOMENTS_prior))
97        legend('relative to param value','relative to prior std','Location','Best')
98    else
99        legend('relative to param value','Location','Best')
100    end
101    if  idehess.flag_score
102        title('Identification strength with asymptotic Information matrix (log-scale)')
103    else
104        title('Identification strength with moments Information matrix (log-scale)')
105    end
106
107    subplot(212)
108    if ~all(isnan(idehess.deltaM_prior))
109        bar(1:nparam, log([idehess.deltaM(is) idehess.deltaM_prior(is)]))
110    else
111        bar(1:nparam, log([idehess.deltaM(is)]))
112    end
113    hold on
114    plot((1:length(idehess.deltaM(is)))-0.15,log([idehess.deltaM(is)']),'o','MarkerSize',7,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor','none')
115    plot((1:length(idehess.deltaM_prior(is)))+0.15,log([idehess.deltaM_prior(is)']),'o','MarkerSize',7,'MarkerFaceColor',[0 0 0],'MarkerEdgeColor','none')
116    inf_pos=find(isinf(log(idehess.deltaM)));
117    if ~isempty(inf_pos)
118        inf_indices=~ismember(inf_pos,idehess.sensitivity_zero_pos);
119        inf_pos=ismember(is,inf_pos(inf_indices));
120        plot(find(inf_pos)-0.15,zeros(sum(inf_pos),1),'o','MarkerSize',7,'MarkerFaceColor',[1 1 1],'MarkerEdgeColor',[0 0 0])
121    end
122    inf_pos=find(isinf(log(idehess.deltaM_prior)));
123    if ~isempty(inf_pos)
124        inf_indices=~ismember(inf_pos,idehess.sensitivity_zero_pos);
125        inf_pos=ismember(is,inf_pos(inf_indices));
126        plot(find(inf_pos)+0.15,zeros(sum(inf_pos),1),'o','MarkerSize',7,'MarkerFaceColor',[1 1 1],'MarkerEdgeColor',[0 0 0])
127    end
128    set(gca,'xlim',[0 nparam+1])
129    set(gca,'xticklabel','')
130    dy = get(gca,'ylim');
131    for ip=1:nparam
132        text(ip,dy(1),name{is(ip)},'rotation',90,'HorizontalAlignment','right','interpreter','none')
133    end
134    if ~all(isnan(idehess.deltaM_prior))
135        legend('relative to param value','relative to prior std','Location','Best')
136    else
137        legend('relative to param value','Location','Best')
138    end
139    if  idehess.flag_score
140        title('Sensitivity component with asymptotic Information matrix (log-scale)')
141    else
142        title('Sensitivity component with moments Information matrix (log-scale)')
143    end
144    if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
145        fidTeX = fopen([IdentifDirectoryName '/' M_.fname '_ident_strength_' tittxt1,'.tex'],'w');
146        fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
147        fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
148        fprintf(fidTeX,'\\begin{figure}[H]\n');
149        fprintf(fidTeX,'\\centering \n');
150        fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_ident_strength_%s}\n',[IdentifDirectoryName '/' M_.fname],tittxt1);
151        fprintf(fidTeX,'\\caption{%s  - Identification using info from observables.}',tit_TeX);
152        fprintf(fidTeX,'\\label{Fig:ident:%s}\n',deblank(tittxt));
153        fprintf(fidTeX,'\\end{figure}\n\n');
154        fprintf(fidTeX,'%% End Of TeX file. \n');
155        fclose(fidTeX);
156    end
157    dyn_saveas(hh,[IdentifDirectoryName '/' M_.fname '_ident_strength_' tittxt1],options_.nodisplay,options_.graph_format);
158
159    if advanced
160        if ~options_.nodisplay
161            skipline()
162            disp('Plotting advanced diagnostics')
163        end
164        if all(isnan([si_dMOMENTSnorm';si_dTAUnorm';si_dLREnorm']))
165            fprintf('\nIDENTIFICATION: Skipping sensitivity plot, because standard deviation of parameters is NaN, possibly due to the use of ML.\n')
166        else
167            hh = dyn_figure(options_.nodisplay,'Name',[tittxt, ' - Sensitivity plot']);
168            subplot(211)
169            mmm = (si_dMOMENTSnorm)'./max(si_dMOMENTSnorm);
170            mmm1 = (si_dTAUnorm)'./max(si_dTAUnorm);
171            mmm=[mmm mmm1];
172            mmm1 = (si_dLREnorm)'./max(si_dLREnorm);
173            offset=length(si_dTAUnorm)-length(si_dLREnorm);
174            mmm1 = [NaN(offset,1); mmm1];
175            mmm=[mmm mmm1];
176
177            bar(log(mmm(is,:).*100))
178            set(gca,'xlim',[0 nparam+1])
179            set(gca,'xticklabel','')
180            dy = get(gca,'ylim');
181            for ip=1:nparam
182                text(ip,dy(1),name{is(ip)},'rotation',90,'HorizontalAlignment','right','interpreter','none')
183            end
184            legend('Moments','Model','LRE model','Location','Best')
185            title('Sensitivity bars using derivatives (log-scale)')
186            dyn_saveas(hh,[IdentifDirectoryName '/' M_.fname '_sensitivity_' tittxt1 ],options_.nodisplay,options_.graph_format);
187            if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
188                fidTeX = fopen([IdentifDirectoryName '/' M_.fname '_sensitivity_' tittxt1,'.tex'],'w');
189                fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
190                fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
191                fprintf(fidTeX,'\\begin{figure}[H]\n');
192                fprintf(fidTeX,'\\centering \n');
193                fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_sensitivity_%s}\n',[IdentifDirectoryName '/' M_.fname],tittxt1);
194                fprintf(fidTeX,'\\caption{%s  - Sensitivity plot.}',tit_TeX);
195                fprintf(fidTeX,'\\label{Fig:sensitivity:%s}\n',deblank(tittxt));
196                fprintf(fidTeX,'\\end{figure}\n\n');
197                fprintf(fidTeX,'%% End Of TeX file. \n');
198                fclose(fidTeX);
199            end
200        end
201        % identificaton patterns
202        for  j=1:size(idemoments.cosndMOMENTS,2)
203            pax=NaN(nparam,nparam);
204            %             fprintf('\n')
205            %             disp(['Collinearity patterns with ', int2str(j) ,' parameter(s)'])
206            %             fprintf('%-15s [%-*s] %10s\n','Parameter',(15+1)*j,' Expl. params ','cosn')
207            for i=1:nparam
208                namx='';
209                for in=1:j
210                    dumpindx = idemoments.pars{i,j}(in);
211                    if isnan(dumpindx)
212                        namx=[namx ' ' sprintf('%-15s','--')];
213                    else
214                        namx=[namx ' ' sprintf('%-15s',name{dumpindx})];
215                        pax(i,dumpindx)=idemoments.cosndMOMENTS(i,j);
216                    end
217                end
218                %                 fprintf('%-15s [%s] %10.3f\n',name{i},namx,idemoments.cosndMOMENTS(i,j))
219            end
220            hh = dyn_figure(options_.nodisplay,'Name',[tittxt,' - Collinearity patterns with ', int2str(j) ,' parameter(s)']);
221            imagesc(pax,[0 1]);
222            set(gca,'xticklabel','')
223            set(gca,'yticklabel','')
224            for ip=1:nparam
225                text(ip,(0.5),name{ip},'rotation',90,'HorizontalAlignment','left','interpreter','none')
226                text(0.5,ip,name{ip},'rotation',0,'HorizontalAlignment','right','interpreter','none')
227            end
228            colorbar;
229            colormap('jet');
230            ax=colormap;
231            ax(1,:)=[0.9 0.9 0.9];
232            colormap(ax);
233            if nparam>10
234                set(gca,'xtick',(5:5:nparam))
235                set(gca,'ytick',(5:5:nparam))
236            end
237            set(gca,'xgrid','on')
238            set(gca,'ygrid','on')
239            xlabel([tittxt,' - Collinearity patterns with ', int2str(j) ,' parameter(s)'],'interpreter','none')
240            dyn_saveas(hh,[ IdentifDirectoryName '/' M_.fname '_ident_collinearity_' tittxt1 '_' int2str(j) ],options_.nodisplay,options_.graph_format);
241            if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
242                fidTeX = fopen([ IdentifDirectoryName '/' M_.fname '_ident_collinearity_' tittxt1 '_' int2str(j),'.tex'],'w');
243                fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
244                fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
245                fprintf(fidTeX,'\\begin{figure}[H]\n');
246                fprintf(fidTeX,'\\centering \n');
247                fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_ident_collinearity_%s_%u}\n',[IdentifDirectoryName '/' M_.fname],tittxt1,j);
248                fprintf(fidTeX,'\\caption{%s  - Collinearity patterns with %u parameter(s).}',tit_TeX,j);
249                fprintf(fidTeX,'\\label{Fig:collinearity:%s:%u_pars}\n',deblank(tittxt),j);
250                fprintf(fidTeX,'\\end{figure}\n\n');
251                fprintf(fidTeX,'%% End Of TeX file. \n');
252                fclose(fidTeX);
253            end
254        end
255        skipline()
256        [U,S,V]=svd(idehess.AHess,0);
257        S=diag(S);
258        if idehess.flag_score
259            if nparam<5
260                f1 = dyn_figure(options_.nodisplay,'Name',[tittxt,' - Identification patterns (Information matrix)']);
261                tex_tit_1=[tittxt,' - Identification patterns (Information matrix)'];
262            else
263                f1 = dyn_figure(options_.nodisplay,'Name',[tittxt,' - Identification patterns (Information matrix): SMALLEST SV']);
264                tex_tit_1=[tittxt,' - Identification patterns (Information matrix): SMALLEST SV'];
265                f2 = dyn_figure(options_.nodisplay,'Name',[tittxt,' - Identification patterns (Information matrix): HIGHEST SV']);
266                tex_tit_2=[tittxt,' - Identification patterns (Information matrix): HIGHEST SV'];
267            end
268        else
269            %             S = idemoments.S;
270            %             V = idemoments.V;
271            if nparam<5
272                f1 = dyn_figure(options_.nodisplay,'Name',[tittxt,' - Identification patterns (moments Information matrix)']);
273                tex_tit_1=[tittxt,' - Identification patterns (moments Information matrix)'];
274            else
275                f1 = dyn_figure(options_.nodisplay,'Name',[tittxt,' - Identification patterns (moments Information matrix): SMALLEST SV']);
276                tex_tit_1=[tittxt,' - Identification patterns (moments Information matrix): SMALLEST SV'];
277                f2 = dyn_figure(options_.nodisplay,'Name',[tittxt,' - Identification patterns (moments Information matrix): HIGHEST SV']);
278                tex_tit_2=[tittxt,' - Identification patterns (moments Information matrix): HIGHEST SV'];
279            end
280        end
281        for j=1:min(nparam,8)
282            if j<5
283                set(0,'CurrentFigure',f1),
284                jj=j;
285            else
286                set(0,'CurrentFigure',f2),
287                jj=j-4;
288            end
289            subplot(4,1,jj)
290            if j<5
291                bar(abs(V(:,end-j+1)))
292                Stit = S(end-j+1);
293            else
294                bar(abs(V(:,jj))),
295                Stit = S(jj);
296            end
297            set(gca,'xticklabel','')
298            if j==4 || j==nparam || j==8
299                for ip=1:nparam
300                    text(ip,-0.02,name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
301                end
302            end
303            title(['Singular value ',num2str(Stit)])
304        end
305        dyn_saveas(f1,[  IdentifDirectoryName '/' M_.fname '_ident_pattern_' tittxt1 '_1' ],options_.nodisplay,options_.graph_format);
306        if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
307            fidTeX = fopen([  IdentifDirectoryName '/' M_.fname '_ident_pattern_' tittxt1 '_1','.tex'],'w');
308            fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
309            fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
310            fprintf(fidTeX,'\\begin{figure}[H]\n');
311            fprintf(fidTeX,'\\centering \n');
312            fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_ident_pattern_%s_1}\n',[IdentifDirectoryName '/' M_.fname],tittxt1);
313            fprintf(fidTeX,'\\caption{%s.}',tex_tit_1);
314            fprintf(fidTeX,'\\label{Fig:ident_pattern:%s:1}\n',tittxt1);
315            fprintf(fidTeX,'\\end{figure}\n\n');
316            fprintf(fidTeX,'%% End Of TeX file. \n');
317            fclose(fidTeX);
318        end
319        if nparam>4
320            dyn_saveas(f2,[  IdentifDirectoryName '/' M_.fname '_ident_pattern_' tittxt1 '_2' ],options_.nodisplay,options_.graph_format);
321            if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
322                fidTeX = fopen([  IdentifDirectoryName '/' M_.fname '_ident_pattern_' tittxt1 '_2.tex'],'w');
323                fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
324                fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
325                fprintf(fidTeX,'\\begin{figure}[H]\n');
326                fprintf(fidTeX,'\\centering \n');
327                fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_ident_pattern_%s_2}\n',[IdentifDirectoryName '/' M_.fname],tittxt1);
328                fprintf(fidTeX,'\\caption{%s.}',tex_tit_2);
329                fprintf(fidTeX,'\\label{Fig:ident_pattern:%s:2}\n',tittxt1);
330                fprintf(fidTeX,'\\end{figure}\n\n');
331                fprintf(fidTeX,'%% End Of TeX file. \n');
332                fclose(fidTeX);
333            end
334        end
335    end
336
337else
338    hh = dyn_figure(options_.nodisplay,'Name',['MC sensitivities']);
339    subplot(211)
340    mmm = (idehess.ide_strength_dMOMENTS);
341    [ss, is] = sort(mmm);
342    mmm = mean(si_dMOMENTSnorm)';
343    mmm = mmm./max(mmm);
344    if advanced
345        mmm1 = mean(si_dTAUnorm)';
346        mmm=[mmm mmm1./max(mmm1)];
347        mmm1 = mean(si_dLREnorm)';
348        offset=size(si_dTAUnorm,2)-size(si_dLREnorm,2);
349        mmm1 = [NaN(offset,1); mmm1./max(mmm1)];
350        mmm=[mmm mmm1];
351    end
352
353    bar(mmm(is,:))
354    set(gca,'xlim',[0 nparam+1])
355    set(gca,'xticklabel','')
356    dy = get(gca,'ylim');
357    for ip=1:nparam
358        text(ip,dy(1),name{is(ip)},'rotation',90,'HorizontalAlignment','right','interpreter','none')
359    end
360    if advanced
361        legend('Moments','Model','LRE model','Location','Best')
362    end
363    title('MC mean of sensitivity measures')
364    dyn_saveas(hh,[ IdentifDirectoryName '/' M_.fname '_MC_sensitivity' ],options_.nodisplay,options_.graph_format);
365    if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
366        fidTeX = fopen([ IdentifDirectoryName '/' M_.fname '_MC_sensitivity.tex'],'w');
367        fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
368        fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
369        fprintf(fidTeX,'\\begin{figure}[H]\n');
370        fprintf(fidTeX,'\\centering \n');
371        fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_MC_sensitivity}\n',[IdentifDirectoryName '/' M_.fname]);
372        fprintf(fidTeX,'\\caption{MC mean of sensitivity measures}');
373        fprintf(fidTeX,'\\label{Fig:_MC_sensitivity}\n');
374        fprintf(fidTeX,'\\end{figure}\n\n');
375        fprintf(fidTeX,'%% End Of TeX file. \n');
376        fclose(fidTeX);
377    end
378
379    if advanced
380        if ~options_.nodisplay,
381            skipline()
382            disp('Displaying advanced diagnostics')
383        end
384        %         options_.nograph=1;
385        hh = dyn_figure(options_.nodisplay,'Name','MC Condition Number');
386        subplot(221)
387        hist(log10(idemodel.cond))
388        title('log10 of Condition number in the model')
389        subplot(222)
390        hist(log10(idemoments.cond))
391        title('log10 of Condition number in the moments')
392        subplot(223)
393        hist(log10(idelre.cond))
394        title('log10 of Condition number in the LRE model')
395        dyn_saveas(hh,[IdentifDirectoryName '/' M_.fname '_ident_COND' ],options_.nodisplay,options_.graph_format);
396        options_mcf.pvalue_ks = 0.1;
397        options_mcf.pvalue_corr = 0.001;
398        options_mcf.alpha2 = 0;
399        options_mcf.param_names = name;
400        options_mcf.param_names_tex = name_tex;
401        options_mcf.fname_ = M_.fname;
402        options_mcf.OutputDirectoryName = IdentifDirectoryName;
403        options_mcf.beha_title = 'LOW condition nbr';
404        options_mcf.nobeha_title = 'HIGH condition nbr';
405        options_mcf.amcf_name = 'MC_HighestCondNumberLRE';
406        options_mcf.amcf_title = 'MC Highest Condition Number LRE Model';
407        options_mcf.title = 'MC Highest Condition Number LRE Model';
408        ncut=floor(SampleSize/10*9);
409        [dum,is]=sort(idelre.cond);
410        mcf_analysis(params, is(1:ncut), is(ncut+1:end), options_mcf, options_);
411        options_mcf.amcf_name = 'MC_HighestCondNumberModel';
412        options_mcf.amcf_title = 'MC Highest Condition Number Model Solution';
413        options_mcf.title = 'MC Highest Condition Number Model Solution';
414        [dum,is]=sort(idemodel.cond);
415        mcf_analysis(params, is(1:ncut), is(ncut+1:end), options_mcf, options_);
416        options_mcf.amcf_name = 'MC_HighestCondNumberMoments';
417        options_mcf.amcf_title = 'MC Highest Condition Number Model Moments';
418        options_mcf.title = 'MC Highest Condition Number Model Moments';
419        [dum,is]=sort(idemoments.cond);
420        mcf_analysis(params, is(1:ncut), is(ncut+1:end), options_mcf, options_);
421        %         [proba, dproba] = stab_map_1(idemoments.Mco', is(1:ncut), is(ncut+1:end), 'HighestCondNumberMoments_vs_Mco', 1, [], IdentifDirectoryName);
422        %         for j=1:nparam,
423        % %             ibeh=find(idemoments.Mco(j,:)<0.9);
424        % %             inonbeh=find(idemoments.Mco(j,:)>=0.9);
425        % %             if ~isempty(ibeh) && ~isempty(inonbeh)
426        % %                 [proba, dproba] = stab_map_1(params, ibeh, inonbeh, ['HighestMultiCollinearity_',name{j}], 1, [], IdentifDirectoryName);
427        % %             end
428        %             [~,is]=sort(idemoments.Mco(:,j));
429        %             [proba, dproba] = stab_map_1(params, is(1:ncut), is(ncut+1:end), ['MC_HighestMultiCollinearity_',name{j}], 1, [], IdentifDirectoryName, 0.15);
430        %         end
431
432        if nparam<5
433            f1 = dyn_figure(options_.nodisplay,'Name',[tittxt,' - MC Identification patterns (moments): HIGHEST SV']);
434            tex_tit_1=[tittxt,' - MC Identification patterns (moments): HIGHEST SV'];
435        else
436            f1 = dyn_figure(options_.nodisplay,'Name',[tittxt,' - MC Identification patterns (moments): SMALLEST SV']);
437            tex_tit_1=[tittxt,' - MC Identification patterns (moments): SMALLEST SV'];
438            f2 = dyn_figure(options_.nodisplay,'Name',[tittxt,' - MC Identification patterns (moments): HIGHEST SV']);
439            tex_tit_2=[tittxt,' - MC Identification patterns (moments): HIGHEST SV'];
440        end
441        nplots=min(nparam,8);
442        if nplots>4
443            nsubplo=ceil(nplots/2);
444        else
445            nsubplo=nplots;
446        end
447        for j=1:nplots
448            if (nparam>4 && j<=ceil(nplots/2)) || nparam<5
449                set(0,'CurrentFigure',f1),
450                jj=j;
451                VVV=squeeze(abs(idemoments.V(:,:,end-j+1)));
452                SSS = idemoments.S(:,end-j+1);
453            else
454                set(0,'CurrentFigure',f2),
455                jj=j-ceil(nplots/2);
456                VVV=squeeze(abs(idemoments.V(:,:,jj)));
457                SSS = idemoments.S(:,jj);
458            end
459            subplot(nsubplo,1,jj)
460            for i=1:nparam
461                [post_mean, post_median(:,i), post_var, hpd_interval(i,:), post_deciles] = posterior_moments(VVV(:,i),0,0.9);
462            end
463            bar(post_median)
464            hold on, plot(hpd_interval,'--*r'),
465            Stit=mean(SSS);
466
467            set(gca,'xticklabel','')
468            if j==4 || j==nparam || j==8
469                for ip=1:nparam
470                    text(ip,-0.02,name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
471                end
472            end
473            title(['MEAN Singular value ',num2str(Stit)])
474        end
475        dyn_saveas(f1,[IdentifDirectoryName '/' M_.fname '_MC_ident_pattern_1' ],options_.nodisplay,options_.graph_format);
476        if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
477            fidTeX = fopen([IdentifDirectoryName '/' M_.fname '_MC_ident_pattern_1.tex'],'w');
478            fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
479            fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
480            fprintf(fidTeX,'\\begin{figure}[H]\n');
481            fprintf(fidTeX,'\\centering \n');
482            fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_MC_ident_pattern_1}\n',[IdentifDirectoryName '/' M_.fname]);
483            fprintf(fidTeX,'\\caption{%s.}',tex_tit_1);
484            fprintf(fidTeX,'\\label{Fig:MC_ident_pattern:1}\n');
485            fprintf(fidTeX,'\\end{figure}\n\n');
486            fprintf(fidTeX,'%% End Of TeX file. \n');
487            fclose(fidTeX);
488        end
489        if nparam>4
490            dyn_saveas(f2,[  IdentifDirectoryName '/' M_.fname '_MC_ident_pattern_2' ],options_.nodisplay,options_.graph_format);
491            if options_.TeX && any(strcmp('eps',cellstr(options_.graph_format)))
492                fidTeX = fopen([  IdentifDirectoryName '/' M_.fname '_MC_ident_pattern_2.tex'],'w');
493                fprintf(fidTeX,'%% TeX eps-loader file generated by plot_identification.m (Dynare).\n');
494                fprintf(fidTeX,['%% ' datestr(now,0) '\n\n']);
495                fprintf(fidTeX,'\\begin{figure}[H]\n');
496                fprintf(fidTeX,'\\centering \n');
497                fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s_MC_ident_pattern_2}\n',[IdentifDirectoryName '/' M_.fname]);
498                fprintf(fidTeX,'\\caption{%s.}',tex_tit_2);
499                fprintf(fidTeX,'\\label{Fig:MC_ident_pattern:2}\n');
500                fprintf(fidTeX,'\\end{figure}\n\n');
501                fprintf(fidTeX,'%% End Of TeX file. \n');
502                fclose(fidTeX);
503            end
504        end
505    end
506end
507