1) check for restricted or extened var list

2) allow proper working will all GSA type of sample: prior, MC, posterior
time-shift
Jukka Heikkonen 2014-09-12 14:49:25 +02:00
parent 8655df67a9
commit 55b6d0eb93
2 changed files with 44 additions and 20 deletions

View File

@ -42,8 +42,7 @@ endo_prior_restrictions.irf= DynareOptions.endogenous_prior_restrictions.irf;
endo_prior_restrictions.moment= DynareOptions.endogenous_prior_restrictions.moment; endo_prior_restrictions.moment= DynareOptions.endogenous_prior_restrictions.moment;
if ~isempty(endo_prior_restrictions.irf), if ~isempty(endo_prior_restrictions.irf),
data_irf=cell(size(endo_prior_restrictions.irf,1),1); data_irf=cell(size(endo_prior_restrictions.irf,1),1);
if DynareOptions.order>1, if DynareOptions.order>1,
error('The algorithm for prior (sign) restrictions on irf''s is currently restricted to first-order decision rules') error('The algorithm for prior (sign) restrictions on irf''s is currently restricted to first-order decision rules')
return return
@ -53,7 +52,18 @@ if ~isempty(endo_prior_restrictions.irf),
[T,R,SteadyState,infox,Model,DynareOptions,DynareResults] = dynare_resolve(Model,DynareOptions,DynareResults); [T,R,SteadyState,infox,Model,DynareOptions,DynareResults] = dynare_resolve(Model,DynareOptions,DynareResults);
else % check if T and R are given in the restricted form!!! else % check if T and R are given in the restricted form!!!
if size(T,1)<size(varlist,1), if size(T,1)<size(varlist,1),
varlist=varlist(DynareResults.dr.restrict_var_list,:); varlist=varlist(DynareResults.dr.restrict_var_list,:);
end
% check if endo_prior_restrictions.irf{:,1} variables are in varlist
varlistok=1;
for j=1:size(endo_prior_restrictions.irf,1)
if isempty(strmatch(endo_prior_restrictions.irf{j,1},varlist,'exact'))
varlistok=0;
end
end
if ~varlistok
varlist=Model.endo_names(DynareResults.dr.order_var,:);
[T,R,SteadyState,infox,Model,DynareOptions,DynareResults] = dynare_resolve(Model,DynareOptions,DynareResults);
end end
end end
NT=1; NT=1;

View File

@ -26,16 +26,29 @@ indx_moment = [];
skipline() skipline()
disp('Sensitivity analysis for calibration criteria') disp('Sensitivity analysis for calibration criteria')
filetoload=[OutputDirectoryName '/' fname_ '_prior']; if DynareOptions.opt_gsa.ppost,
load(filetoload,'lpmat','lpmat0','istable','iunstable','iindeterm','iwrong' ,'infox') filetoload=dir([Model.dname filesep 'metropolis' filesep fname_ '_param_irf*.mat']);
if ~isempty(lpmat0), lpmat=[];
lpmatx=lpmat0(istable,:); for j=1:length(filetoload),
load([Model.dname filesep 'metropolis' filesep fname_ '_param_irf',int2str(j),'.mat'])
lpmat = [lpmat; stock];
clear stock
end
type = 'post';
else else
lpmatx=[]; if DynareOptions.opt_gsa.pprior
filetoload=[OutputDirectoryName '/' fname_ '_prior'];
load(filetoload,'lpmat','lpmat0','istable','iunstable','iindeterm','iwrong' ,'infox')
lpmat = [lpmat0 lpmat];
type = 'prior';
else
filetoload=[OutputDirectoryName '/' fname_ '_mc'];
load(filetoload,'lpmat','lpmat0','istable','iunstable','iindeterm','iwrong' ,'infox')
lpmat = [lpmat0 lpmat];
type = 'mc';
end
end end
[Nsam, np] = size(lpmat); [Nsam, np] = size(lpmat);
nshock = size(lpmat0,2);
npT = np+nshock;
nbr_irf_restrictions = size(DynareOptions.endogenous_prior_restrictions.irf,1); nbr_irf_restrictions = size(DynareOptions.endogenous_prior_restrictions.irf,1);
mat_irf=cell(nbr_irf_restrictions,1); mat_irf=cell(nbr_irf_restrictions,1);
@ -51,7 +64,7 @@ end
irestrictions = [1:Nsam]; irestrictions = [1:Nsam];
for j=1:Nsam, for j=1:Nsam,
Model = set_all_parameters([lpmat0(j,:) lpmat(j,:)]',EstimatedParameters,Model); Model = set_all_parameters(lpmat(j,:)',EstimatedParameters,Model);
[Tt,Rr,SteadyState,info] = dynare_resolve(Model,DynareOptions,DynareResults,'restrict'); [Tt,Rr,SteadyState,info] = dynare_resolve(Model,DynareOptions,DynareResults,'restrict');
if info(1)==0, if info(1)==0,
[info, info_irf, info_moment, data_irf, data_moment]=endogenous_prior_restrictions(Tt,Rr,Model,DynareOptions,DynareResults); [info, info_irf, info_moment, data_irf, data_moment]=endogenous_prior_restrictions(Tt,Rr,Model,DynareOptions,DynareResults);
@ -72,12 +85,13 @@ for j=1:Nsam,
end end
end end
irestrictions=irestrictions(find(irestrictions)); irestrictions=irestrictions(find(irestrictions));
xmat=[lpmat0(irestrictions,:) lpmat(irestrictions,:)]; xmat=lpmat(irestrictions,:);
skipline() skipline()
save([OutputDirectoryName,filesep,fname_,'_',type,'_restrictions'],'xmat','mat_irf','mat_moment','irestrictions','indx_irf','indx_moment');
if ~isempty(indx_irf), if ~isempty(indx_irf),
indx_irf = indx_irf(irestrictions,:); indx_irf = indx_irf(irestrictions,:);
h1=dyn_figure(DynareOptions,'name','Evaluation of irf restrictions'); h1=dyn_figure(DynareOptions,'name',[type ' evaluation of irf restrictions']);
nrow=ceil(sqrt(nbr_irf_restrictions)); nrow=ceil(sqrt(nbr_irf_restrictions));
ncol=nrow; ncol=nrow;
if nrow*(nrow-1)>nbr_irf_restrictions, if nrow*(nrow-1)>nbr_irf_restrictions,
@ -108,21 +122,21 @@ if ~isempty(indx_irf),
indx2 = find(indx_irf(:,ij)~=0); indx2 = find(indx_irf(:,ij)~=0);
atitle=[DynareOptions.endogenous_prior_restrictions.irf{ij,1},' vs ',DynareOptions.endogenous_prior_restrictions.irf{ij,2}, '(', leg,')']; atitle=[DynareOptions.endogenous_prior_restrictions.irf{ij,1},' vs ',DynareOptions.endogenous_prior_restrictions.irf{ij,2}, '(', leg,')'];
fprintf(['%4.1f%% of the prior support matches IRF ',atitle,' inside [%4.1f, %4.1f]\n'],length(indx1)/length(irestrictions)*100,DynareOptions.endogenous_prior_restrictions.irf{ij,4}) fprintf(['%4.1f%% of the prior support matches IRF ',atitle,' inside [%4.1f, %4.1f]\n'],length(indx1)/length(irestrictions)*100,DynareOptions.endogenous_prior_restrictions.irf{ij,4})
aname=['irf_calib_',int2str(ij)]; aname=[type '_irf_calib_',int2str(ij)];
atitle=['IRF Calib: Parameter(s) driving ',DynareOptions.endogenous_prior_restrictions.irf{ij,1},' vs ',DynareOptions.endogenous_prior_restrictions.irf{ij,2}, '(', leg,')']; atitle=[type ' IRF Calib: Parameter(s) driving ',DynareOptions.endogenous_prior_restrictions.irf{ij,1},' vs ',DynareOptions.endogenous_prior_restrictions.irf{ij,2}, '(', leg,')'];
[proba, dproba] = stab_map_1(xmat, indx1, indx2, aname, 0); [proba, dproba] = stab_map_1(xmat, indx1, indx2, aname, 0);
indplot=find(proba<pvalue_ks); indplot=find(proba<pvalue_ks);
if ~isempty(indplot) if ~isempty(indplot)
stab_map_1(xmat, indx1, indx2, aname, 1, indplot, OutputDirectoryName,[],atitle); stab_map_1(xmat, indx1, indx2, aname, 1, indplot, OutputDirectoryName,[],atitle);
end end
end end
dyn_saveas(h1,[OutputDirectoryName,filesep,fname_,'_irf_restrictions'],DynareOptions); dyn_saveas(h1,[OutputDirectoryName,filesep,fname_,'_',type,'_irf_restrictions'],DynareOptions);
skipline() skipline()
end end
if ~isempty(indx_moment) if ~isempty(indx_moment)
indx_moment = indx_moment(irestrictions,:); indx_moment = indx_moment(irestrictions,:);
h2=dyn_figure(DynareOptions,'name','Evaluation of moment restrictions'); h2=dyn_figure(DynareOptions,'name',[type ' evaluation of moment restrictions']);
nrow=ceil(sqrt(nbr_moment_restrictions)); nrow=ceil(sqrt(nbr_moment_restrictions));
ncol=nrow; ncol=nrow;
if nrow*(nrow-1)>nbr_moment_restrictions, if nrow*(nrow-1)>nbr_moment_restrictions,
@ -153,15 +167,15 @@ if ~isempty(indx_moment)
indx2 = find(indx_moment(:,ij)~=0); indx2 = find(indx_moment(:,ij)~=0);
atitle=[DynareOptions.endogenous_prior_restrictions.moment{ij,1},' vs ',DynareOptions.endogenous_prior_restrictions.moment{ij,2}, '(', leg,')']; atitle=[DynareOptions.endogenous_prior_restrictions.moment{ij,1},' vs ',DynareOptions.endogenous_prior_restrictions.moment{ij,2}, '(', leg,')'];
fprintf(['%4.1f%% of the prior support matches MOMENT ',atitle,' inside [%4.1f, %4.1f]\n'],length(indx1)/length(irestrictions)*100,DynareOptions.endogenous_prior_restrictions.moment{ij,4}) fprintf(['%4.1f%% of the prior support matches MOMENT ',atitle,' inside [%4.1f, %4.1f]\n'],length(indx1)/length(irestrictions)*100,DynareOptions.endogenous_prior_restrictions.moment{ij,4})
aname=['moment_calib_',int2str(ij)]; aname=[type '_moment_calib_',int2str(ij)];
atitle=['MOMENT Calib: Parameter(s) driving ',DynareOptions.endogenous_prior_restrictions.moment{ij,1},' vs ',DynareOptions.endogenous_prior_restrictions.moment{ij,2}, '(', leg,')']; atitle=[type ' MOMENT Calib: Parameter(s) driving ',DynareOptions.endogenous_prior_restrictions.moment{ij,1},' vs ',DynareOptions.endogenous_prior_restrictions.moment{ij,2}, '(', leg,')'];
[proba, dproba] = stab_map_1(xmat, indx1, indx2, aname, 0); [proba, dproba] = stab_map_1(xmat, indx1, indx2, aname, 0);
indplot=find(proba<pvalue_ks); indplot=find(proba<pvalue_ks);
if ~isempty(indplot) if ~isempty(indplot)
stab_map_1(xmat, indx1, indx2, aname, 1, indplot, OutputDirectoryName,[],atitle); stab_map_1(xmat, indx1, indx2, aname, 1, indplot, OutputDirectoryName,[],atitle);
end end
end end
dyn_saveas(h2,[OutputDirectoryName,filesep,fname_,'_moment_restrictions'],DynareOptions); dyn_saveas(h2,[OutputDirectoryName,filesep,fname_,'_',type,'_moment_restrictions'],DynareOptions);
skipline() skipline()
end end
return return