stab_map_.m 21.6 KB
Newer Older
rattoma's avatar
rattoma committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function x0 = stab_map_(OutputDirectoryName)
%
% function x0 = stab_map_(OutputDirectoryName)
%
% Mapping of stability regions in the prior ranges applying
% Monte Carlo filtering techniques.
%
% INPUTS (from opt_gsa structure)
% Nsam = MC sample size
% fload = 0 to run new MC; 1 to load prevoiusly generated analysis
% alpha2 =  significance level for bivariate sensitivity analysis
% [abs(corrcoef) > alpha2]
% prepSA = 1: save transition matrices for mapping reduced form
%        = 0: no transition matrix saved (default)
% pprior = 1: sample from prior ranges (default): sample saved in
%            _prior.mat   file
%        = 0: sample from posterior ranges: sample saved in
%            _mc.mat file
19
% OUTPUT:
rattoma's avatar
rattoma committed
20
21
22
23
24
% x0: one parameter vector for which the model is stable.
%
% GRAPHS
% 1) Pdf's of marginal distributions under the stability (dotted
%     lines) and unstability (solid lines) regions
25
26
% 2) Cumulative distributions of:
%   - stable subset (dotted lines)
rattoma's avatar
rattoma committed
27
%   - unacceptable subset (solid lines)
28
% 3) Bivariate plots of significant correlation patterns
rattoma's avatar
rattoma committed
29
30
%  ( abs(corrcoef) > alpha2) under the stable and unacceptable subsets
%
31
% USES lptauSEQ,
rattoma's avatar
rattoma committed
32
33
34
35
36
37
38
%      stab_map_1, stab_map_2
%
% Part of the Sensitivity Analysis Toolbox for DYNARE
%
% Written by Marco Ratto, 2006
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
39
% marco.ratto@jrc.it
rattoma's avatar
rattoma committed
40
%
41
42
% Disclaimer: This software is not subject to copyright protection and is in the public domain.
% It is an experimental system. The Joint Research Centre of European Commission
rattoma's avatar
rattoma committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
% assumes no responsibility whatsoever for its use by other parties
% and makes no guarantees, expressed or implied, about its quality, reliability, or any other
% characteristic. We would appreciate acknowledgement if the software is used.
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
%

%global bayestopt_ estim_params_ dr_ options_ ys_ fname_
global bayestopt_ estim_params_ options_ oo_ M_

opt_gsa=options_.opt_gsa;

Nsam   = opt_gsa.Nsam;
fload  = opt_gsa.load_stab;
57
58
ksstat = opt_gsa.ksstat;
alpha2 = opt_gsa.alpha2_stab;
Marco Ratto's avatar
Marco Ratto committed
59
60
pvalue_ks = opt_gsa.pvalue_ks;
pvalue_corr = opt_gsa.pvalue_corr;
61
62
prepSA = (opt_gsa.redform | opt_gsa.identification);
pprior = opt_gsa.pprior;
63
neighborhood_width = opt_gsa.neighborhood_width;
rattoma's avatar
rattoma committed
64
ilptau = opt_gsa.ilptau;
65
nliv   = opt_gsa.morris_nliv;
rattoma's avatar
rattoma committed
66
67
68
69
ntra   = opt_gsa.morris_ntra;

dr_ = oo_.dr;
%if isfield(dr_,'ghx'),
70
71
72
73
ys_ = oo_.dr.ys;
nspred = dr_.nspred; %size(dr_.ghx,2);
nboth = dr_.nboth;
nfwrd = dr_.nfwrd;
rattoma's avatar
rattoma committed
74
75
76
77
78
79
80
81
82
83
%end
fname_ = M_.fname;

np = estim_params_.np;
nshock = estim_params_.nvx;
nshock = nshock + estim_params_.nvn;
nshock = nshock + estim_params_.ncx;
nshock = nshock + estim_params_.ncn;
lpmat0=[];

84
85
86
87
88
pshape = bayestopt_.pshape(nshock+1:end);
p1 = bayestopt_.p1(nshock+1:end);
p2 = bayestopt_.p2(nshock+1:end);
p3 = bayestopt_.p3(nshock+1:end);
p4 = bayestopt_.p4(nshock+1:end);
rattoma's avatar
rattoma committed
89
90

if nargin==0,
91
    OutputDirectoryName='';
rattoma's avatar
rattoma committed
92
93
94
end

opt=options_;
95
96
97
98
99
options_.periods=0;
options_.nomoments=1;
options_.irf=0;
options_.noprint=1;
options_.simul=0;
rattoma's avatar
rattoma committed
100
if fload==0,
101
102
103
    %   if prepSA
    %     T=zeros(size(dr_.ghx,1),size(dr_.ghx,2)+size(dr_.ghu,2),Nsam/2);
    %   end
104

105
106
107
108
    if isfield(dr_,'ghx'),
        egg=zeros(length(dr_.eigval),Nsam);
    end
    yys=zeros(length(dr_.ys),Nsam);
109

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
    if opt_gsa.morris == 1
        [lpmat, OutFact] = Sampling_Function_2(nliv, np+nshock, ntra, ones(np+nshock, 1), zeros(np+nshock,1), []);
        lpmat = lpmat.*(nliv-1)/nliv+1/nliv/2;
        Nsam=size(lpmat,1);
        lpmat0 = lpmat(:,1:nshock);
        lpmat = lpmat(:,nshock+1:end);
    elseif opt_gsa.morris==3,
        lpmat = prep_ide(Nsam,np,5);
        Nsam=size(lpmat,1);
    else
        if np<52 & ilptau>0,
            [lpmat] = lptauSEQ(Nsam,np); % lptau
            if np>30 | ilptau==2, % scrambled lptau
                for j=1:np,
                    lpmat(:,j)=lpmat(randperm(Nsam),j);
                end
            end
        else %ilptau==0
            %[lpmat] = rand(Nsam,np);
            for j=1:np,
                lpmat(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube
            end
132

rattoma's avatar
rattoma committed
133
134
        end
    end
135
    %   try
rattoma's avatar
rattoma committed
136
    dummy=prior_draw_gsa(1);
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
    %   catch
    %     if pprior,
    %       if opt_gsa.prior_range==0;
    %         error('Some unknown prior is specified or ML estimation,: use prior_range=1 option!!');
    %       end
    %     end
    %
    %   end
    if pprior,
        for j=1:nshock,
            if opt_gsa.morris~=1,
                lpmat0(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube
            end
            if opt_gsa.prior_range
                lpmat0(:,j)=lpmat0(:,j).*(bayestopt_.ub(j)-bayestopt_.lb(j))+bayestopt_.lb(j);
            end
        end
        if opt_gsa.prior_range
            %       if opt_gsa.identification,
            %         deltx=min(0.001, 1/Nsam/2);
            %         for j=1:np,
            %           xdelt(:,:,j)=prior_draw_gsa(0,[lpmat0 lpmat]+deltx);
            %         end
            %       end
            for j=1:np,
                lpmat(:,j)=lpmat(:,j).*(bayestopt_.ub(j+nshock)-bayestopt_.lb(j+nshock))+bayestopt_.lb(j+nshock);
            end
        else
            xx=prior_draw_gsa(0,[lpmat0 lpmat]);
            %       if opt_gsa.identification,
            %         deltx=min(0.001, 1/Nsam/2);
            %         ldum=[lpmat0 lpmat];
            %         ldum = prior_draw_gsa(0,ldum+deltx);
            %         for j=1:nshock+np,
            %           xdelt(:,:,j)=xx;
            %           xdelt(:,j,j)=ldum(:,j);
            %         end
            %         clear ldum
            %       end
            lpmat0=xx(:,1:nshock);
            lpmat=xx(:,nshock+1:end);
            clear xx;
        end
rattoma's avatar
rattoma committed
180
    else
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
        %         for j=1:nshock,
        %             xparam1(j) = oo_.posterior_mode.shocks_std.(bayestopt_.name{j});
        %             sd(j) = oo_.posterior_std.shocks_std.(bayestopt_.name{j});
        %             lpmat0(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube
        %             lb = max(bayestopt_.lb(j), xparam1(j)-2*sd(j));
        %             ub1=xparam1(j)+(xparam1(j) - lb); % define symmetric range around the mode!
        %             ub = min(bayestopt_.ub(j),ub1);
        %             if ub<ub1,
        %                 lb=xparam1(j)-(ub-xparam1(j)); % define symmetric range around the mode!
        %             end
        %             lpmat0(:,j) = lpmat0(:,j).*(ub-lb)+lb;
        %         end
        %         %
        %         for j=1:np,
        %             xparam1(j+nshock) = oo_.posterior_mode.parameters.(bayestopt_.name{j+nshock});
        %             sd(j+nshock) = oo_.posterior_std.parameters.(bayestopt_.name{j+nshock});
        %             lb = max(bayestopt_.lb(j+nshock),xparam1(j+nshock)-2*sd(j+nshock));
        %             ub1=xparam1(j+nshock)+(xparam1(j+nshock) - lb); % define symmetric range around the mode!
        %             ub = min(bayestopt_.ub(j+nshock),ub1);
        %             if ub<ub1,
        %                 lb=xparam1(j+nshock)-(ub-xparam1(j+nshock)); % define symmetric range around the mode!
        %             end
        %             %ub = min(bayestopt_.ub(j+nshock),xparam1(j+nshock)+2*sd(j+nshock));
        %             if np>30 & np<52
        %                 lpmat(:,j) = lpmat(randperm(Nsam),j).*(ub-lb)+lb;
        %             else
        %                 lpmat(:,j) = lpmat(:,j).*(ub-lb)+lb;
        %             end
        %         end
        %load([fname_,'_mode'])
        eval(['load ' options_.mode_file ';']');
212
213
214
215
216
217
218
219
220
221
222
        if neighborhood_width>0,
            for j=1:nshock,
                lpmat0(:,j) = randperm(Nsam)'./(Nsam+1); %latin hypercube
                ub=min([bayestopt_.ub(j) xparam1(j)*(1+neighborhood_width)]);
                lb=max([bayestopt_.lb(j) xparam1(j)*(1-neighborhood_width)]);
                lpmat0(:,j)=lpmat0(:,j).*(ub-lb)+lb;
            end
            for j=1:np,
                ub=min([bayestopt_.ub(j+nshock) xparam1(j+nshock)*(1+neighborhood_width)]);
                lb=max([bayestopt_.lb(j+nshock) xparam1(j+nshock)*(1-neighborhood_width)]);
                lpmat(:,j)=lpmat(:,j).*(ub-lb)+lb;
223
            end
224
225
226
227
228
229
230
231
232
233
234
235
236
        else
            d = chol(inv(hh));
            lp=randn(Nsam*2,nshock+np)*d+kron(ones(Nsam*2,1),xparam1');
            for j=1:Nsam*2,
                lnprior(j) = any(lp(j,:)'<=bayestopt_.lb | lp(j,:)'>=bayestopt_.ub);
            end
            ireal=[1:2*Nsam];
            ireal=ireal(find(lnprior==0));
            lp=lp(ireal,:);
            Nsam=min(Nsam, length(ireal));
            lpmat0=lp(1:Nsam,1:nshock);
            lpmat=lp(1:Nsam,nshock+1:end);
            clear lp lnprior ireal;
237
238
239
240
241
242
243
244
245
246
247
248
249
        end
    end
    %
    h = waitbar(0,'Please wait...');
    istable=[1:Nsam];
    jstab=0;
    iunstable=[1:Nsam];
    iindeterm=zeros(1,Nsam);
    iwrong=zeros(1,Nsam);
    for j=1:Nsam,
        M_.params(estim_params_.param_vals(:,1)) = lpmat(j,:)';
        %try stoch_simul([]);
        try
250
            [Tt,Rr,SteadyState,infox{j},M_,options_,oo_] = dynare_resolve(M_,options_,oo_);
251
252
253
254
255
256
            if infox{j}(1)==0 && ~exist('T'),
                dr_=oo_.dr;
                T=zeros(size(dr_.ghx,1),size(dr_.ghx,2)+size(dr_.ghu,2),Nsam);
                egg=zeros(length(dr_.eigval),Nsam);
            end
            if infox{j},
Marco Ratto's avatar
Marco Ratto committed
257
%                 disp('no solution'),
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
                if isfield(oo_.dr,'ghx'),
                    oo_.dr=rmfield(oo_.dr,'ghx');
                end
            end
        catch
            if isfield(oo_.dr,'eigval'),
                oo_.dr=rmfield(oo_.dr,'eigval');
            end
            if isfield(oo_.dr,'ghx'),
                oo_.dr=rmfield(oo_.dr,'ghx');
            end
            disp('No solution could be found'),
        end
        dr_ = oo_.dr;
        if isfield(dr_,'ghx'),
            egg(:,j) = sort(dr_.eigval);
            iunstable(j)=0;
            if prepSA
                jstab=jstab+1;
                T(:,:,jstab) = [dr_.ghx dr_.ghu];
                %         [A,B] = ghx2transition(squeeze(T(:,:,jstab)), ...
                %           bayestopt_.restrict_var_list, ...
                %           bayestopt_.restrict_columns, ...
                %           bayestopt_.restrict_aux);
            end
            if ~exist('nspred'),
                nspred = dr_.nspred; %size(dr_.ghx,2);
                nboth = dr_.nboth;
                nfwrd = dr_.nfwrd;
            end
        else
            istable(j)=0;
            if isfield(dr_,'eigval')
                egg(:,j) = sort(dr_.eigval);
                if exist('nspred')
                    if any(isnan(egg(1:nspred,j)))
                        iwrong(j)=j;
                    else
                        if (nboth | nfwrd) & abs(egg(nspred+1,j))<=options_.qz_criterium,
                            iindeterm(j)=j;
                        end
                    end
                end
            else
                if exist('egg'),
                    egg(:,j)=ones(size(egg,1),1).*NaN;
                end
                iwrong(j)=j;
            end
        end
        ys_=real(dr_.ys);
        yys(:,j) = ys_;
        ys_=yys(:,1);
        waitbar(j/Nsam,h,['MC iteration ',int2str(j),'/',int2str(Nsam)])
rattoma's avatar
rattoma committed
312
    end
313
314
315
316
317
318
319
320
    close(h)
    if prepSA,
        T=T(:,:,1:jstab);
    end
    istable=istable(find(istable));  % stable params
    iunstable=iunstable(find(iunstable));   % unstable params
    iindeterm=iindeterm(find(iindeterm));  % indeterminacy
    iwrong=iwrong(find(iwrong));  % dynare could not find solution
321

322
323
324
325
326
327
328
329
330
331
332
    %     % map stable samples
    %     istable=[1:Nsam];
    %     for j=1:Nsam,
    %         if any(isnan(egg(1:nspred,j)))
    %             istable(j)=0;
    %         else
    %             if abs(egg(nspred,j))>=options_.qz_criterium; %(1-(options_.qz_criterium-1)); %1-1.e-5;
    %                 istable(j)=0;
    %                 %elseif (dr_.nboth | dr_.nfwrd) & abs(egg(nspred+1,j))<=options_.qz_criterium; %1+1.e-5;
    %             elseif (nboth | nfwrd) & abs(egg(nspred+1,j))<=options_.qz_criterium; %1+1.e-5;
    %                 istable(j)=0;
rattoma's avatar
rattoma committed
333
334
    %             end
    %         end
335
336
337
338
339
340
341
342
343
344
345
346
347
    %     end
    %     istable=istable(find(istable));  % stable params
    %
    %     % map unstable samples
    %     iunstable=[1:Nsam];
    %     for j=1:Nsam,
    %         %if abs(egg(dr_.npred+1,j))>1+1.e-5 & abs(egg(dr_.npred,j))<1-1.e-5;
    %         %if (dr_.nboth | dr_.nfwrd),
    %         if ~any(isnan(egg(1:5,j)))
    %             if (nboth | nfwrd),
    %                 if abs(egg(nspred+1,j))>options_.qz_criterium & abs(egg(nspred,j))<options_.qz_criterium; %(1-(options_.qz_criterium-1));
    %                     iunstable(j)=0;
    %                 end
rattoma's avatar
rattoma committed
348
    %             else
349
350
351
    %                 if abs(egg(nspred,j))<options_.qz_criterium; %(1-(options_.qz_criterium-1));
    %                     iunstable(j)=0;
    %                 end
rattoma's avatar
rattoma committed
352
353
    %             end
    %         end
354
355
356
357
358
359
360
361
362
363
364
365
    %     end
    %     iunstable=iunstable(find(iunstable));   % unstable params
    bkpprior.pshape=bayestopt_.pshape;
    bkpprior.p1=bayestopt_.p1;
    bkpprior.p2=bayestopt_.p2;
    bkpprior.p3=bayestopt_.p3;
    bkpprior.p4=bayestopt_.p4;
    if pprior,
        if ~prepSA
            save([OutputDirectoryName '/' fname_ '_prior'], ...
                'bkpprior','lpmat','lpmat0','iunstable','istable','iindeterm','iwrong', ...
                'egg','yys','nspred','nboth','nfwrd')
rattoma's avatar
rattoma committed
366
        else
367
368
369
            save([OutputDirectoryName '/' fname_ '_prior'], ...
                'bkpprior','lpmat','lpmat0','iunstable','istable','iindeterm','iwrong', ...
                'egg','yys','T','nspred','nboth','nfwrd')
rattoma's avatar
rattoma committed
370
        end
371

372
373
374
375
376
377
378
379
380
    else
        if ~prepSA
            save([OutputDirectoryName '/' fname_ '_mc'], ...
                'lpmat','lpmat0','iunstable','istable','iindeterm','iwrong', ...
                'egg','yys','nspred','nboth','nfwrd')
        else
            save([OutputDirectoryName '/' fname_ '_mc'], ...
                'lpmat','lpmat0','iunstable','istable','iindeterm','iwrong', ...
                'egg','yys','T','nspred','nboth','nfwrd')
rattoma's avatar
rattoma committed
381
382
        end
    end
383
384
385
else
    if pprior,
        filetoload=[OutputDirectoryName '/' fname_ '_prior'];
rattoma's avatar
rattoma committed
386
    else
387
        filetoload=[OutputDirectoryName '/' fname_ '_mc'];
rattoma's avatar
rattoma committed
388
    end
389
390
    load(filetoload,'lpmat','lpmat0','iunstable','istable','iindeterm','iwrong','egg','yys','nspred','nboth','nfwrd')
    Nsam = size(lpmat,1);
391
392


393
394
395
396
397
398
399
400
401
402
403
404
    if prepSA & isempty(strmatch('T',who('-file', filetoload),'exact')),
        h = waitbar(0,'Please wait...');
        options_.periods=0;
        options_.nomoments=1;
        options_.irf=0;
        options_.noprint=1;
        stoch_simul([]);
        %T=zeros(size(dr_.ghx,1),size(dr_.ghx,2)+size(dr_.ghu,2),length(istable));
        ntrans=length(istable);
        for j=1:ntrans,
            M_.params(estim_params_.param_vals(:,1)) = lpmat(istable(j),:)';
            %stoch_simul([]);
405
406
407
408
409
            [Tt,Rr,SteadyState,info,M_,options_,oo_] = dynare_resolve(M_,options_,oo_);
            % This syntax is not compatible with the current version of dynare_resolve [stepan].
            %[Tt,Rr,SteadyState,info] = dynare_resolve(bayestopt_.restrict_var_list,...
            %    bayestopt_.restrict_columns,...
            %    bayestopt_.restrict_aux);
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
            if ~exist('T')
                T=zeros(size(dr_.ghx,1),size(dr_.ghx,2)+size(dr_.ghu,2),ntrans);
            end
            dr_ = oo_.dr;
            T(:,:,j) = [dr_.ghx dr_.ghu];
            if ~exist('nspred')
                nspred = dr_.nspred; %size(dr_.ghx,2);
                nboth = dr_.nboth;
                nfwrd = dr_.nfwrd;
            end
            ys_=real(dr_.ys);
            yys(:,j) = ys_;
            ys_=yys(:,1);
            waitbar(j/ntrans,h,['MC iteration ',int2str(j),'/',int2str(ntrans)])
        end
        close(h)
        save(filetoload,'T','-append')
    elseif prepSA
        load(filetoload,'T')
rattoma's avatar
rattoma committed
429
430
431
432
    end
end

if pprior
433
434
435
436
437
438
    aname='prior_stab';
    auname='prior_unacceptable';
    aunstname='prior_unstable';
    aindname='prior_indeterm';
    awrongname='prior_wrong';
    asname='prior_stable';
rattoma's avatar
rattoma committed
439
else
440
441
442
443
444
445
    aname='mc_stab';
    auname='mc_unacceptable';
    aunstname='mc_unstable';
    aindname='mc_indeterm';
    awrongname='mc_wrong';
    asname='mc_stable';
rattoma's avatar
rattoma committed
446
end
rattoma's avatar
rattoma committed
447
448
449
450
451
452
delete([OutputDirectoryName,'/',fname_,'_',aname,'_*.*']);
%delete([OutputDirectoryName,'/',fname_,'_',aname,'_SA_*.*']);
delete([OutputDirectoryName,'/',fname_,'_',asname,'_corr_*.*']);
delete([OutputDirectoryName,'/',fname_,'_',auname,'_corr_*.*']);
delete([OutputDirectoryName,'/',fname_,'_',aunstname,'_corr_*.*']);
delete([OutputDirectoryName,'/',fname_,'_',aindname,'_corr_*.*']);
rattoma's avatar
rattoma committed
453
454

if length(iunstable)>0 & length(iunstable)<Nsam,
Marco Ratto's avatar
Marco Ratto committed
455
456
    fprintf(['%4.1f%% of the prior support is stable.\n'],length(istable)/Nsam*100)
    fprintf(['%4.1f%% of the prior support is unstable.\n'],(length(iunstable)-length(iwrong)-length(iindeterm) )/Nsam*100)
457
    if ~isempty(iindeterm),
Marco Ratto's avatar
Marco Ratto committed
458
        fprintf(['%4.1f%% of the prior support gives indeterminacy.'],length(iindeterm)/Nsam*100)
459
460
461
    end
    if ~isempty(iwrong),
        disp(' ');
Marco Ratto's avatar
Marco Ratto committed
462
        disp(['For ',num2str(length(iwrong)/Nsam*100,'%1.3f'),'\% of the prior support dynare could not find a solution.'])
463
    end
rattoma's avatar
rattoma committed
464
    disp(' ');
465
466
    % Blanchard Kahn
    [proba, dproba] = stab_map_1(lpmat, istable, iunstable, aname,0);
Marco Ratto's avatar
Marco Ratto committed
467
468
%     indstab=find(dproba>ksstat);
    indstab=find(proba<pvalue_ks);
469
    disp('Smirnov statistics in driving acceptable behaviour')
Marco Ratto's avatar
Marco Ratto committed
470
471
    for j=1:length(indstab),
        disp([M_.param_names(estim_params_.param_vals(indstab(j),1),:),'   d-stat = ', num2str(dproba(indstab(j)),'%1.3f'),'   p-value = ', num2str(proba(indstab(j)),'%1.3f')])
rattoma's avatar
rattoma committed
472
473
    end
    disp(' ');
474
475
    if ~isempty(indstab)
        stab_map_1(lpmat, istable, iunstable, aname, 1, indstab, OutputDirectoryName);
rattoma's avatar
rattoma committed
476
    end
477
478
479
    ixun=iunstable(find(~ismember(iunstable,[iindeterm,iwrong])));
    if ~isempty(iindeterm),
        [proba, dproba] = stab_map_1(lpmat, [1:Nsam], iindeterm, [aname, '_indet'],0);
Marco Ratto's avatar
Marco Ratto committed
480
481
%         indindet=find(dproba>ksstat);
        indindet=find(proba<pvalue_ks);
482
        disp('Smirnov statistics in driving indeterminacy')
Marco Ratto's avatar
Marco Ratto committed
483
484
        for j=1:length(indindet),
            disp([M_.param_names(estim_params_.param_vals(indindet(j),1),:),'   d-stat = ', num2str(dproba(indindet(j)),'%1.3f'),'   p-value = ', num2str(proba(indindet(j)),'%1.3f')])
485
486
487
488
489
        end
        disp(' ');
        if ~isempty(indindet)
            stab_map_1(lpmat, [1:Nsam], iindeterm, [aname, '_indet'], 1, indindet, OutputDirectoryName);
        end
rattoma's avatar
rattoma committed
490
    end
491

492
493
    if ~isempty(ixun),
        [proba, dproba] = stab_map_1(lpmat, [1:Nsam], ixun, [aname, '_unst'],0);
Marco Ratto's avatar
Marco Ratto committed
494
495
%         indunst=find(dproba>ksstat);
        indunst=find(proba<pvalue_ks);
496
        disp('Smirnov statistics in driving instability')
Marco Ratto's avatar
Marco Ratto committed
497
498
        for j=1:length(indunst),
            disp([M_.param_names(estim_params_.param_vals(indunst(j),1),:),'   d-stat = ', num2str(dproba(indunst(j)),'%1.3f'),'   p-value = ', num2str(proba(indunst(j)),'%1.3f')])
499
500
501
502
503
        end
        disp(' ');
        if ~isempty(indunst)
            stab_map_1(lpmat, [1:Nsam], ixun, [aname, '_unst'], 1, indunst, OutputDirectoryName);
        end
504
    end
505

506
507
    if ~isempty(iwrong),
        [proba, dproba] = stab_map_1(lpmat, [1:Nsam], iwrong, [aname, '_wrong'],0);
Marco Ratto's avatar
Marco Ratto committed
508
509
%         indwrong=find(dproba>ksstat);
        indwrong=find(proba<pvalue_ks);
510
        disp('Smirnov statistics in driving no solution')
Marco Ratto's avatar
Marco Ratto committed
511
512
        for j=1:length(indwrong),
            disp([M_.param_names(estim_params_.param_vals(indwrong(j),1),:),'   d-stat = ', num2str(dproba(indwrong(j)),'%1.3f'),'   p-value = ', num2str(proba(indwrong(j)),'%1.3f')])
513
514
515
516
517
        end
        disp(' ');
        if ~isempty(indwrong)
            stab_map_1(lpmat, [1:Nsam], iwrong, [aname, '_wrong'], 1, indwrong, OutputDirectoryName);
        end
518
    end
519

520
521
    disp(' ')
    disp('Starting bivariate analysis:')
522

523
524
    c0=corrcoef(lpmat(istable,:));
    c00=tril(c0,-1);
525

Marco Ratto's avatar
Marco Ratto committed
526
    stab_map_2(lpmat(istable,:),alpha2, pvalue_corr, asname, OutputDirectoryName);
527
    if length(iunstable)>10,
Marco Ratto's avatar
Marco Ratto committed
528
        stab_map_2(lpmat(iunstable,:),alpha2, pvalue_corr, auname, OutputDirectoryName);
rattoma's avatar
rattoma committed
529
    end
530
    if length(iindeterm)>10,
Marco Ratto's avatar
Marco Ratto committed
531
        stab_map_2(lpmat(iindeterm,:),alpha2, pvalue_corr, aindname, OutputDirectoryName);
532
533
    end
    if length(ixun)>10,
Marco Ratto's avatar
Marco Ratto committed
534
        stab_map_2(lpmat(ixun,:),alpha2, pvalue_corr, aunstname, OutputDirectoryName);
535
536
    end
    if length(iwrong)>10,
Marco Ratto's avatar
Marco Ratto committed
537
        stab_map_2(lpmat(iwrong,:),alpha2, pvalue_corr, awrongname, OutputDirectoryName);
538
    end
539

rattoma's avatar
rattoma committed
540
541
    x0=0.5.*(bayestopt_.ub(1:nshock)-bayestopt_.lb(1:nshock))+bayestopt_.lb(1:nshock);
    x0 = [x0; lpmat(istable(1),:)'];
542
543
    if istable(end)~=Nsam
        M_.params(estim_params_.param_vals(:,1)) = lpmat(istable(1),:)';
544
        [oo_.dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_);
545
546
547
548
549
550
551
552
553
554
555
        %     stoch_simul([]);
    end
else
    if length(iunstable)==0,
        disp('All parameter values in the specified ranges are stable!')
        x0=0.5.*(bayestopt_.ub(1:nshock)-bayestopt_.lb(1:nshock))+bayestopt_.lb(1:nshock);
        x0 = [x0; lpmat(istable(1),:)'];
    else
        disp('All parameter values in the specified ranges are not acceptable!')
        x0=[];
    end
556

rattoma's avatar
rattoma committed
557
558
559
560
561
end


options_.periods=opt.periods;
if isfield(opt,'nomoments'),
562
    options_.nomoments=opt.nomoments;
rattoma's avatar
rattoma committed
563
564
565
566
end
options_.irf=opt.irf;
options_.noprint=opt.noprint;
if isfield(opt,'simul'),
567
    options_.simul=opt.simul;
rattoma's avatar
rattoma committed
568
569
570
571
end