2015-05-05 16:02:37 +02:00
function myoutput= PosteriorIRF_core2 ( myinputs,fpar,npar,whoiam,ThisMatlab)
% function myoutput=PosteriorIRF_core2(myinputs,fpar,npar,whoiam, ThisMatlab)
2013-10-12 09:40:04 +02:00
% Generates the Posterior IRFs plot from the IRFs generated in
% PosteriorIRF_core1
2015-05-05 16:02:37 +02:00
%
2010-05-31 11:52:38 +02:00
% PARALLEL CONTEXT
2015-05-05 16:02:37 +02:00
% Performs in parallel execution a portion of the PosteriorIRF.m code.
2016-05-19 17:13:39 +02:00
% For more information, see the comment in posterior_sampler_core.m
2015-05-05 16:02:37 +02:00
% function.
2010-05-31 11:52:38 +02:00
%
2014-06-23 11:08:48 +02:00
% INPUTS
2015-05-05 16:02:37 +02:00
% o myimput [struc] The mandatory variables for local/remote
2016-05-19 17:13:39 +02:00
% parallel computing obtained from posterior_sampler.m
2015-05-05 16:02:37 +02:00
% function.
% o fblck and nblck [integer] The Metropolis-Hastings chains.
% o whoiam [integer] In concurrent programming a modality to refer to the differents thread running in parallel is needed.
% The integer whoaim is the integer that
% allows us to distinguish between them. Then it is the index number of this CPU among all CPUs in the
% cluster.
% o ThisMatlab [integer] Allows us to distinguish between the
% 'main' matlab, the slave matlab worker, local matlab, remote matlab,
% ... Then it is the index number of this slave machine in the cluster.
2010-05-31 11:52:38 +02:00
%
% OUTPUTS
2015-05-05 16:02:37 +02:00
% o myoutput [struc] Contained: OutputFileName (i.e. the figures without the file .txt).
2010-05-31 11:52:38 +02:00
%
2014-06-23 11:08:48 +02:00
% ALGORITHM
% Portion of PosteriorIRF.m function code. Specifically the last 'for' cycle.
2010-05-31 11:52:38 +02:00
%
% SPECIAL REQUIREMENTS.
% None.
%
2016-05-19 17:13:39 +02:00
% Copyright (C) 2006-2016 Dynare Team
2010-02-15 16:52:36 +01:00
%
% This file is part of Dynare.
%
% 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/>.
2014-06-23 11:08:48 +02:00
global options_ M_
2010-02-10 18:46:24 +01:00
if nargin < 4 ,
whoiam = 0 ;
end
2010-05-31 11:52:38 +02:00
% Reshape 'myinputs' for local computation.
% In order to avoid confusion in the name space, the instruction struct2local(myinputs) is replaced by:
2010-10-08 16:19:03 +02:00
Check = options_ . TeX ;
2011-02-04 17:17:48 +01:00
if ( Check )
varlist_TeX = myinputs . varlist_TeX ;
end
2010-05-31 11:52:38 +02:00
nvar = myinputs . nvar ;
MeanIRF = myinputs . MeanIRF ;
tit = myinputs . tit ;
nn = myinputs . nn ;
MAX_nirfs_dsgevar = myinputs . MAX_nirfs_dsgevar ;
HPDIRF = myinputs . HPDIRF ;
2010-08-11 12:04:14 +02:00
if options_ . dsge_var
HPDIRFdsgevar = myinputs . HPDIRFdsgevar ;
MeanIRFdsgevar = myinputs . MeanIRFdsgevar ;
end
2010-06-24 12:49:27 +02:00
2010-05-31 11:52:38 +02:00
varlist = myinputs . varlist ;
MaxNumberOfPlotPerFigure = myinputs . MaxNumberOfPlotPerFigure ;
% Necessary only for remote computing!
if whoiam
2011-02-04 17:17:48 +01:00
Parallel = myinputs . Parallel ;
2010-05-31 11:52:38 +02:00
end
2010-02-10 18:46:24 +01:00
% To save the figures where the function is computed!
2011-12-15 11:56:23 +01:00
DirectoryName = CheckPath ( ' Output' , M_ . dname ) ;
2010-02-10 18:46:24 +01:00
RemoteFlag = 0 ;
2010-02-12 18:01:53 +01:00
if whoiam ,
2011-12-13 18:32:57 +01:00
if Parallel ( ThisMatlab ) . Local == 0 ,
RemoteFlag = 1 ;
2010-02-12 18:01:53 +01:00
end
2011-12-13 18:32:57 +01:00
prct0 = { 0 , whoiam , Parallel ( ThisMatlab ) } ;
dyn_waitbar ( prct0 , ' PosteriorIRF Plots ...' ) ;
2010-02-12 18:01:53 +01:00
end
2010-02-10 18:46:24 +01:00
OutputFileName = { } ;
subplotnum = 0 ;
2010-02-12 18:01:53 +01:00
for i = fpar : npar ,
2011-02-04 17:17:48 +01:00
figunumber = 0 ;
2014-06-23 11:08:48 +02:00
2011-02-04 17:17:48 +01:00
for j = 1 : nvar
2015-08-14 12:36:08 +02:00
if max ( abs ( MeanIRF ( : , j , i ) ) ) > = options_ . impulse_responses . plot_threshold
2011-02-04 17:17:48 +01:00
subplotnum = subplotnum + 1 ;
2012-04-20 20:17:20 +02:00
if subplotnum == 1 && options_ . relative_irf
hh = dyn_figure ( options_ , ' Name' , [ ' Relative response to orthogonalized shock to ' tit ( i , : ) ] ) ;
elseif subplotnum == 1 && ~ options_ . relative_irf
hh = dyn_figure ( options_ , ' Name' , [ ' Orthogonalized shock to ' tit ( i , : ) ] ) ;
2011-02-04 17:17:48 +01:00
end
2014-06-23 11:08:48 +02:00
2011-02-04 17:17:48 +01:00
set ( 0 , ' CurrentFigure' , hh )
subplot ( nn , nn , subplotnum ) ;
if ~ MAX_nirfs_dsgevar
2015-05-05 16:02:37 +02:00
h1 = area ( 1 : options_ . irf , HPDIRF ( : , 2 , j , i ) , ' FaceColor' , [ . 9 . 9 . 9 ] , ' BaseValue' , min ( HPDIRF ( : , 1 , j , i ) ) ) ; %grey below HPDIsup and minimum of HPDIinf
2011-02-04 17:17:48 +01:00
hold on
2015-05-05 16:02:37 +02:00
h2 = area ( 1 : options_ . irf , HPDIRF ( : , 1 , j , i ) , ' FaceColor' , [ 1 1 1 ] , ' BaseValue' , min ( HPDIRF ( : , 1 , j , i ) ) ) ; %white below HPDIinf and minimum of HPDIinf
2011-02-04 17:17:48 +01:00
plot ( 1 : options_ . irf , MeanIRF ( : , j , i ) , ' -k' , ' linewidth' , 3 )
2014-06-23 11:08:48 +02:00
% plot([1 options_.irf],[0 0],'-r','linewidth',0.5);
2011-02-04 17:17:48 +01:00
box on
axis tight
xlim ( [ 1 options_ . irf ] ) ;
2016-06-18 14:28:49 +02:00
remove_fractional_xticks ;
2011-02-04 17:17:48 +01:00
hold off
2014-06-23 11:08:48 +02:00
else
2015-05-05 16:02:37 +02:00
h1 = area ( 1 : options_ . irf , HPDIRF ( : , 2 , j , i ) , ' FaceColor' , [ . 9 . 9 . 9 ] , ' BaseValue' , min ( [ min ( HPDIRF ( : , 1 , j , i ) ) , min ( HPDIRFdsgevar ( : , 1 , j , i ) ) ] ) ) ; %grey below HPDIsup and minimum of HPDIinf and HPDIRFdsgevar
hold on
h2 = area ( 1 : options_ . irf , HPDIRF ( : , 1 , j , i ) , ' FaceColor' , [ 1 1 1 ] , ' BaseValue' , min ( [ min ( HPDIRF ( : , 1 , j , i ) ) , min ( HPDIRFdsgevar ( : , 1 , j , i ) ) ] ) ) ; %white below HPDIinf and minimum of HPDIinf and HPDIRFdsgevar
2011-02-04 17:17:48 +01:00
plot ( 1 : options_ . irf , MeanIRF ( : , j , i ) , ' -k' , ' linewidth' , 3 )
plot ( 1 : options_ . irf , MeanIRFdsgevar ( : , j , i ) , ' --k' , ' linewidth' , 2 )
plot ( 1 : options_ . irf , HPDIRFdsgevar ( : , 1 , j , i ) , ' --k' , ' linewidth' , 1 )
plot ( 1 : options_ . irf , HPDIRFdsgevar ( : , 2 , j , i ) , ' --k' , ' linewidth' , 1 )
2015-05-05 16:02:37 +02:00
% plot([1 options_.irf],[0 0],'-r','linewidth',0.5);
2011-02-04 17:17:48 +01:00
box on
axis tight
xlim ( [ 1 options_ . irf ] ) ;
2016-06-18 14:28:49 +02:00
remove_fractional_xticks ;
2011-02-04 17:17:48 +01:00
hold off
end
name = deblank ( varlist ( j , : ) ) ;
title ( name , ' Interpreter' , ' none' )
2013-10-12 10:42:16 +02:00
else
if options_ . debug
fprintf ( ' POSTERIOR_IRF: The IRF of %s to %s is smaller than the irf_plot_threshold of %4.3f and will not be displayed.\n' , deblank ( varlist ( j , : ) ) , tit ( i , : ) , options_ . impulse_responses . plot_threshold )
2014-06-23 11:08:48 +02:00
end
2010-02-10 18:46:24 +01:00
end
2014-06-23 11:08:48 +02:00
2011-02-10 17:23:22 +01:00
if subplotnum == MaxNumberOfPlotPerFigure || ( j == nvar && subplotnum > 0 )
2011-02-04 17:17:48 +01:00
figunumber = figunumber + 1 ;
2012-04-20 20:17:20 +02:00
dyn_saveas ( hh , [ DirectoryName ' /' M_ . fname ' _Bayesian_IRF_' deblank ( tit ( i , : ) ) ' _' int2str ( figunumber ) ] , options_ ) ;
2011-02-04 17:17:48 +01:00
if RemoteFlag == 1 ,
OutputFileName = [ OutputFileName ; { [ DirectoryName , filesep ] , [ M_ . fname ' _Bayesian_IRF_' deblank ( tit ( i , : ) ) ' _' int2str ( figunumber ) ' .*' ] } ] ;
end
subplotnum = 0 ;
2010-02-10 18:46:24 +01:00
end
2011-02-04 17:17:48 +01:00
end % loop over selected endo_var
2010-02-10 18:46:24 +01:00
if whoiam ,
2011-02-04 17:17:48 +01:00
fprintf ( ' Done! \n' ) ;
waitbarString = [ ' Exog. shocks ' int2str ( i ) ' /' int2str ( npar ) ' done.' ] ;
2011-12-13 18:32:57 +01:00
% fMessageStatus((i-fpar+1)/(npar-fpar+1),whoiam,waitbarString, waitbarTitle, Parallel(ThisMatlab));
dyn_waitbar ( ( i - fpar + 1 ) / ( npar - fpar + 1 ) , [ ] , waitbarString ) ;
2010-02-10 18:46:24 +01:00
end
2014-06-23 11:08:48 +02:00
end % loop over exo_var
2011-02-04 17:17:48 +01:00
2010-02-10 18:46:24 +01:00
myoutput . OutputFileName = OutputFileName ;