2012-06-11 01:33:01 +02:00
function redform_map ( dirname,options_gsa_)
2011-12-09 21:13:16 +01:00
%function redform_map(dirname)
% inputs (from opt_gsa structure
% anamendo = options_gsa_.namendo;
% anamlagendo = options_gsa_.namlagendo;
% anamexo = options_gsa_.namexo;
% iload = options_gsa_.load_redform;
% pprior = options_gsa_.pprior;
% ilog = options_gsa_.logtrans_redform;
% threshold = options_gsa_.threshold_redform;
% ksstat = options_gsa_.ksstat_redform;
% alpha2 = options_gsa_.alpha2_redform;
%
2012-01-09 13:12:31 +01:00
% Written by Marco Ratto
2011-12-09 21:13:16 +01:00
% Joint Research Centre, The European Commission,
% (http://eemc.jrc.ec.europa.eu/),
2012-06-15 12:29:22 +02:00
% marco.ratto@jrc.it
2011-12-09 21:13:16 +01:00
%
% Reference:
% M. Ratto, Global Sensitivity Analysis for Macroeconomic models, MIMEO, 2006.
2012-01-09 13:12:31 +01:00
2013-06-12 16:42:09 +02:00
% Copyright (C) 2012-2013 Dynare Team
2012-01-09 13:12:31 +01:00
%
% This file is part of Dynare.
2011-12-09 21:13:16 +01:00
%
2012-01-09 13:12:31 +01:00
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
2011-12-09 21:13:16 +01:00
global M_ oo_ estim_params_ options_ bayestopt_
2012-06-11 01:33:01 +02:00
% options_gsa_ = options_.opt_gsa;
2011-12-09 21:13:16 +01:00
anamendo = options_gsa_ . namendo ;
anamlagendo = options_gsa_ . namlagendo ;
anamexo = options_gsa_ . namexo ;
iload = options_gsa_ . load_redform ;
pprior = options_gsa_ . pprior ;
ilog = options_gsa_ . logtrans_redform ;
threshold = options_gsa_ . threshold_redform ;
2012-06-11 01:33:01 +02:00
% ksstat = options_gsa_.ksstat_redform;
2011-12-09 21:13:16 +01:00
alpha2 = options_gsa_ . alpha2_redform ;
2012-06-11 01:33:01 +02:00
alpha2 = 0 ;
pvalue_ks = options_gsa_ . ksstat_redform ;
pvalue_corr = options_gsa_ . alpha2_redform ;
2011-12-09 21:13:16 +01:00
pnames = M_ . param_names ( estim_params_ . param_vals ( : , 1 ) , : ) ;
if nargin == 0 ,
2012-06-15 12:29:22 +02:00
dirname = ' ' ;
2011-12-09 21:13:16 +01:00
end
if pprior
2013-04-27 16:22:25 +02:00
load ( [ dirname , filesep , M_ . fname , ' _prior' ] , ' lpmat' , ' lpmat0' , ' istable' , ' T' ) ;
adir = [ dirname filesep ' redform_stab' ] ;
2011-12-09 21:13:16 +01:00
else
2013-04-27 16:22:25 +02:00
load ( [ dirname , filesep , M_ . fname , ' _mc' ] , ' lpmat' , ' lpmat0' , ' istable' , ' T' ) ;
adir = [ dirname filesep ' redform_mc' ] ;
2011-12-09 21:13:16 +01:00
end
if ~ exist ( ' T' )
2012-06-15 12:29:22 +02:00
stab_map_ ( dirname , options_gsa_ ) ;
if pprior
2013-04-27 16:22:25 +02:00
load ( [ dirname , filesep , M_ . fname , ' _prior' ] , ' T' ) ;
2012-06-15 12:29:22 +02:00
else
2013-04-27 16:22:25 +02:00
load ( [ dirname , filesep , M_ . fname , ' _mc' ] , ' T' ) ;
2012-06-15 12:29:22 +02:00
end
2013-03-19 17:06:33 +01:00
if ~ exist ( ' T' ) ,
disp ( ' The model is too large!' )
disp ( ' Reduced form mapping stopped!' )
return
end
2011-12-09 21:13:16 +01:00
end
if isempty ( dir ( adir ) )
2012-06-15 12:29:22 +02:00
mkdir ( adir )
2011-12-09 21:13:16 +01:00
end
adir0 = pwd ;
%cd(adir)
nspred = size ( T , 2 ) - M_ . exo_nbr ;
x0 = lpmat ( istable , : ) ;
2013-04-18 19:36:41 +02:00
if isempty ( lpmat0 ) ,
xx0 = [ ] ;
nshocks = 0 ;
else
xx0 = lpmat0 ( istable , : ) ;
nshocks = size ( xx0 , 2 ) ;
end
2011-12-09 21:13:16 +01:00
[ kn , np ] = size ( x0 ) ;
offset = length ( bayestopt_ . pshape ) - np ;
if options_gsa_ . prior_range ,
2012-06-15 12:29:22 +02:00
pshape = 5 * ( ones ( np , 1 ) ) ;
pd = [ NaN ( np , 1 ) NaN ( np , 1 ) bayestopt_ . lb ( offset + 1 : end ) bayestopt_ . ub ( offset + 1 : end ) ] ;
2011-12-09 21:13:16 +01:00
else
2012-06-15 12:29:22 +02:00
pshape = bayestopt_ . pshape ( offset + 1 : end ) ;
pd = [ bayestopt_ . p6 ( offset + 1 : end ) bayestopt_ . p7 ( offset + 1 : end ) bayestopt_ . p3 ( offset + 1 : end ) bayestopt_ . p4 ( offset + 1 : end ) ] ;
2011-12-09 21:13:16 +01:00
end
nsok = length ( find ( M_ . lead_lag_incidence ( M_ . maximum_lag , : ) ) ) ;
2013-04-18 19:36:41 +02:00
lpmat = [ ] ;
lpmat0 = [ ] ;
2011-12-09 21:13:16 +01:00
js = 0 ;
for j = 1 : size ( anamendo , 1 )
2012-06-15 12:29:22 +02:00
namendo = deblank ( anamendo ( j , : ) ) ;
iendo = strmatch ( namendo , M_ . endo_names ( oo_ . dr . order_var , : ) , ' exact' ) ;
ifig = 0 ;
iplo = 0 ;
for jx = 1 : size ( anamexo , 1 )
namexo = deblank ( anamexo ( jx , : ) ) ;
iexo = strmatch ( namexo , M_ . exo_names , ' exact' ) ;
2013-07-10 17:12:34 +02:00
skipline ( )
2012-06-15 12:29:22 +02:00
disp ( [ ' [' , namendo , ' vs. ' , namexo , ' ]' ] )
2011-12-09 21:13:16 +01:00
2012-06-15 12:29:22 +02:00
if ~ isempty ( iexo ) ,
%y0=squeeze(T(iendo,iexo+nspred,istable));
y0 = squeeze ( T ( iendo , iexo + nspred , : ) ) ;
if ( max ( y0 ) - min ( y0 ) ) > 1.e-10 ,
if mod ( iplo , 9 ) == 0 && isempty ( threshold ) && ~ options_ . nograph ,
ifig = ifig + 1 ;
2013-04-27 12:52:48 +02:00
hfig = dyn_figure ( options_ , ' name' , [ ' Reduced Form Mapping: ' , namendo , ' vs. shocks ' , int2str ( ifig ) ] ) ;
2012-06-15 12:29:22 +02:00
iplo = 0 ;
end
iplo = iplo + 1 ;
js = js + 1 ;
2013-04-27 16:22:25 +02:00
xdir0 = [ adir , filesep , namendo , ' _vs_' , namexo ] ;
2013-12-10 17:31:26 +01:00
if ilog == 0 || ~ isempty ( threshold ) ,
2012-06-15 12:29:22 +02:00
if isempty ( threshold )
if isempty ( dir ( xdir0 ) )
mkdir ( xdir0 )
end
si ( : , js ) = redform_private ( x0 , y0 , pshape , pd , iload , pnames , namendo , namexo , xdir0 , options_gsa_ ) ;
else
iy = find ( ( y0 > threshold ( 1 ) ) & ( y0 < threshold ( 2 ) ) ) ;
iyc = find ( ( y0 < = threshold ( 1 ) ) | ( y0 > = threshold ( 2 ) ) ) ;
2013-04-11 10:09:21 +02:00
xdir = [ xdir0 , ' _threshold' ] ;
2012-06-15 12:29:22 +02:00
if isempty ( dir ( xdir ) )
mkdir ( xdir )
end
2012-06-29 00:36:22 +02:00
if ~ options_ . nograph ,
2013-04-27 12:52:48 +02:00
hf = dyn_figure ( options_ , ' name' , [ ' Reduced Form Mapping: ' , namendo , ' vs. ' , namexo ] ) ; hist ( y0 , 30 ) , title ( [ namendo , ' vs. ' , namexo ] , ' interpreter' , ' none' )
2013-04-27 16:22:25 +02:00
dyn_saveas ( hf , [ xdir , filesep , namendo , ' _vs_' , namexo ] , options_ ) ;
2012-06-29 00:36:22 +02:00
end
2012-06-15 12:29:22 +02:00
% if ~isempty(iy),
% si(:,js) = redform_private(x0(iy,:), y0(iy), pshape, pd, iload, pnames, namendo, namexo, xdir, options_gsa_);
% else
si ( : , js ) = NaN ( np , 1 ) ;
% end
2013-04-18 19:36:41 +02:00
if length ( iy ) > size ( x0 , 2 ) && length ( iyc ) > size ( x0 , 2 )
2013-04-11 10:09:21 +02:00
delete ( [ xdir , ' /*threshold*.*' ] )
[ proba , dproba ] = stab_map_1 ( x0 , iy , iyc , ' threshold' , 0 ) ;
2012-06-15 12:29:22 +02:00
% indsmirnov = find(dproba>ksstat);
indsmirnov = find ( proba < pvalue_ks ) ;
for jp = 1 : length ( indsmirnov ) ,
disp ( [ M_ . param_names ( estim_params_ . param_vals ( indsmirnov ( jp ) , 1 ) , : ) , ' d-stat = ' , num2str ( dproba ( indsmirnov ( jp ) ) , ' %1.3f' ) , ' p-value = ' , num2str ( proba ( indsmirnov ( jp ) ) , ' %1.3f' ) ] )
end
2013-07-10 17:12:34 +02:00
skipline ( )
2013-05-02 08:36:29 +02:00
stab_map_1 ( x0 , iy , iyc , ' threshold' , pvalue_ks , indsmirnov , xdir , [ ] , [ ' Reduced Form Mapping (Threshold) for ' , namendo , ' vs. lagged ' , namexo ] ) ;
stab_map_2 ( x0 ( iy , : ) , alpha2 , pvalue_corr , ' inside_threshold' , xdir , [ ] , [ ' Reduced Form Mapping (Inside Threshold)for ' , namendo , ' vs. lagged ' , namexo ] )
stab_map_2 ( x0 ( iyc , : ) , alpha2 , pvalue_corr , ' outside_threshold' , xdir , [ ] , [ ' Reduced Form Mapping (Outside Threshold) for ' , namendo , ' vs. lagged ' , namexo ] )
2012-06-15 12:29:22 +02:00
lpmat = x0 ( iy , : ) ;
2013-04-18 19:36:41 +02:00
if nshocks ,
lpmat0 = xx0 ( iy , : ) ;
end
2012-06-15 12:29:22 +02:00
istable = [ 1 : length ( iy ) ] ;
2013-04-11 10:09:21 +02:00
save ( [ xdir , filesep , ' threshold.mat' ] , ' lpmat' , ' lpmat0' , ' istable' , ' y0' , ' x0' , ' xx0' , ' iy' , ' iyc' )
2013-04-18 19:36:41 +02:00
lpmat = [ ] ; lpmat0 = [ ] ; istable = [ ] ;
2012-06-15 12:29:22 +02:00
end
end
else
[ yy , xdir ] = log_trans_ ( y0 , xdir0 ) ;
if isempty ( dir ( xdir ) )
mkdir ( xdir )
end
silog ( : , js ) = redform_private ( x0 , yy , pshape , pd , iload , pnames , namendo , namexo , xdir , options_gsa_ ) ;
end
if isempty ( threshold ) && ~ options_ . nograph ,
figure ( hfig )
subplot ( 3 , 3 , iplo ) ,
if ilog ,
[ saso , iso ] = sort ( - silog ( : , js ) ) ;
bar ( [ silog ( iso ( 1 : min ( np , 10 ) ) , js ) ] )
logflag = ' log' ;
else
[ saso , iso ] = sort ( - si ( : , js ) ) ;
bar ( si ( iso ( 1 : min ( np , 10 ) ) , js ) )
logflag = ' ' ;
end
%set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8)
set ( gca , ' xticklabel' , ' ' , ' fontsize' , 10 )
set ( gca , ' xlim' , [ 0.5 10.5 ] )
for ip = 1 : min ( np , 10 ) ,
text ( ip , - 0.02 , deblank ( pnames ( iso ( ip ) , : ) ) , ' rotation' , 90 , ' HorizontalAlignment' , ' right' , ' interpreter' , ' none' )
end
title ( [ logflag , ' ' , namendo , ' vs. ' , namexo ] , ' interpreter' , ' none' )
if iplo == 9 ,
2013-04-27 16:22:25 +02:00
dyn_saveas ( hfig , [ dirname , filesep , M_ . fname , ' _redform_' , namendo , ' _vs_shocks_' , logflag , num2str ( ifig ) ] , options_ ) ;
2012-06-15 12:29:22 +02:00
end
end
2011-12-09 21:13:16 +01:00
end
end
2012-06-15 12:29:22 +02:00
end
if iplo < 9 && iplo > 0 && ifig && ~ options_ . nograph ,
2013-04-27 16:22:25 +02:00
dyn_saveas ( hfig , [ dirname , filesep , M_ . fname , ' _redform_' , namendo , ' _vs_shocks_' , logflag , num2str ( ifig ) ] , options_ ) ;
2012-04-20 20:17:20 +02:00
end
2012-06-15 12:29:22 +02:00
ifig = 0 ;
iplo = 0 ;
for je = 1 : size ( anamlagendo , 1 )
namlagendo = deblank ( anamlagendo ( je , : ) ) ;
2012-11-16 20:05:13 +01:00
ilagendo = strmatch ( namlagendo , M_ . endo_names ( oo_ . dr . order_var ( M_ . nstatic + 1 : M_ . nstatic + nsok ) , : ) , ' exact' ) ;
2013-07-10 17:12:34 +02:00
skipline ( )
2012-06-15 12:29:22 +02:00
disp ( [ ' [' , namendo , ' vs. lagged ' , namlagendo , ' ]' ] )
if ~ isempty ( ilagendo ) ,
%y0=squeeze(T(iendo,ilagendo,istable));
y0 = squeeze ( T ( iendo , ilagendo , : ) ) ;
if ( max ( y0 ) - min ( y0 ) ) > 1.e-10 ,
if mod ( iplo , 9 ) == 0 && isempty ( threshold ) && ~ options_ . nograph ,
ifig = ifig + 1 ;
2013-04-27 12:52:48 +02:00
hfig = dyn_figure ( options_ , ' name' , [ ' Reduced Form Mapping: ' namendo , ' vs. lags ' , int2str ( ifig ) ] ) ;
2012-06-15 12:29:22 +02:00
iplo = 0 ;
end
iplo = iplo + 1 ;
js = js + 1 ;
2013-04-27 16:22:25 +02:00
xdir0 = [ adir , filesep , namendo , ' _vs_' , namlagendo ] ;
2013-12-10 17:31:26 +01:00
if ilog == 0 || ~ isempty ( threshold ) ,
2012-06-15 12:29:22 +02:00
if isempty ( threshold )
if isempty ( dir ( xdir0 ) )
mkdir ( xdir0 )
end
si ( : , js ) = redform_private ( x0 , y0 , pshape , pd , iload , pnames , namendo , namlagendo , xdir0 , options_gsa_ ) ;
else
iy = find ( ( y0 > threshold ( 1 ) ) & ( y0 < threshold ( 2 ) ) ) ;
iyc = find ( ( y0 < = threshold ( 1 ) ) | ( y0 > = threshold ( 2 ) ) ) ;
2013-04-11 10:09:21 +02:00
xdir = [ xdir0 , ' _threshold' ] ;
2012-06-15 12:29:22 +02:00
if isempty ( dir ( xdir ) )
mkdir ( xdir )
end
% if ~isempty(iy)
% si(:,js) = redform_private(x0(iy,:), y0(iy), pshape, pd, iload, pnames, namendo, namlagendo, xdir, options_gsa_);
% end
2012-06-29 00:36:22 +02:00
if ~ options_ . nograph ,
2013-04-27 12:52:48 +02:00
hf = dyn_figure ( options_ , ' name' , [ ' Reduced Form Mapping: ' , namendo , ' vs. lagged ' , namlagendo ] ) ; hist ( y0 , 30 ) , title ( [ namendo , ' vs. lagged ' , namlagendo ] , ' interpreter' , ' none' )
2013-04-27 16:22:25 +02:00
dyn_saveas ( hf , [ xdir , filesep , namendo , ' _vs_' , namlagendo ] , options_ ) ;
2012-06-29 00:36:22 +02:00
end
2013-04-18 19:36:41 +02:00
if length ( iy ) > size ( x0 , 2 ) && length ( iyc ) > size ( x0 , 2 ) ,
2013-04-11 10:09:21 +02:00
delete ( [ xdir , ' /*threshold*.*' ] )
[ proba , dproba ] = stab_map_1 ( x0 , iy , iyc , ' threshold' , 0 ) ;
2012-06-15 12:29:22 +02:00
% indsmirnov = find(dproba>ksstat);
indsmirnov = find ( proba < pvalue_ks ) ;
for jp = 1 : length ( indsmirnov ) ,
disp ( [ M_ . param_names ( estim_params_ . param_vals ( indsmirnov ( jp ) , 1 ) , : ) , ' d-stat = ' , num2str ( dproba ( indsmirnov ( jp ) ) , ' %1.3f' ) , ' p-value = ' , num2str ( proba ( indsmirnov ( jp ) ) , ' %1.3f' ) ] )
end
2013-07-10 17:12:34 +02:00
skipline ( )
2013-04-27 12:52:48 +02:00
stab_map_1 ( x0 , iy , iyc , ' threshold' , pvalue_ks , indsmirnov , xdir , [ ] , [ ' Reduced Form Mapping (Threshold) for ' , namendo , ' vs. lagged ' , namlagendo ] ) ;
stab_map_2 ( x0 ( iy , : ) , alpha2 , pvalue_corr , ' inside_threshold' , xdir , [ ] , [ ' Reduced Form Mapping (Inside Threshold) for ' , namendo , ' vs. lagged ' , namlagendo ] )
stab_map_2 ( x0 ( iyc , : ) , alpha2 , pvalue_corr , ' outside_threshold' , xdir , [ ] , [ ' Reduced Form Mapping (Outside Threshold) for ' , namendo , ' vs. lagged ' , namlagendo ] )
2012-06-15 12:29:22 +02:00
lpmat = x0 ( iy , : ) ;
2013-04-18 19:36:41 +02:00
if nshocks ,
lpmat0 = xx0 ( iy , : ) ;
end
2012-06-15 12:29:22 +02:00
istable = [ 1 : length ( iy ) ] ;
2013-04-11 10:09:21 +02:00
save ( [ xdir , filesep , ' threshold.mat' ] , ' lpmat' , ' lpmat0' , ' istable' , ' y0' , ' x0' , ' xx0' , ' iy' , ' iyc' )
2013-04-18 19:36:41 +02:00
lpmat = [ ] ; lpmat0 = [ ] ; istable = [ ] ;
2012-06-15 12:29:22 +02:00
end
end
else
[ yy , xdir ] = log_trans_ ( y0 , xdir0 ) ;
if isempty ( dir ( xdir ) )
mkdir ( xdir )
end
silog ( : , js ) = redform_private ( x0 , yy , pshape , pd , iload , pnames , namendo , namlagendo , xdir , options_gsa_ ) ;
end
if isempty ( threshold ) && ~ options_ . nograph
figure ( hfig ) ,
subplot ( 3 , 3 , iplo ) ,
if ilog ,
[ saso , iso ] = sort ( - silog ( : , js ) ) ;
bar ( [ silog ( iso ( 1 : min ( np , 10 ) ) , js ) ] )
logflag = ' log' ;
else
[ saso , iso ] = sort ( - si ( : , js ) ) ;
bar ( si ( iso ( 1 : min ( np , 10 ) ) , js ) )
logflag = ' ' ;
end
%set(gca,'xticklabel',pnames(iso(1:min(np,10)),:),'fontsize',8)
set ( gca , ' xticklabel' , ' ' , ' fontsize' , 10 )
set ( gca , ' xlim' , [ 0.5 10.5 ] )
for ip = 1 : min ( np , 10 ) ,
text ( ip , - 0.02 , deblank ( pnames ( iso ( ip ) , : ) ) , ' rotation' , 90 , ' HorizontalAlignment' , ' right' , ' interpreter' , ' none' )
end
title ( [ logflag , ' ' , namendo , ' vs. ' , namlagendo , ' (-1)' ] , ' interpreter' , ' none' )
if iplo == 9 ,
2013-04-27 16:22:25 +02:00
dyn_saveas ( hfig , [ dirname , filesep , M_ . fname , ' _redform_' , namendo , ' _vs_lags_' , logflag , num2str ( ifig ) ] , options_ ) ;
2012-06-15 12:29:22 +02:00
end
end
2012-04-20 20:17:20 +02:00
end
2011-12-09 21:13:16 +01:00
end
end
2012-06-15 12:29:22 +02:00
if iplo < 9 && iplo > 0 && ifig && ~ options_ . nograph ,
2013-04-27 16:22:25 +02:00
dyn_saveas ( hfig , [ dirname , filesep , M_ . fname , ' _redform_' , namendo , ' _vs_lags_' , logflag , num2str ( ifig ) ] , options_ ) ;
2012-04-20 20:17:20 +02:00
end
2011-12-09 21:13:16 +01:00
end
2012-06-15 12:29:22 +02:00
if isempty ( threshold ) && ~ options_ . nograph ,
if ilog == 0 ,
2013-04-27 12:52:48 +02:00
hfig = dyn_figure ( options_ , ' name' , ' Reduced Form GSA' ) ; %bar(si)
2012-06-15 12:29:22 +02:00
% boxplot(si','whis',10,'symbol','r.')
myboxplot ( si ' , [ ] , ' .' , [ ] , 10 )
xlabel ( ' ' )
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
title ( ' Reduced form GSA' )
2013-04-27 16:22:25 +02:00
dyn_saveas ( hfig , [ dirname , filesep , M_ . fname , ' _redform_gsa' ] , options_ ) ;
2012-06-15 12:29:22 +02:00
else
2013-04-27 12:52:48 +02:00
hfig = dyn_figure ( options_ , ' name' , ' Reduced Form GSA' ) ; %bar(silog)
2012-06-15 12:29:22 +02:00
% boxplot(silog','whis',10,'symbol','r.')
myboxplot ( silog ' , [ ] , ' .' , [ ] , 10 )
set ( gca , ' xticklabel' , ' ' , ' fontsize' , 10 , ' xtick' , [ 1 : np ] )
xlabel ( ' ' )
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
title ( ' Reduced form GSA - Log-transformed elements' )
2013-04-27 16:22:25 +02:00
dyn_saveas ( hfig , [ dirname , filesep , M_ . fname , ' _redform_gsa_log' ] , options_ ) ;
2012-06-15 12:29:22 +02:00
end
2012-06-11 01:33:01 +02:00
end
function si = redform_private ( x0, y0, pshape, pd, iload, pnames, namy, namx, xdir, opt_gsa)
2011-12-09 21:13:16 +01:00
global bayestopt_ options_
2012-06-11 01:33:01 +02:00
% opt_gsa=options_.opt_gsa;
2011-12-09 21:13:16 +01:00
np = size ( x0 , 2 ) ;
x00 = x0 ;
2012-06-15 12:29:22 +02:00
if opt_gsa . prior_range ,
2011-12-09 21:13:16 +01:00
for j = 1 : np ,
2012-06-15 12:29:22 +02:00
x0 ( : , j ) = ( x0 ( : , j ) - pd ( j , 3 ) ) ./ ( pd ( j , 4 ) - pd ( j , 3 ) ) ;
2011-12-09 21:13:16 +01:00
end
2012-06-15 12:29:22 +02:00
else
2011-12-09 21:13:16 +01:00
x0 = priorcdf ( x0 , pshape , pd ( : , 1 ) , pd ( : , 2 ) , pd ( : , 3 ) , pd ( : , 4 ) ) ;
2012-06-15 12:29:22 +02:00
end
2011-12-09 21:13:16 +01:00
fname = [ xdir , ' /map' ] ;
if iload == 0 ,
2012-06-15 12:29:22 +02:00
if isempty ( dir ( xdir ) )
mkdir ( xdir )
end
if ~ options_ . nograph ,
2013-04-27 12:52:48 +02:00
hfig = dyn_figure ( options_ , ' name' , [ ' Reduced Form Mapping: ' , namy , ' vs. ' , namx ] ) ; hist ( y0 , 30 ) , title ( [ namy , ' vs. ' , namx ] , ' interpreter' , ' none' )
2013-04-27 16:22:25 +02:00
dyn_saveas ( hfig , [ xdir , filesep , namy , ' _vs_' , namx ] , options_ ) ;
2012-06-15 12:29:22 +02:00
end
% gsa_ = gsa_sdp_dyn(y0, x0, -2, [],[],[],1,fname, pnames);
nrun = length ( y0 ) ;
nest = min ( 250 , nrun ) ;
nfit = min ( 1000 , nrun ) ;
% dotheplots = (nfit<=nest);
gsa_ = gsa_sdp ( y0 ( 1 : nest ) , x0 ( 1 : nest , : ) , 2 , [ ] , [ - 1 - 1 - 1 - 1 - 1 0 ] , [ ] , 0 , [ fname , ' _est' ] , pnames ) ;
if nfit > nest ,
gsa_ = gsa_sdp ( y0 ( 1 : nfit ) , x0 ( 1 : nfit , : ) , - 2 , gsa_ . nvr * nest ^3 / nfit ^3 , [ - 1 - 1 - 1 - 1 - 1 0 ] , [ ] , 0 , fname , pnames ) ;
end
save ( [ fname , ' .mat' ] , ' gsa_' )
[ sidum , iii ] = sort ( - gsa_ . si ) ;
gsa_ . x0 = x00 ( 1 : nfit , : ) ;
if ~ options_ . nograph ,
hfig = gsa_sdp_plot ( gsa_ , fname , pnames , iii ( 1 : min ( 12 , np ) ) ) ;
2013-03-27 17:38:18 +01:00
if options_ . nodisplay
close ( hfig ) ;
end
2012-06-15 12:29:22 +02:00
end
gsa_ . x0 = x0 ( 1 : nfit , : ) ;
% copyfile([fname,'_est.mat'],[fname,'.mat'])
if ~ options_ . nograph ,
2013-04-27 12:52:48 +02:00
hfig = dyn_figure ( options_ , ' name' , [ ' Reduced Form Mapping: ' namy , ' _vs_' , namx , ' _fit' ] ) ;
2012-06-15 12:29:22 +02:00
plot ( y0 ( 1 : nfit ) , [ gsa_ . fit y0 ( 1 : nfit ) ] , ' .' ) ,
2013-04-27 12:52:48 +02:00
title ( [ namy , ' vs. ' , namx , ' fit' ] , ' interpreter' , ' none' )
2013-04-27 16:22:25 +02:00
dyn_saveas ( hfig , [ xdir , filesep , namy , ' _vs_' , namx , ' _fit' ] , options_ ) ;
2012-06-15 12:29:22 +02:00
if nfit < nrun ,
npred = [ nfit + 1 : nrun ] ;
yf = ss_anova_fcast ( x0 ( npred , : ) , gsa_ ) ;
2013-04-27 12:52:48 +02:00
hfig = dyn_figure ( options_ , ' name' , [ ' Reduced Form Mapping: ' namy , ' _vs_' , namx , ' _pred' ] ) ;
2012-06-15 12:29:22 +02:00
plot ( y0 ( npred ) , [ yf y0 ( npred ) ] , ' .' ) ,
2013-04-27 12:52:48 +02:00
title ( [ namy , ' vs. ' , namx , ' pred' ] , ' interpreter' , ' none' )
2013-04-27 16:22:25 +02:00
dyn_saveas ( hfig , [ xdir , filesep , namy , ' _vs_' , namx , ' _pred' ] , options_ ) ;
2012-06-15 12:29:22 +02:00
end
end
2011-12-09 21:13:16 +01:00
else
2012-06-15 12:29:22 +02:00
% gsa_ = gsa_sdp_dyn(y0, x0, 0, [],[],[],0,fname, pnames);
gsa_ = gsa_sdp ( y0 , x0 , 0 , [ ] , [ ] , [ ] , 0 , fname , pnames ) ;
if ~ options_ . nograph ,
yf = ss_anova_fcast ( x0 , gsa_ ) ;
2013-04-27 12:52:48 +02:00
hfig = dyn_figure ( options_ , [ ' Reduced Form Mapping: ' namy , ' _vs_' , namx , ' _pred' ] ) ;
2012-06-15 12:29:22 +02:00
plot ( y0 , [ yf y0 ] , ' .' ) ,
2013-04-27 12:52:48 +02:00
title ( [ namy , ' vs. ' , namx , ' pred' ] , ' interpreter' , ' none' )
2013-04-27 16:22:25 +02:00
dyn_saveas ( hfig , [ xdir , filesep , namy , ' _vs_' , namx , ' _pred' ] , options_ ) ;
2012-06-15 12:29:22 +02:00
end
2011-12-09 21:13:16 +01:00
end
% si = gsa_.multivariate.si;
si = gsa_ . si ;