map_ident_.m 55.8 KB
Newer Older
rattoma's avatar
rattoma committed
1
2
3
4
5
6
7
8
9
10
function map_ident_(OutputDirectoryName)
global bayestopt_ M_ options_ estim_params_ oo_

opt_gsa = options_.opt_gsa;
fname_ = M_.fname;
nliv   = opt_gsa.morris_nliv;
ntra   = opt_gsa.morris_ntra;
itrans = opt_gsa.trans_ident;

np = estim_params_.np;
11
if opt_gsa.load_ident_files,
rattoma's avatar
rattoma committed
12
13
14
15
16
17
18
  gsa_flag=0;
else
  gsa_flag=-2;
end

pnames = M_.param_names(estim_params_.param_vals(:,1),:);

rattoma's avatar
rattoma committed
19
filetoload=[OutputDirectoryName '/' fname_ '_prior'];
rattoma's avatar
rattoma committed
20
load(filetoload,'lpmat','lpmat0','istable','T','yys','nspred','nboth','nfwrd')
21
22
23
24
25
if ~isempty(lpmat0),
  lpmatx=lpmat0(istable,:);
else
  lpmatx=[];
end
rattoma's avatar
rattoma committed
26
27
28
29
30
31
Nsam = size(lpmat,1);
nshock = size(lpmat0,2);
npT = np+nshock;

fname_ = M_.fname;

32
if opt_gsa.load_ident_files==0,
33
  % th moments
34
%     options_.ar = min(3,options_.ar);
rattoma's avatar
rattoma committed
35

rattoma's avatar
rattoma committed
36
37
38
  mss = yys(bayestopt_.mfys,:);
  mss = teff(mss(:,istable),Nsam,istable);
  yys = teff(yys(oo_.dr.order_var,istable),Nsam,istable);
39
  [vdec, cc, ac] = mc_moments(T, lpmatx, oo_.dr);
rattoma's avatar
rattoma committed
40
41


42
  if opt_gsa.morris==2,
43
44
   pdraws = dynare_identification(options_.options_ident,[lpmatx lpmat(istable,:)]);
%    [pdraws, TAU, GAM] = dynare_identification(options_.options_ident,[lpmatx lpmat(istable,:)]);
45
    if max(max(abs(pdraws-[lpmatx lpmat(istable,:)])))==0,
rattoma's avatar
rattoma committed
46
      disp(['Sample check OK ', num2str(max(max(abs(pdraws-[lpmatx lpmat(istable,:)]))))]),
47
      clear pdraws;
rattoma's avatar
rattoma committed
48
    end
rattoma's avatar
rattoma committed
49
50
51
52
53
54
%     for j=1:length(istable), gas(:,j)=[vech(cc(:,:,j)); vec(ac(:,:,j))];  end
%     if ~isempty(mss),
%     gas = [mss(istable,:)'; gas];
%     end
%     if max(max(abs(GAM-gas)))<=1.e-8,
%       disp(['Moments check OK ',num2str(max(max(abs(GAM-gas))))]),
55
      clear GAM gas
rattoma's avatar
rattoma committed
56
%     end
57
  end
rattoma's avatar
rattoma committed
58
  if opt_gsa.morris~=1 & M_.exo_nbr>1,
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
    ifig=0;
    for j=1:M_.exo_nbr,
      if mod(j,6)==1
        figure('name',['Variance decomposition shocks']);
        ifig=ifig+1;
        iplo=0;
      end
      iplo=iplo+1;
      subplot(2,3,iplo)
      myboxplot(squeeze(vdec(:,j,:))',[],'.',[],10)
      %     boxplot(squeeze(vdec(:,j,:))','whis',10,'symbol','.r')
      set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:size(options_.varobs,1)])
      set(gca,'xlim',[0.5 size(options_.varobs,1)+0.5])
      set(gca,'ylim',[-2 102])
      for ip=1:size(options_.varobs,1),
        text(ip,-4,deblank(options_.varobs(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
      end
      xlabel(' ')
      ylabel(' ')
      title(M_.exo_names(j,:),'interpreter','none')
      if mod(j,6)==0 | j==M_.exo_nbr,
        saveas(gcf,[OutputDirectoryName,'/',fname_,'_vdec_exo_',int2str(ifig)])
        eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_vdec_exo_',int2str(ifig)]);
        eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_vdec_exo_',int2str(ifig)]);
        close(gcf),
      end
rattoma's avatar
rattoma committed
85
86
    end
  end
87
88
89
90
91
92
  for j=1:size(cc,1)
    cc(j,j,:)=stand_(squeeze(log(cc(j,j,:))))./2;
  end
  [vdec, j0, ir_vdec, ic_vdec] = teff(vdec,Nsam,istable);
  [cc, j0, ir_cc, ic_cc] = teff(cc,Nsam,istable);
  [ac, j0, ir_ac, ic_ac] = teff(ac,Nsam,istable);
rattoma's avatar
rattoma committed
93

94
  [nr1, nc1, nnn] = size(T);
95
96
97
98
99
100
    endo_nbr = M_.endo_nbr;
    nstatic = oo_.dr.nstatic;
    npred = oo_.dr.npred;
    iv = (1:endo_nbr)';
    ic = [ nstatic+(1:npred) endo_nbr+(1:size(oo_.dr.ghx,2)-npred) ]';
  
101
102
103
    dr.ghx = T(:, [1:(nc1-M_.exo_nbr)],1);
    dr.ghu = T(:, [(nc1-M_.exo_nbr+1):end], 1);
    [Aa,Bb] = kalman_transition_matrix(dr,iv,ic,M_.exo_nbr);
104
105
106
107
108
109
110
111
112
113
%     bayestopt_.restrict_var_list, ...
%     bayestopt_.restrict_columns, ...
%     bayestopt_.restrict_aux, M_.exo_nbr);
  A = zeros(size(Aa,1),size(Aa,2)+size(Aa,1),length(istable));
  % Sig(estim_params_.var_exo(:,1))=lpmatx(1,:).^2;
  set_shocks_param(lpmatx(1,:));
  A(:,:,1)=[Aa, triu(Bb*M_.Sigma_e*Bb')];
  for j=2:length(istable),
    dr.ghx = T(:, [1:(nc1-M_.exo_nbr)],j);
    dr.ghu = T(:, [(nc1-M_.exo_nbr+1):end], j);
114
    [Aa,Bb] = kalman_transition_matrix(dr, iv, ic, M_.exo_nbr);
115
116
117
118
119
120
121
122
%       bayestopt_.restrict_var_list, ...
%       bayestopt_.restrict_columns, ...
%       bayestopt_.restrict_aux, M_.exo_nbr);
    set_shocks_param(lpmatx(j,:));
    A(:,:,j)=[Aa, triu(Bb*M_.Sigma_e*Bb')];
  end
  clear T;
  clear lpmatx;
rattoma's avatar
rattoma committed
123

124
125
126
127
128
129
  [nr,nc,nn]=size(A);
  io=bayestopt_.mf2;
  % T1=A(io,1:nr,:);
  % ino=find(~ismember([1:nr],io));
  % T2=A(ino,1:nr,:);
  R=A(:,nr+1:nc,:);
rattoma's avatar
rattoma committed
130
131
132
%   [tadj, iff] = speed(A(1:nr,1:nr,:),R,io,0.5);
%   [tadj, j0, ir_tadj, ic_tadj] = teff(tadj,Nsam,istable);
%   [iff, j0, ir_if, ic_if] = teff(iff,Nsam,istable);
rattoma's avatar
rattoma committed
133
134


135
  [yt, j0]=teff(A,Nsam,istable);
rattoma's avatar
rattoma committed
136
  yt = [yys yt];
137
  if opt_gsa.morris==2,
rattoma's avatar
rattoma committed
138
139
140
141
142
143
%     iii=find(std(yt(istable,:))>1.e-8);
%     if max(max(abs(TAU-yt(istable,iii)')))<= 1.e-8,
%       err = max(max(abs(TAU-yt(istable,iii)')));
%       disp(['Model check OK ',num2str(err)]),
      clear TAU A
%     end
144
  else
rattoma's avatar
rattoma committed
145
    clear A,
146
147
148
149
150
151
  end
  % [yt1, j01]=teff(T1,Nsam,istable);
  % [yt2, j02]=teff(T2,Nsam,istable);
  % [ytr, j0r]=teff(R,Nsam,istable);
  %
  % yt=[yt1 yt2 ytr];
rattoma's avatar
rattoma committed
152
  save([OutputDirectoryName,'/',fname_,'_main_eff'],'ac','cc','vdec','yt','mss')
153
else
154
  if opt_gsa.morris==2,
155
%    [pdraws, TAU, GAM] = dynare_identification([1:npT]); %,[lpmatx lpmat(istable,:)]);
156
157
%    [pdraws, TAU, GAM] = dynare_identification(options_.options_ident);
   pdraws = dynare_identification(options_.options_ident);
158
  end
rattoma's avatar
rattoma committed
159
  load([OutputDirectoryName,'/',fname_,'_main_eff'],'ac','cc','vdec','yt','mss')
160
end
rattoma's avatar
rattoma committed
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175

%   for j=1:nr,
%     for i=1:nc,
%       y0=squeeze(A(j,i,:));
%       if max(y0)-min(y0)>1.e-10,
%         j0=j0+1;
%         y1=ones(size(lpmat,1),1)*NaN;
%         y1(istable,1)=y0;
%         yt(:,j0)=y1;
%       end
%     end
%   end
%   yt = yt(:,j0);

if opt_gsa.morris==1,
176
  %OutputDir = CheckPath('gsa/screen');
rattoma's avatar
rattoma committed
177
  if ~isempty(vdec),
178
  if opt_gsa.load_ident_files==0,
rattoma's avatar
rattoma committed
179
180
181
182
183
  SAMorris = [];
  for i=1:size(vdec,2),
    [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], vdec(:,i),nliv);
  end
  SAvdec = squeeze(SAMorris(:,1,:))';
rattoma's avatar
rattoma committed
184
  save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAvdec','vdec','ir_vdec','ic_vdec')
185
  else
rattoma's avatar
rattoma committed
186
    load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAvdec','vdec','ir_vdec','ic_vdec')
187
188
  end
  
rattoma's avatar
rattoma committed
189
  figure,
rattoma's avatar
rattoma committed
190
191
%   boxplot(SAvdec,'whis',10,'symbol','r.')
  myboxplot(SAvdec,[],'.',[],10)
rattoma's avatar
rattoma committed
192
193
194
195
196
197
198
199
200
201
  set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT])
  set(gca,'xlim',[0.5 npT+0.5])
  ydum = get(gca,'ylim');
  set(gca,'ylim',[0 ydum(2)])
  set(gca,'position',[0.13 0.2 0.775 0.7])
  for ip=1:npT,
    text(ip,-2,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
  end
  xlabel(' ')
  title('All variance decomposition')
rattoma's avatar
rattoma committed
202
203
204
  saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_vdec'])
  eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_vdec']);
  eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_vdec']);
205
  close(gcf)
rattoma's avatar
rattoma committed
206
207
208
209
  else
  save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'vdec')
    
  end
rattoma's avatar
rattoma committed
210

rattoma's avatar
rattoma committed
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
%   ifig = 0;
%   for j=1:size(options_.varobs,1)
%     if mod(j,6)==1
%       figure('name',['EET variance decomposition observed variables']);
%       ifig=ifig+1;
%       iplo=0;
%     end
%     iplo=iplo+1;
%     subplot(3,2,iplo)
%     iv = find(ir_vdec==j);
%     if ~isempty(iv)
%       if length(iv)>1
% %         boxplot(SAvdec(iv,:),'whis',3,'symbol','r.');
%         myboxplot(SAvdec(iv,:),[],'.',[],3)
%       else
%         plot(SAvdec(iv,:),'r.');
%       end
%       set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT])
%       set(gca,'xlim',[0.5 npT+0.5])
%       ydum = get(gca,'ylim');
%       set(gca,'ylim',[0 ydum(2)])
%       for ip=1:npT,
%         text(ip,-2,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
%       end
%       xlabel(' ')
%     end
%     title(options_.varobs(j,:),'interpreter','none')
%     if mod(j,6)==0 | j==size(options_.varobs,1)
%       saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_vdec_varobs_',int2str(ifig)])
%       eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_vdec_varobs_',int2str(ifig)]);
%       eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_vdec_varobs_',int2str(ifig)]);
%       close(gcf)
%     end
%   end
% 
%   ifig = 0;
%   for j=1:M_.exo_nbr,
%     if mod(j,6)==1
%       figure('name',['EET variance decomposition shocks']);
%       ifig=ifig+1;
%       iplo=0;
%     end
%     iplo=iplo+1;
%     subplot(3,2,iplo)
%     iv = find(ic_vdec==j);
%     if ~isempty(iv)
%       if length(iv)>1
% %         boxplot(SAvdec(iv,:),'whis',3,'symbol','r.');
%         myboxplot(SAvdec(iv,:),[],'.',[],3)
%       else
%         plot(SAvdec(iv,:),'r.');
%       end
%       set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT])
%       set(gca,'xlim',[0.5 npT+0.5])
%       ydum = get(gca,'ylim');
%       set(gca,'ylim',[0 ydum(2)])
%       for ip=1:npT,
%         text(ip,-2,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
%       end
%       xlabel(' ')
%     end
%     title(M_.exo_names(j,:),'interpreter','none')
%     if mod(j,6)==0 | j==M_.exo_nbr,
%       saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_vdec_exo_',int2str(ifig)])
%       eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_vdec_exo_',int2str(ifig)]);
%       eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_vdec_exo_',int2str(ifig)]);
%       close(gcf),
%     end
%   end
rattoma's avatar
rattoma committed
280
281


282
  if opt_gsa.load_ident_files==0,
rattoma's avatar
rattoma committed
283
  SAMorris = [];
rattoma's avatar
rattoma committed
284
  ccac = [mss cc ac];
rattoma's avatar
rattoma committed
285
286
  for i=1:size(ccac,2),
    [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], [ccac(:,i)],nliv);
rattoma's avatar
rattoma committed
287
288
  end
  SAcc = squeeze(SAMorris(:,1,:))';
289
  SAcc = SAcc./(max(SAcc')'*ones(1,npT));
rattoma's avatar
rattoma committed
290
  save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAcc','cc','ir_cc','ic_cc','-append')
rattoma's avatar
rattoma committed
291
  save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'ac','ir_ac','ic_ac','-append')
292
  else
rattoma's avatar
rattoma committed
293
    load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAcc','cc','ir_cc','ic_cc')
rattoma's avatar
rattoma committed
294
    load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'ac','ir_ac','ic_ac')
295
  end
rattoma's avatar
rattoma committed
296
  
rattoma's avatar
rattoma committed
297
  figure,
rattoma's avatar
rattoma committed
298
299
%   boxplot(SAcc,'whis',10,'symbol','r.')
  myboxplot(SAcc,[],'.',[],10)
rattoma's avatar
rattoma committed
300
301
302
  set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT])
  set(gca,'xlim',[0.5 npT+0.5])
  ydum = get(gca,'ylim');
rattoma's avatar
rattoma committed
303
  set(gca,'ylim',[0 1])
rattoma's avatar
rattoma committed
304
305
306
307
308
  set(gca,'position',[0.13 0.2 0.775 0.7])
  for ip=1:npT,
    text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
  end
  xlabel(' ')
rattoma's avatar
rattoma committed
309
310
311
312
313
  title('EET All moments')
  saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_moments'])
  eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_moments']);
  eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_moments']);
%   close(gcf),
rattoma's avatar
rattoma committed
314

315
316
317
318
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MORRIS FOR DERIVATIVES  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

319
% if opt_gsa.load_ident_files==0,
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
%     for j=1:npT,
%   SAMorris = [];
%   ddd=NaN(size(lpmat,1),size(JJ,1));
%   ddd(istable,:) = squeeze(JJ(:,j,:))';
%   for i=1:size(ddd,2),
%     [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], [ddd(:,i)],nliv);
%   end
%   SAddd(:,:,j) = squeeze(SAMorris(:,1,:))';
%   SAddd(:,:,j) = SAddd(:,:,j)./(max(SAddd(:,:,j)')'*ones(1,npT));
%   sad(:,j) = median(SAddd(find(~isnan(squeeze(SAddd(:,1,j)))),:,j))'; 
%     end
%   save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAddd','sad','-append')
%   else
%     load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAddd','sad')
%   end
%   figure,
%   contourf(sad,10), colorbar
%   set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT])
%   set(gca,'yticklabel',' ','fontsize',10,'ytick',[1:npT])
%   for ip=1:npT,
%     text(ip,0.9,['D(',bayestopt_.name{ip},')'],'rotation',90,'HorizontalAlignment','right','interpreter','none')
%     text(0.9,ip,[bayestopt_.name{ip}],'rotation',0,'HorizontalAlignment','right','interpreter','none')
%   end
%   [m,im]=max(sad);
%   iii = find((im-[1:npT])==0);
%   disp('Most identified params')
%   disp(bayestopt_.name(iii))
  
  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% END OF MORRIS FOR DERIVATIVES  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
rattoma's avatar
rattoma committed
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
%   ifig = 0;
%   for j=1:size(options_.varobs,1)
%     if mod(j,6)==1
%       figure('name',['EET cross-correlations']);
%       ifig=ifig+1;
%       iplo=0;
%     end
%     iplo=iplo+1;
%     subplot(3,2,iplo)
%     iv = find(ir_cc==j);
%     iv = [iv; find(ic_cc==j)];
%     if ~isempty(iv)
%       if length(iv)>1
% %         boxplot(SAcc(iv,:),'whis',3,'symbol','r.');
%         myboxplot(SAcc(iv,:),[],'.',[],3)
%       else
%         plot(SAcc(iv,:),'r.');
%       end
%       set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT])
%       set(gca,'xlim',[0.5 npT+0.5])
%       ydum = get(gca,'ylim');
%       set(gca,'ylim',[0 ydum(2)])
%       for ip=1:npT,
%         text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
%       end
%       xlabel(' ')
%     end
%     title(options_.varobs(j,:),'interpreter','none')
%     if mod(j,6)==0 | j==size(options_.varobs,1)
%       saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_cc_',int2str(ifig)])
%       eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_cc_',int2str(ifig)]);
%       eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_cc_',int2str(ifig)]);
%       close(gcf),
%     end
%   end
rattoma's avatar
rattoma committed
388

rattoma's avatar
rattoma committed
389

390
%   if opt_gsa.load_ident_files==0,
rattoma's avatar
rattoma committed
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
%   SAMorris = [];
%   for i=1:size(ac,2),
%     [SAmeas, SAMorris(:,:,i)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], ac(:,i),nliv);
%   end
%   %end
%   SAac = squeeze(SAMorris(:,1,:))';
%   save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAac','ac','ir_ac','ic_ac','-append')
%   else
%     load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAac','ac','ir_ac','ic_ac')
%   end
%   figure,
% %   boxplot(SAac,'whis',10,'symbol','r.')
%   myboxplot(SAac,[],'.',[],10)
%   set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT])
%   set(gca,'xlim',[0.5 npT+0.5])
%   ydum = get(gca,'ylim');
%   set(gca,'ylim',[0 ydum(2)])
%   set(gca,'position',[0.13 0.2 0.775 0.7])
%   for ip=1:npT,
%     text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
%   end
%   xlabel(' ')
%   title('EET All auto-correlations')
%   saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_ac'])
%   eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_ac']);
%   eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_ac']);
%   close(gcf),

%   ifig = 0;
%   for j=1:size(options_.varobs,1)
%     if mod(j,6)==1
%       figure('name',['EET auto-correlations']);
%       ifig=ifig+1;
%       iplo=0;
%     end
%     iplo=iplo+1;
%     subplot(3,2,iplo)
%     iv = find(ir_ac==j);
%     if ~isempty(iv)
%       if length(iv)>1
% %         boxplot(SAac(iv,:),'whis',3,'symbol','r.');
%         myboxplot(SAac(iv,:),[],'.',[],3)
%       else
%         plot(SAac(iv,:),'r.');
%       end
%       set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT])
%       set(gca,'xlim',[0.5 npT+0.5])
%       ydum = get(gca,'ylim');
%       set(gca,'ylim',[0 ydum(2)])
%       for ip=1:npT,
%         text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
%       end
%       xlabel(' ')
%     end
%     title(options_.varobs(j,:),'interpreter','none')
%     if mod(j,6)==0 | j==size(options_.varobs,1)
%       saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_ac_',int2str(ifig)])
%       eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_ac_',int2str(ifig)]);
%       eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_ac_',int2str(ifig)]);
%       close(gcf),
%     end
%   end
rattoma's avatar
rattoma committed
453

454
%   if opt_gsa.load_ident_files==0,
rattoma's avatar
rattoma committed
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
%   js=0;
%   %for j=1:size(tadj,1),
%   SAMorris = [];
%   for i=1:size(tadj,2),
%     js=js+1;
%     [SAmeas, SAMorris(:,:,js)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], tadj(:,i),nliv);
%   end
%   %end
%   SAM = squeeze(SAMorris(nshock+1:end,1,:));
%   for j=1:js,
%     SAtadj(:,j)=SAM(:,j)./(max(SAM(:,j))+eps);
%   end
%   SAtadj = SAtadj';
%   save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAtadj','tadj','ir_tadj','ic_tadj','-append')
%   else
%     load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAtadj','tadj','ir_tadj','ic_tadj')
%   end
472
%   if opt_gsa.load_ident_files==0,
rattoma's avatar
rattoma committed
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
%   js=0;
%   SAMorris = [];
%   for i=1:size(iff,2),
%     js=js+1;
%     [SAmeas, SAMorriss(:,:,js)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], iff(:,i),nliv);
%   end
%   SAM = squeeze(SAMorriss(nshock+1:end,1,:));
%   for j=1:js,
%     SAIF(:,j)=SAM(:,j)./(max(SAM(:,j))+eps);
%   end
%   SAIF = SAIF';
%   save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAIF','iff','ir_if','ic_if','-append')
%   else
%     load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAIF','iff','ir_if','ic_if')
%   end
%   figure,
%   %bar(SAtadj),
% %   boxplot(SAtadj,'whis',10,'symbol','r.')
%   myboxplot(SAtadj,[],'.',[],10)
%   set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
%   set(gca,'xlim',[0.5 np+0.5])
%   set(gca,'ylim',[0 1])
%   set(gca,'position',[0.13 0.2 0.775 0.7])
%   for ip=1:np,
%     text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
%   end
%   xlabel(' ')
%   title('All half-life')
%   saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_tadj'])
%   eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_tadj']);
%   eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_tadj']);
%   close(gcf),
rattoma's avatar
rattoma committed
505

rattoma's avatar
rattoma committed
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
%   ifig = 0;
%   for j=1:size(options_.varobs,1)
%     if mod(j,6)==1
%       figure('name',['EET speed of adjustment observed variables']);
%       ifig=ifig+1;
%       iplo=0;
%     end
%     iplo=iplo+1;
%     subplot(3,2,iplo)
%     iv = find(ir_tadj==j);
%     if ~isempty(iv)
%       if length(iv)>1
% %         boxplot(SAtadj(iv,:),'whis',3,'symbol','r.');
%         myboxplot(SAtadj(iv,:),[],'.',[],3)
%       else
%         plot(SAtadj(iv,:),'r.');
%       end
%       set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
%       set(gca,'xlim',[0.5 np+0.5])
%       ydum = get(gca,'ylim');
%       set(gca,'ylim',[0 ydum(2)])
%       for ip=1:np,
%         text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
%       end
%       xlabel(' ')
%     end
%     title(options_.varobs(j,:),'interpreter','none')
%     if mod(j,6)==0 | j==size(options_.varobs,1)
%       saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_tadj_varobs_',int2str(ifig)])
%       eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_tadj_varobs_',int2str(ifig)]);
%       eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_tadj_varobs_',int2str(ifig)]);
%       close(gcf),
%     end
%   end
rattoma's avatar
rattoma committed
540

rattoma's avatar
rattoma committed
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
%   ifig = 0;
%   for j=1:M_.exo_nbr,
%     if mod(j,6)==1
%       figure('name',['EET speed of adjustment shocks']);
%       ifig=ifig+1;
%       iplo=0;
%     end
%     iplo=iplo+1;
%     subplot(3,2,iplo)
%     iv = find(ic_tadj==j);
%     if ~isempty(iv)
%       if length(iv)>1
% %         boxplot(SAtadj(iv,:),'whis',3,'symbol','r.');
%         myboxplot(SAtadj(iv,:),[],'.',[],3)
%       else
%         plot(SAtadj(iv,:),'r.');
%       end
%       set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
%       set(gca,'xlim',[0.5 np+0.5])
%       ydum = get(gca,'ylim');
%       set(gca,'ylim',[0 ydum(2)])
%       for ip=1:np,
%         text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
%       end
%       xlabel(' ')
%     end
%     title(M_.exo_names(j,:),'interpreter','none')
%     if mod(j,6)==0 | j==M_.exo_nbr,
%       saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_tadj_exo_',int2str(ifig)])
%       eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_tadj_exo_',int2str(ifig)]);
%       eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_tadj_exo_',int2str(ifig)]);
%       close(gcf),
%     end
%   end
rattoma's avatar
rattoma committed
575

rattoma's avatar
rattoma committed
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
%   figure,
%   %bar(SAIF),
% %   boxplot(SAIF,'whis',10,'symbol','r.')
%   myboxplot(SAIF,[],'.',[],10)
%   set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
%   set(gca,'xlim',[0.5 np+0.5])
%   set(gca,'ylim',[0 1])
%   set(gca,'position',[0.13 0.2 0.775 0.7])
%   for ip=1:np,
%     text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
%   end
%   xlabel(' ')
%   ylabel('Elementary Effects')
%   title('Steady state gains (impact factors)')
%   saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_gain'])
%   eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_gain']);
%   eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_gain']);
%   close(gcf),
rattoma's avatar
rattoma committed
594
  %figure, bar(SAIF'), title('All Gain Relationships')
rattoma's avatar
rattoma committed
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
%   ifig = 0;
%   for j=1:size(options_.varobs,1)
%     if mod(j,6)==1
%       figure('name',['EET steady state gain observed series']);
%       ifig=ifig+1;
%       iplo=0;
%     end
%     iplo=iplo+1;
%     subplot(3,2,iplo)
%     iv = find(ir_if==j);
%     if ~isempty(iv)
%       if length(iv)>1
% %         boxplot(SAIF(iv,:),'whis',10,'symbol','r.');
%         myboxplot(SAIF(iv,:),[],'.',[],10)
%       else
%         plot(SAIF(iv,:),'r.');
%       end
%       set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
%       set(gca,'xlim',[0.5 np+0.5])
%       ydum = get(gca,'ylim');
%       set(gca,'ylim',[0 ydum(2)])
%       for ip=1:np,
%         text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
%       end
%       xlabel(' ')
%     end
%     title(options_.varobs(j,:),'interpreter','none')
%     if mod(j,6)==0 | j==size(options_.varobs,1)
%       saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_gain_varobs_',int2str(ifig)])
%       eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_gain_varobs_',int2str(ifig)]);
%       eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_gain_varobs_',int2str(ifig)]);
%       close(gcf),
%     end
%   end
% 
%   ifig = 0;
%   for j=1:M_.exo_nbr,
%     if mod(j,6)==1
%       figure('name',['EET steady state gain shocks']);
%       ifig=ifig+1;
%       iplo=0;
%     end
%     iplo=iplo+1;
%     subplot(3,2,iplo)
%     iv = find(ic_if==j);
%     if ~isempty(iv)
%       if length(iv)>1
% %         boxplot(SAIF(iv,:),'whis',3,'symbol','r.');
%         myboxplot(SAIF(iv,:),[],'.',[],3)
%       else
%         plot(SAIF(iv,:),'r.');
%       end
%       set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
%       set(gca,'xlim',[0.5 np+0.5])
%       ydum = get(gca,'ylim');
%       set(gca,'ylim',[0 ydum(2)])
%       for ip=1:np,
%         text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
%       end
%       xlabel(' ')
%     end
%     title(M_.exo_names(j,:),'interpreter','none')
%     if mod(j,6)==0 | j==M_.exo_nbr,
%       saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_gain_exo_',int2str(ifig)])
%       eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_gain_exo_',int2str(ifig)]);
%       eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_gain_exo_',int2str(ifig)]);
%       close(gcf),
%     end
%   end
rattoma's avatar
rattoma committed
664
665


666
  if opt_gsa.load_ident_files==0,
rattoma's avatar
rattoma committed
667
668
669
670
671
  SAMorris = [];
  for j=1:j0,
    [SAmeas, SAMorris(:,:,j)] = Morris_Measure_Groups(npT, [lpmat0 lpmat], yt(:,j),nliv);
  end

rattoma's avatar
rattoma committed
672
673
%   SAM = squeeze(SAMorris(nshock+1:end,1,:));
  SAM = squeeze(SAMorris(1:end,1,:));
rattoma's avatar
rattoma committed
674
675
676
677
678
679
  for j=1:j0
    SAnorm(:,j)=SAM(:,j)./max(SAM(:,j));
    irex(j)=length(find(SAnorm(:,j)>0.01));
  end
  [dum, irel]=sort(irex);

rattoma's avatar
rattoma committed
680
681
%   SAMmu = squeeze(SAMorris(nshock+1:end,2,:));
  SAMmu = squeeze(SAMorris(1:end,2,:));
rattoma's avatar
rattoma committed
682
683
684
  for j=1:j0
    SAmunorm(:,j)=SAMmu(:,j)./max(SAM(:,j));  % normalised w.r.t. mu*
  end
rattoma's avatar
rattoma committed
685
686
%   SAMsig = squeeze(SAMorris(nshock+1:end,3,:));
  SAMsig = squeeze(SAMorris(1:end,3,:));
rattoma's avatar
rattoma committed
687
688
689
  for j=1:j0
    SAsignorm(:,j)=SAMsig(:,j)./max(SAMsig(:,j));
  end
rattoma's avatar
rattoma committed
690
    save([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAnorm','SAmunorm','SAsignorm','-append')
691
  else
rattoma's avatar
rattoma committed
692
    load([OutputDirectoryName,'/',fname_,'_morris_IDE'],'SAnorm','SAmunorm','SAsignorm')
693
  end
rattoma's avatar
rattoma committed
694
  figure, %bar(SAnorm(:,irel))
rattoma's avatar
rattoma committed
695
696
%   boxplot(SAnorm','whis',10,'symbol','r.')
  myboxplot(SAnorm',[],'.',[],10)
rattoma's avatar
rattoma committed
697
698
  set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT])
  set(gca,'xlim',[0.5 npT+0.5])
rattoma's avatar
rattoma committed
699
700
701
  set(gca,'ylim',[0 1])
  set(gca,'position',[0.13 0.2 0.775 0.7])
  xlabel(' ')
rattoma's avatar
rattoma committed
702
703
704
  for ip=1:npT,
%     text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
    text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
rattoma's avatar
rattoma committed
705
706
  end
  xlabel(' ')
rattoma's avatar
rattoma committed
707
  title('Elementary effects in the model')
rattoma's avatar
rattoma committed
708
709
710
  saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_par'])
  eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_par']);
  eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_par']);
rattoma's avatar
rattoma committed
711
712

  figure, %bar(SAmunorm(:,irel))
rattoma's avatar
rattoma committed
713
714
%   boxplot(SAmunorm','whis',10,'symbol','r.')
  myboxplot(SAmunorm',[],'.',[],10)
rattoma's avatar
rattoma committed
715
716
  set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT])
  set(gca,'xlim',[0.5 npT+0.5])
rattoma's avatar
rattoma committed
717
718
719
  set(gca,'ylim',[-1 1])
  set(gca,'position',[0.13 0.2 0.775 0.7])
  xlabel(' ')
rattoma's avatar
rattoma committed
720
721
  for ip=1:npT,
    text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
rattoma's avatar
rattoma committed
722
723
  end
  xlabel(' ')
rattoma's avatar
rattoma committed
724
  title('\mu in the model')
rattoma's avatar
rattoma committed
725
726
727
  saveas(gcf,[OutputDirectoryName,'/',fname_,'_morrismu_par'])
  eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morrismu_par']);
  eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morrismu_par']);
rattoma's avatar
rattoma committed
728
729
  close(gcf),
  
rattoma's avatar
rattoma committed
730
  figure, %bar(SAsignorm(:,irel))
rattoma's avatar
rattoma committed
731
732
%   boxplot(SAsignorm','whis',10,'symbol','r.')
  myboxplot(SAsignorm',[],'.',[],10)
rattoma's avatar
rattoma committed
733
734
  set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT])
  set(gca,'xlim',[0.5 npT+0.5])
rattoma's avatar
rattoma committed
735
736
737
  set(gca,'ylim',[0 1])
  set(gca,'position',[0.13 0.2 0.775 0.7])
  xlabel(' ')
rattoma's avatar
rattoma committed
738
739
  for ip=1:npT,
    text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
rattoma's avatar
rattoma committed
740
741
  end
  xlabel(' ')
rattoma's avatar
rattoma committed
742
  title('\sigma in the model')
rattoma's avatar
rattoma committed
743
744
745
  saveas(gcf,[OutputDirectoryName,'/',fname_,'_morrissig_par'])
  eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morrissig_par']);
  eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morrissig_par']);
rattoma's avatar
rattoma committed
746
  close(gcf),
rattoma's avatar
rattoma committed
747
748
749
750
751

  %     figure, bar(SAnorm(:,irel)')
  %     set(gca,'xtick',[1:j0])
  %     set(gca,'xlim',[0.5 j0+0.5])
  %     title('Elementary effects relationships')
rattoma's avatar
rattoma committed
752
753
754
  %     saveas(gcf,[OutputDirectoryName,'/',fname_,'_morris_redform'])
  %     eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_morris_redform']);
  %     eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_morris_redform']);
rattoma's avatar
rattoma committed
755

756
elseif opt_gsa.morris==3,
rattoma's avatar
rattoma committed
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
  np=estim_params_.np;
  na=(4*np+1)*opt_gsa.Nsam;
  for j=1:j0,
    [idex(j,:), yd(j,:)] = spop_ide(lpmat, yt(:,j), opt_gsa.Nsam, 5-1);
  end
  iok=find(~isnan(yt(1:opt_gsa.Nsam,1)));
  yr=NaN*ones(size(lpmat,1),j0);
  for j=1:j0,
    ys(j,:)=yd(j,:)./max(yd(j,:));
    [dum, is]=sort(yt(iok,j));
    yr(iok(is),j)=[1:length(iok)]'./length(iok);
    yr(istable(length(iok)+1:end),j) = interp1(yt(iok,j),yr(iok,j),yt(istable(length(iok)+1:end),j),'','extrap');
    ineg=find(yr(:,j)<0);
    if any(ineg),
      [dum, is]=sort(yr(ineg,j));
      yr(ineg(is),j)=-[length(ineg):-1:1]./length(iok);

    end
    [idex_r(j,:), yd_r(j,:)] = spop_ide(lpmat, yr(:,j), opt_gsa.Nsam, 5-1);
    ys_r(j,:)=yd_r(j,:)./max(yd_r(j,:));

  end,
  figure, bar((idex.*ys)./opt_gsa.Nsam), title('Relationships')
  figure, bar((idex.*ys)'./opt_gsa.Nsam), title('Parameters')
  figure, bar((idex_r.*ys_r)./opt_gsa.Nsam), title('Relationships rank')
  figure, bar((idex_r.*ys_r)'./opt_gsa.Nsam), title('Parameters rank')
  [v0,d0]=eig(corrcoef(yt(iok,:)));
  ee=diag(d0);
  ee=ee([end:-1:1])./j0;
  i0=length(find(ee>0.01));
  v0=v0(:,[end:-1:1]);
  for j=1:i0,
    [idex_pc(j,:), yd_pc(j,:)] = spop_ide(lpmat, yt*v0(:,j), opt_gsa.Nsam, 5-1);
  end
  for j=1:i0,
    ys_pc(j,:)=yd_pc(j,:)./max(yd_pc(j,:));
  end,
  figure, bar((idex_pc.*ys_pc)./opt_gsa.Nsam), title('Relationships PCA')
  figure, bar((idex_pc.*ys_pc)'./opt_gsa.Nsam), title('Parameters PCA')

  [vr,dr]=eig(corrcoef(yr(iok,:)));
  er=diag(dr);
  er=er([end:-1:1])./j0;
  ir0=length(find(er>0.01));
  vr=vr(:,[end:-1:1]);
  for j=1:ir0,
    [idex_pcr(j,:), yd_pcr(j,:)] = spop_ide(lpmat, yr*vr(:,j), opt_gsa.Nsam, 5-1);
  end
  for j=1:ir0,
    ys_pcr(j,:)=yd_pcr(j,:)./max(yd_pcr(j,:));
  end,
  figure, bar((idex_pcr.*ys_pcr)./opt_gsa.Nsam), title('Relationships rank PCA')
  figure, bar((idex_pcr.*ys_pcr)'./opt_gsa.Nsam), title('Parameters rank PCA')
810
  
811
elseif opt_gsa.morris==2,   % ISKREV staff
rattoma's avatar
rattoma committed
812
  return,
813
814
815

  
else,  % main effects analysis
rattoma's avatar
rattoma committed
816
  
rattoma's avatar
rattoma committed
817
818
819
820
821
822
823
  if itrans==0,
    fsuffix = '';
  elseif itrans==1,
    fsuffix = '_log';
  else
    fsuffix = '_rank';
  end
rattoma's avatar
rattoma committed
824
825
  
  imap=[1:npT];
rattoma's avatar
rattoma committed
826

rattoma's avatar
rattoma committed
827
  x0=[lpmat0(istable,:), lpmat(istable,:)];
rattoma's avatar
rattoma committed
828
829
830
  nrun=length(istable);
  nest=min(250,nrun);
  nfit=min(1000,nrun);
831
  
832
%   opt_gsa.load_ident_files=0;
833
  
834
%   if opt_gsa.load_ident_files==0,
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
%   try 
%     EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAvdec','vdec','ir_vdec','ic_vdec');
%   catch
%     EET=[];
%   end
%   SAvdec=zeros(size(vdec,2),npT);
% 
%   for j=1:size(vdec,2),
%     if itrans==0,
%       y0 = vdec(istable,j);
%     elseif itrans==1,
%       y0 = log_trans_(vdec(istable,j));
%     else
%       y0 = trank(vdec(istable,j));
%     end
%     if ~isempty(EET),
% %       imap=find(EET.SAvdec(j,:));
% %       [dum, isort]=sort(-EET.SAvdec(j,:));
%       imap=find(EET.SAvdec(j,:) >= (0.1.*max(EET.SAvdec(j,:))) );
%     end
%   gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ...
%       2, [],[],[],0,[OutputDirectoryName,'/map_vdec',fsuffix,int2str(j)], pnames);
%   if nfit>nest,
%     gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ...
%         -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_vdec',fsuffix,int2str(j)], pnames);
%   end
%     
%     SAvdec(j,imap)=gsa_(j).si;
%     imap_vdec{j}=imap;
%   end
%   save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_vdec','SAvdec','vdec','ir_vdec','ic_vdec','-append')
%   else
%   load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_vdec','SAvdec','vdec','ir_vdec','ic_vdec')
%   end
%   figure,
% %   boxplot(SAvdec,'whis',10,'symbol','r.')
%   myboxplot(SAvdec,[],'.',[],10)
%   set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
%   set(gca,'xlim',[0.5 npT+0.5])
%   ydum = get(gca,'ylim');
%   set(gca,'ylim',[0 ydum(2)])
%   set(gca,'position',[0.13 0.2 0.775 0.7])
%   for ip=1:npT,
%     text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
% %     text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
%   end
%   xlabel(' ')
%   title(['Main effects variance decomposition ',fsuffix],'interpreter','none')
%   saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_vdec',fsuffix])
%   eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix]);
%   eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix]);
%   close(gcf),
% 
%   ifig = 0;
%   for j=1:size(options_.varobs,1)
%     if mod(j,6)==1
%       figure('name',['Main effects observed variance decomposition ',fsuffix]);
%       ifig=ifig+1;
%       iplo=0;
%     end
%     iplo=iplo+1;
%     subplot(3,2,iplo)
%     iv = find(ir_vdec==j);
%     if ~isempty(iv)
%       if length(iv)>1
% %         boxplot(SAvdec(iv,:),'whis',10,'symbol','r.');
%         myboxplot(SAvdec(iv,:),[],'.',[],10)
%       else
%         plot(SAvdec(iv,:),'r.');
%       end
%       set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
%       set(gca,'xlim',[0.5 npT+0.5])
%       ydum = get(gca,'ylim');
%       set(gca,'ylim',[0 ydum(2)])
%       for ip=1:npT,
%         text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
% %         text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
%       end
%       xlabel(' ')
%     end
%     title(options_.varobs(j,:),'interpreter','none')
%     if mod(j,6)==0 | j==size(options_.varobs,1)
%       saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_vdec',fsuffix,'_varobs_',int2str(ifig)])
%       eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix,'_varobs_',int2str(ifig)]);
%       eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix,'_varobs_',int2str(ifig)]);
%       close(gcf),
%     end
%   end
% 
%   ifig = 0;
%   for j=1:M_.exo_nbr,
%     if mod(j,6)==1
%       figure('name',['Main effects shocks variance decomposition ',fsuffix]);
%       ifig=ifig+1;
%       iplo=0;
%     end
%     iplo=iplo+1;
%     subplot(3,2,iplo)
%     iv = find(ic_vdec==j);
%     if ~isempty(iv)
%       if length(iv)>1
% %         boxplot(SAvdec(iv,:),'whis',3,'symbol','r.');
%         myboxplot(SAvdec(iv,:),[],'.',[],10)
%       else
%         plot(SAvdec(iv,:),'r.');
%       end
%       set(gca,'xticklabel',' ','fontsize',3,'xtick',[1:np])
%       set(gca,'xlim',[0.5 npT+0.5])
%       ydum = get(gca,'ylim');
%       set(gca,'ylim',[0 ydum(2)])
%       for ip=1:npT,
%         text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
% %         text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
%       end
%       xlabel(' ')
%       set(gca,'fontsize',10)
%     end
%     title(M_.exo_names(j,:),'interpreter','none','fontsize',10)
%     if mod(j,6)==0 | j==M_.exo_nbr
%       saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_vdec',fsuffix,'_exo_',int2str(ifig)])
%       eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix,'_exo_',int2str(ifig)]);
%       eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_vdec',fsuffix,'_exo_',int2str(ifig)]);
%       close(gcf),
%     end
%   end
rattoma's avatar
rattoma committed
960

961
  if opt_gsa.load_ident_files==0,
rattoma's avatar
rattoma committed
962
  try 
rattoma's avatar
rattoma committed
963
    EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAcc','ir_cc','ic_cc');
rattoma's avatar
rattoma committed
964
965
966
  catch
    EET=[];
  end
rattoma's avatar
rattoma committed
967
  ccac = stand_([mss cc ac]);
968
969
970
  [pcc, dd] = eig(cov(ccac(istable,:)));
  [latent, isort] = sort(-diag(dd));
  latent = -latent;
971
972
  figure, bar(latent)
  title('Eigenvalues in PCA')
973
974
  pcc=pcc(:,isort);
  ccac = ccac*pcc;
rattoma's avatar
rattoma committed
975
976
%   npca = min(40, max(find(cumsum(latent)./length(latent)<0.99))+1);
  npca = max(find(cumsum(latent)./length(latent)<0.99))+1;
977
  siPCA = (EET.SAcc'*abs(pcc'))';
rattoma's avatar
rattoma committed
978
979
%   siPCA = siPCA./(max(siPCA')'*ones(1,npT)).*(latent*ones(1,npT));
  siPCA = siPCA./(max(siPCA')'*ones(1,npT));
980
981
982
983
%   siPCA = sum(siPCA,1);
%   siPCA = siPCA./max(siPCA);
  SAcc=zeros(size(ccac,2),npT);
  for j=1:npca, %size(ccac,2),
rattoma's avatar
rattoma committed
984
    if itrans==0,
985
      y0 = ccac(istable,j);
rattoma's avatar
rattoma committed
986
    elseif itrans==1,
987
      y0 = log_trans_(ccac(istable,j));
rattoma's avatar
rattoma committed
988
    else
989
      y0 = trank(ccac(istable,j));
rattoma's avatar
rattoma committed
990
    end
rattoma's avatar
rattoma committed
991
992
993
    if ~isempty(EET),
%       imap=find(EET.SAvdec(j,:));
%       [dum, isort]=sort(-EET.SAvdec(j,:));
994
995
      imap=find(siPCA(j,:) >= (0.1.*max(siPCA(j,:))) );
%       imap=find(EET.SAcc(j,:) >= (0.1.*max(EET.SAcc(j,:))) );
rattoma's avatar
rattoma committed
996
997
    end
  gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ...
rattoma's avatar
rattoma committed
998
      2, [],[],[],0,[OutputDirectoryName,'/map_cc',fsuffix,int2str(j)], pnames);
999
1000
1001
1002
%   if nfit>nest,
%     gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ...
%         -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_cc',fsuffix,int2str(j)], pnames);
%   end
rattoma's avatar
rattoma committed
1003
1004
    SAcc(j,imap)=gsa_(j).si;
    imap_cc{j}=imap;
rattoma's avatar
rattoma committed
1005
1006

  end
rattoma's avatar
rattoma committed
1007
  save([OutputDirectoryName,'/map_cc',fsuffix],'gsa_')
1008
  save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_cc','SAcc','ccac','-append')
1009
  else
1010
    load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_cc','SAcc','ccac')
1011
1012
    
  end
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
%   figure,
% %   boxplot(SAcc,'whis',10,'symbol','r.')
%   myboxplot(SAcc,[],'.',[],10)
%   set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
%   set(gca,'xlim',[0.5 npT+0.5])
%   ydum = get(gca,'ylim');
%   set(gca,'ylim',[0 ydum(2)])
%   set(gca,'position',[0.13 0.2 0.775 0.7])
%   for ip=1:npT,
%     text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
% %     text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
%   end
%   xlabel(' ')
%   ylabel(' ')
%   title(['Main effects moments''s PCA ',fsuffix],'interpreter','none')
%   saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_cc',fsuffix])
%   eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_moments',fsuffix]);
%   eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_moments',fsuffix]);
%   close(gcf),
rattoma's avatar
rattoma committed
1032

1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
%   ifig = 0;
%   for j=1:size(options_.varobs,1)
%     if mod(j,6)==1
%       figure('name',['Main effects cross-covariances ',fsuffix]);
%       ifig=ifig+1;
%       iplo=0;
%     end
%     iplo=iplo+1;
%     subplot(3,2,iplo)
%     iv = find(ir_cc==j);
%     iv = [iv; find(ic_cc==j)];
%     if ~isempty(iv)
%       if length(iv)>1
% %         boxplot(SAcc(iv,:),'whis',10,'symbol','r.');
%         myboxplot(SAcc(iv,:),[],'.',[],10)
%       else
%         plot(SAcc(iv,:),'r.');
%       end
%       set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
%       set(gca,'xlim',[0.5 npT+0.5])
%       ydum = get(gca,'ylim');
%       set(gca,'ylim',[0 ydum(2)])
%       for ip=1:npT,
%         text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
% %         text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
%       end
%       xlabel(' ')
%       set(gca,'fontsize',10)
%     end
%     title(options_.varobs(j,:),'interpreter','none','fontsize',10)
%     if mod(j,6)==0 | j==size(options_.varobs,1)
%       saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_cc',fsuffix,'_',int2str(ifig)])
%       eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_cc',fsuffix,'_',int2str(ifig)]);
%       eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_cc',fsuffix,'_',int2str(ifig)]);
%       close(gcf),
%     end
%   end
% 
1071
%   if opt_gsa.load_ident_files==0,
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
%   try 
%     EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAac','ir_ac','ic_ac');
%   catch
%     EET=[];
%   end
%   SAac=zeros(size(ac,2),npT);
%   for j=1:size(ac,2),
%     if itrans==0,
%       y0 = ac(istable,j);
%     elseif itrans==1,
%       y0 = log_trans_(ac(istable,j));
%     else
%       y0 = trank(ac(istable,j));
%     end
%     if ~isempty(EET),
%       imap=find(EET.SAac(j,:) >= (0.1.*max(EET.SAac(j,:))) );
%     end
% %     gsa_(j) = gsa_sdp_dyn( y0, lpmat(istable,:), ...
% %       gsa_flag, [],[],[],0,[OutputDirectoryName,'/map_ac',fsuffix,int2str(j)], pnames);
%   gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ...
%       2, [],[],[],0,[OutputDirectoryName,'/map_ac',fsuffix,int2str(j)], pnames);
%   if nfit>nest,
%     gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ...
%         -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_ac',fsuffix,int2str(j)], pnames);
%   end
%     SAac(j,imap)=gsa_(j).si;
%     imap_ac{j}=imap;
% 
%   end
%   save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_ac','SAac','ac','ir_ac','ic_ac','-append')
%   else
%   load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_ac','SAac','ac','ir_ac','ic_ac')
%   end
% 
%   figure,
% %   boxplot(SAac,'whis',10,'symbol','r.')
%   myboxplot(SAac,[],'.',[],10)
%   set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
%   set(gca,'xlim',[0.5 npT+0.5])
%   ydum = get(gca,'ylim');
%   set(gca,'ylim',[0 ydum(2)])
%   set(gca,'position',[0.13 0.2 0.775 0.7])
%   for ip=1:np,
%     text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
%   end
%   xlabel(' ')
%   title(['Main effects 1 lag auto-covariances ',fsuffix],'interpreter','none')
%   saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_ac',fsuffix])
%   eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_ac',fsuffix]);
%   eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_ac',fsuffix]);
1122
%   close(gcf),
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
% 
%   ifig = 0;
%   for j=1:size(options_.varobs,1)
%     if mod(j,6)==1
%       figure('name',['Main effects auto-covariances ',fsuffix]);
%       ifig=ifig+1;
%       iplo = 0;
%     end
%     iplo=iplo+1;
%     subplot(3,2,iplo)
%     iv = find(ir_ac==j);
%     %iv = [iv; find(ic_ac==j)];
%     if ~isempty(iv)
%       if length(iv)>1
% %         boxplot(SAac(iv,:),'whis',10,'symbol','r.');
%         myboxplot(SAac(iv,:),[],'.',[],10)
%       else
%         plot(SAac(iv,:),'r.');
%       end
%       set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
%       set(gca,'xlim',[0.5 npT+0.5])
%       ydum = get(gca,'ylim');
%       set(gca,'ylim',[0 ydum(2)])
%       for ip=1:npT,
%         text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
% %         text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
%       end
%       xlabel(' ')
%       set(gca,'fontsize',10)
%     end
%     title(options_.varobs(j,:),'interpreter','none','fontsize',10)
%     if mod(j,6)==0 | j==size(options_.varobs,1)
%       saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_ac',fsuffix,'_',int2str(ifig)])
%       eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_ac',fsuffix,'_',int2str(ifig)]);
%       eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_ac',fsuffix,'_',int2str(ifig)]);
%       close(gcf),
%     end
%   end
1161
  
1162
1163
%   x0=x0(:,nshock+1:end);
  imap=[1:npT];
rattoma's avatar
rattoma committed
1164

1165
%   if opt_gsa.load_ident_files==0,
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
%   try 
%     EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAtadj','ir_tadj','ic_tadj');
%     ny=size(EET.SAtadj,1);
%   catch
%     EET=[];
%   end
%   SAtadj=zeros(size(tadj,2),np);
%   for j=1:size(tadj,2),
%     if itrans==0,
%       y0 = tadj(istable,j);
%     elseif itrans==1,
%       y0 = log_trans_(tadj(istable,j));
%     else
%       y0 = trank(tadj(istable,j));
%     end
%     if ~isempty(EET),
%       if size(tadj,2)~=ny,
%         jj=find(EET.ir_tadj==ir_tadj(j));
%         jj=jj(find(EET.ic_tadj(jj)==ic_tadj(j)));
%         if ~isempty(jj),
%           imap=find(EET.SAtadj(jj,:) >= (0.1.*max(EET.SAtadj(jj,:))) );
%         else
%           imap=[1:np];
%         end
%       else
%         imap=find(EET.SAtadj(j,:) >= (0.1.*max(EET.SAtadj(j,:))) );
%       end
%     end
% %     gsa_(j) = gsa_sdp_dyn( y0, lpmat(istable,:), ...
% %       gsa_flag, [],[],[],0,[OutputDirectoryName,'/map_tadj',fsuffix,int2str(j)], pnames);
%   gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ...
%       2, [],[],[],0,[OutputDirectoryName,'/map_tadj',fsuffix,int2str(j)], pnames);
%   if nfit>nest,
%     gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ...
%         -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_tadj',fsuffix,int2str(j)], pnames);
%   end
%     SAtadj(j,imap)=gsa_(j).si;
%     imap_tadj{j}=imap;
% 
%   end
%   save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_tadj','SAtadj','tadj','ir_tadj','ic_tadj','-append')
%   else
%   load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_tadj','SAtadj','tadj','ir_tadj','ic_tadj')
%   end
% 
%   figure,
% %   boxplot(SAtadj,'whis',10,'symbol','r.')
%   myboxplot(SAtadj,[],'.',[],10)
%   set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
%   set(gca,'xlim',[0.5 np+0.5])
%   ydum = get(gca,'ylim');
%   set(gca,'ylim',[0 ydum(2)])
%   set(gca,'position',[0.13 0.2 0.775 0.7])
%   for ip=1:np,
%     text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
%   end
%   xlabel(' ')
%   title(['Main effects speed of adjustment ',fsuffix],'interpreter','none')
%   saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_tadj',fsuffix])
%   eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix]);
%   eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix]);
1227
%   close(gcf),
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
% 
%   ifig = 0;
%   for j=1:size(options_.varobs,1)
%     if mod(j,6)==1
%       figure('name',['Main effects observed speed adjustment ',fsuffix]);
%       ifig=ifig+1;
%       iplo = 0;
%     end
%     iplo=iplo+1;
%     subplot(3,2,iplo)
%     iv = find(ir_tadj==j);
%     if ~isempty(iv)
%       if length(iv)>1
% %         boxplot(SAtadj(iv,:),'whis',3,'symbol','r.');
%         myboxplot(SAtadj(iv,:),[],'.',[],10)
%       else
%         plot(SAtadj(iv,:),'r.');
%       end
%       set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
%       set(gca,'xlim',[0.5 np+0.5])
%       ydum = get(gca,'ylim');
%       set(gca,'ylim',[0 ydum(2)])
%       for ip=1:np,
%         text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
%       end
%       xlabel(' ')
%     end
%     title(options_.varobs(j,:),'interpreter','none')
%     if mod(j,6)==0 | j==size(options_.varobs,1)
%       saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_tadj',fsuffix,'_varobs_',int2str(ifig)])
%       eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix,'_varobs_',int2str(ifig)]);
%       eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix,'_varobs_',int2str(ifig)]);
%       close(gcf),
%     end
%   end
% 
%   ifig = 0;
%   for j=1:M_.exo_nbr,
%     if mod(j,6)==1
%       figure('name',['Main effects shocks speed of adjustment ',fsuffix]);
%       ifig=ifig+1;
%       iplo=0;
%     end
%     iplo=iplo+1;
%     subplot(3,2,iplo)
%     iv = find(ic_tadj==j);
%     if ~isempty(iv)
%       if length(iv)>1
% %         boxplot(SAtadj(iv,:),'whis',3,'symbol','r.');
%         myboxplot(SAtadj(iv,:),[],'.',[],10)
%       else
%         plot(SAtadj(iv,:),'r.');
%       end
%       set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
%       set(gca,'xlim',[0.5 np+0.5])
%       ydum = get(gca,'ylim');
%       set(gca,'ylim',[0 ydum(2)])
%       for ip=1:np,
%         text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
%       end
%       xlabel(' ')
%     end
%     title(M_.exo_names(j,:),'interpreter','none')
%     if mod(j,6)==0 | j==M_.exo_nbr,
%       saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_tadj',fsuffix,'_exo_',int2str(ifig)])
%       eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix,'_exo_',int2str(ifig)]);
%       eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_tadj',fsuffix,'_exo_',int2str(ifig)]);
%       close(gcf),
%     end
%   end
% 
% 
1300
%   if opt_gsa.load_ident_files==0,
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
%   try 
%     EET=load([OutputDirectoryName,'/SCREEN/',fname_,'_morris_IDE'],'SAIF','ir_if','ic_if');
%   catch
%     EET=[];
%   end
%   SAif=zeros(size(iff,2),np);
%   for j=1:size(iff,2),
%     if itrans==0,
%       y0 = iff(istable,j);
%     elseif itrans==1,
%       y0 = log_trans_(iff(istable,j));
%     else
%       y0 = trank(iff(istable,j));
%     end
%     if ~isempty(EET),
%       imap=find(EET.SAIF(j,:) >= (0.1.*max(EET.SAIF(j,:))) );
%     end
% %     gsa_(j) = gsa_sdp_dyn( y0, lpmat(istable,:), ...
% %       gsa_flag, [],[],[],0,[OutputDirectoryName,'/map_if',fsuffix,int2str(j)], pnames);
%   gsa_(j) = gsa_sdp(y0(1:nest), x0(1:nest,imap), ...
%       2, [],[],[],0,[OutputDirectoryName,'/map_if',fsuffix,int2str(j)], pnames);
%   if nfit>nest,
%     gsa_(j) = gsa_sdp(y0(1:nfit), x0(1:nfit,imap), ...
%         -2, gsa_(j).nvr*nest^3/nfit^3,[],[],0,[OutputDirectoryName,'/map_if',fsuffix,int2str(j)], pnames);
%   end
%     SAif(j,imap)=gsa_(j).si;
%     imap_if{j}=imap;
%     
%   end
%   save([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_if','SAif','iff','ir_if','ic_if','-append')
%   else
%   load([OutputDirectoryName,'/',fname_,'_main_eff'],'imap_if','SAif','iff','ir_if','ic_if')
%   end
% 
%   figure,
% %   boxplot(SAif,'whis',10,'symbol','r.')
%   myboxplot(SAif,[],'.',[],10)
%   set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
%   set(gca,'xlim',[0.5 np+0.5])
%   ydum = get(gca,'ylim');
%   set(gca,'ylim',[0 ydum(2)])
%   set(gca,'position',[0.13 0.2 0.775 0.7])
%   for ip=1:np,
%     text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
%   end
%   xlabel(' ')
%   title(['Main effects impact factors ',fsuffix],'interpreter','none')
%   saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_if',fsuffix])
%   eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_if',fsuffix]);
%   eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_if',fsuffix]);
%   close(gcf),
% 
%   ifig = 0;
%   for j=1:size(options_.varobs,1)
%     if mod(j,6)==1
%       figure('name',['Main effects observed impact factors ',fsuffix]);
%       ifig=ifig+1;
%       iplo = 0;
%     end
%     iplo=iplo+1;
%     subplot(3,2,iplo)
%     iv = find(ir_if==j);
%     if ~isempty(iv)
%       if length(iv)>1
% %         boxplot(SAif(iv,:),'whis',3,'symbol','r.');
%         myboxplot(SAif(iv,:),[],'.',[],10)
%       else
%         plot(SAif(iv,:),'r.');
%       end
%       set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
%       set(gca,'xlim',[0.5 np+0.5])
%       ydum = get(gca,'ylim');
%       set(gca,'ylim',[0 ydum(2)])
%       for ip=1:np,
%         text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
%       end
%       xlabel(' ')
%     end
%     title(options_.varobs(j,:),'interpreter','none')
%     if mod(j,6)==0 | j==size(options_.varobs,1)
%       saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_if',fsuffix,'_varobs_',int2str(ifig)])
%       eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_if',fsuffix,'_varobs_',int2str(ifig)]);
%       eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_if',fsuffix,'_varobs_',int2str(ifig)]);
%       close(gcf),
%     end
%   end
% 
%   ifig = 0;
%   for j=1:M_.exo_nbr,
%     if mod(j,6)==1
%       figure('name',['Main effects shocks impact factors ',fsuffix]);
%       ifig=ifig+1;
%       iplo=0;
%     end
%     iplo=iplo+1;
%     subplot(3,2,iplo)
%     iv = find(ic_if==j);
%     if ~isempty(iv)
%       if length(iv)>1
% %         boxplot(SAif(iv,:),'whis',3,'symbol','r.');
%         myboxplot(SAif(iv,:),[],'.',[],10)
%       else
%         plot(SAif(iv,:),'r.');
%       end
%       set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
%       set(gca,'xlim',[0.5 np+0.5])
%       ydum = get(gca,'ylim');
%       set(gca,'ylim',[0 ydum(2)])
%       for ip=1:np,
%         text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
%       end
%       xlabel(' ')
%     end
%     title(M_.exo_names(j,:),'interpreter','none')
%     if mod(j,6)==0 | j==M_.exo_nbr
%       saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_if',fsuffix,'_exo_',int2str(ifig)])
%       eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_if',fsuffix,'_exo_',int2str(ifig)]);
%       eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_if',fsuffix,'_exo_',int2str(ifig)]);
%       close(gcf),
%     end
%   end
%   SAmom = [SAvdec' SAcc' SAac']';
%   SAdyn = [SAtadj' SAif']';
%   SAall = [SAmom(:,nshock+1:end)' SAdyn']';
%   
%   figure,
%   %   boxplot(SAtadj,'whis',10,'symbol','r.')
%   myboxplot(SAmom,[],'.',[],10)
%   set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT])
%   set(gca,'xlim',[0.5 npT+0.5])
%   ydum = get(gca,'ylim');
%   set(gca,'ylim',[0 ydum(2)])
%   set(gca,'position',[0.13 0.2 0.775 0.7])
%   for ip=1:npT,
%     %     text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
%     text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
%   end
%   xlabel(' ')
%   title(['Main effects theoretical moments ',fsuffix],'interpreter','none')
%   saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_moments',fsuffix])
%   eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_moments',fsuffix]);
%   eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_moments',fsuffix]);
% %   close(gcf),
%   
%   figure,
%   %   boxplot(SAtadj,'whis',10,'symbol','r.')
%   myboxplot(SAdyn,[],'.',[],10)
%   set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
%   set(gca,'xlim',[0.5 np+0.5])
%   ydum = get(gca,'ylim');
%   set(gca,'ylim',[0 ydum(2)])
%   set(gca,'position',[0.13 0.2 0.775 0.7])
%   for ip=1:np,
%     text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
% %     text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
%   end
%   xlabel(' ')
%   title(['Main effects short-long term dynamics ',fsuffix],'interpreter','none')
%   saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_dynamics',fsuffix])
%   eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_dynamics',fsuffix]);
%   eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_dynamics',fsuffix]);
% %   close(gcf),
% 
%   figure,
%   %   boxplot(SAtadj,'whis',10,'symbol','r.')
%   myboxplot(SAall,[],'.',[],10)
%   set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:np])
%   set(gca,'xlim',[0.5 np+0.5])
%   ydum = get(gca,'ylim');
%   set(gca,'ylim',[0 ydum(2)])
%   set(gca,'position',[0.13 0.2 0.775 0.7])
%   for ip=1:np,
%     text(ip,-0.02,deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
% %     text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
%   end
%   xlabel(' ')
%   title(['Main effects all ',fsuffix],'interpreter','none')
%   saveas(gcf,[OutputDirectoryName,'/',fname_,'_map_ALL',fsuffix])
%   eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_map_ALL',fsuffix]);
%   eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_map_ALL',fsuffix]);
% %   close(gcf),
1482

1483
1484
1485
1486
1487
1488
1489
1490
1491
%   for j=1:size(SAall,1),
%     SAallN(j,:)=SAall(j,:)./max(SAall(j,:));
%   end
%   SAmean=mean(SAallN);
%   for j=1:size(SAmom,1),
%     SAmomN(j,:)=SAmom(j,1:nshock)./max(SAmom(j,1:nshock));
%   end
%   SAmomN(find(isnan(SAmomN)))=0;
%   SAmeanexo=mean(SAmomN(:,1:nshock));
1492

rattoma's avatar
rattoma committed
1493
1494
%   figure, bar(latent'*SAcc),
  figure, bar(sum(SAcc)),
1495
1496
  set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:npT])
  set(gca,'xlim',[0.5 npT+0.5])
1497
1498
1499
  ydum = get(gca,'ylim');
  set(gca,'ylim',[0 ydum(2)])
  set(gca,'position',[0.13 0.2 0.775 0.7])
1500
1501
  for ip=1:npT,
    text(ip,-0.02*(ydum(2)),bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
1502
1503
1504
    %     text(ip,-0.02,bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
  end
  xlabel(' ')
1505
  title(['Identifiability indices in the ',fsuffix,' moments.'],'interpreter','none')
rattoma's avatar
rattoma committed
1506
1507
1508
  saveas(gcf,[OutputDirectoryName,'/',fname_,'_ident_ALL',fsuffix])
  eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_ident_ALL',fsuffix]);
  eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_ident_ALL',fsuffix]);
1509

1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
%   figure, bar(SAmeanexo),
%   set(gca,'xticklabel',' ','fontsize',10,'xtick',[1:nshock])
%   set(gca,'xlim',[0.5 nshock+0.5])
%   ydum = get(gca,'ylim');
%   set(gca,'ylim',[0 ydum(2)])
%   set(gca,'position',[0.13 0.2 0.775 0.7])
%   for ip=1:nshock,
%     %     text(ip,-0.02*(ydum(2)),deblank(pnames(ip,:)),'rotation',90,'HorizontalAlignment','right','interpreter','none')
%     text(ip,-0.02*(ydum(2)),bayestopt_.name{ip},'rotation',90,'HorizontalAlignment','right','interpreter','none')
%   end
%   xlabel(' ')
%   title(['Identifiability indices for shocks',fsuffix],'interpreter','none')
%   saveas(gcf,[OutputDirectoryName,'/',fname_,'_ident_SHOCKS',fsuffix])
%   eval(['print -depsc2 ' OutputDirectoryName '/' fname_ '_ident_SHOCKS',fsuffix]);
%   eval(['print -dpdf ' OutputDirectoryName '/' fname_ '_ident_SHOCKS',fsuffix]);
rattoma's avatar
rattoma committed
1525
end
rattoma's avatar
rattoma committed
1526
1527

return