From fa1f7794d5a85de8c805947f600873032b3cf6bc Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sat, 9 May 2015 15:13:59 +0200 Subject: [PATCH] Delete stale files from previous MCMC runs Closes #566. Also adds cosmetic changes to headers of affected routines --- matlab/PosteriorIRF.m | 24 +++++++------- ...ional_variance_decomposition_mc_analysis.m | 22 ++++++++++++- matlab/covariance_mc_analysis.m | 20 +++++++++-- ...tical_conditional_variance_decomposition.m | 12 ++++++- .../dsge_simulated_theoretical_correlation.m | 33 ++++++++++++------- .../dsge_simulated_theoretical_covariance.m | 10 +++++- ...lated_theoretical_variance_decomposition.m | 12 +++++-- matlab/utilities/general/delete_stale_file.m | 26 +++++++++++++++ matlab/variance_decomposition_mc_analysis.m | 24 +++++++++++++- 9 files changed, 150 insertions(+), 33 deletions(-) create mode 100644 matlab/utilities/general/delete_stale_file.m diff --git a/matlab/PosteriorIRF.m b/matlab/PosteriorIRF.m index fc1c3bcf5..47da7e86f 100644 --- a/matlab/PosteriorIRF.m +++ b/matlab/PosteriorIRF.m @@ -16,7 +16,7 @@ function PosteriorIRF(type) % functions associated with it(the _core1 and _core2). % See also the comments random_walk_metropolis_hastings.m funtion. -% Copyright (C) 2006-2013 Dynare Team +% Copyright (C) 2006-2015 Dynare Team % % This file is part of Dynare. % @@ -93,8 +93,15 @@ elseif strcmpi(type,'gsa') else MhDirectoryName = CheckPath('prior',M_.dname); end -delete([MhDirectoryName filesep M_.fname '_IRF_DSGEs*.mat']); -delete([MhDirectoryName filesep M_.fname '_IRF_BVARDSGEs*.mat']); + +%delete old stale files before creating new ones +delete_stale_file([MhDirectoryName filesep M_.fname '_IRF_DSGEs*.mat']); +delete_stale_file([MhDirectoryName filesep M_.fname '_IRF_BVARDSGEs*.mat']); +delete_stale_file([MhDirectoryName filesep M_.fname '_irf_dsge*.mat']); +delete_stale_file([MhDirectoryName filesep M_.fname '_irf_bvardsge*.mat']); +delete_stale_file([MhDirectoryName filesep M_.fname '_param_irf*.mat']); + + if strcmpi(type,'posterior') B = options_.sub_draws; options_.B = B; @@ -112,16 +119,7 @@ else% type = 'prior' B = options_.prior_draws; options_.B = B; end -try - delete([MhDirectoryName filesep M_.fname '_irf_dsge*.mat']) -catch - disp('No _IRFs (dsge) files to be deleted!') -end -try - delete([MhDirectoryName filesep M_.fname '_irf_bvardsge*.mat']) -catch - disp('No _IRFs (bvar-dsge) files to be deleted!') -end + irun = 0; IRUN = 0; irun2 = 0; diff --git a/matlab/conditional_variance_decomposition_mc_analysis.m b/matlab/conditional_variance_decomposition_mc_analysis.m index 004239800..22273f2be 100644 --- a/matlab/conditional_variance_decomposition_mc_analysis.m +++ b/matlab/conditional_variance_decomposition_mc_analysis.m @@ -1,7 +1,27 @@ function oo_ = ... conditional_variance_decomposition_mc_analysis(NumberOfSimulations, type, dname, fname, Steps, exonames, exo, var_list, endogenous_variable_index, mh_conf_sig, oo_) % This function analyses the (posterior or prior) distribution of the -% endogenous conditional variance decomposition. +% endogenous variables' conditional variance decomposition. +% +% INPUTS +% NumberOfSimulations [integer] scalar, number of simulations. +% type [string] 'prior' or 'posterior' +% dname [string] directory name where to save +% fname [string] name of the mod-file +% Steps [integers] horizons at which to conduct decomposition +% exonames [string] (n_exo*char_length) character array with names of exogenous variables +% exo [string] name of current exogenous +% variable +% var_list [string] (n_endo*char_length) character array with name +% of endogenous variables +% endogenous_variable_index [integer] index of the current +% endogenous variable +% mh_conf_sig [double] 2 by 1 vector with upper +% and lower bound of HPD intervals +% oo_ [structure] Dynare structure where the results are saved. +% +% OUTPUTS +% oo_ [structure] Dynare structure where the results are saved. % Copyright (C) 2009-2013 Dynare Team % diff --git a/matlab/covariance_mc_analysis.m b/matlab/covariance_mc_analysis.m index a24ec665e..d98992f0e 100644 --- a/matlab/covariance_mc_analysis.m +++ b/matlab/covariance_mc_analysis.m @@ -1,8 +1,24 @@ function oo_ = covariance_mc_analysis(NumberOfSimulations,type,dname,fname,vartan,nvar,var1,var2,mh_conf_sig,oo_) % This function analyses the (posterior or prior) distribution of the -% endogenous variables covariance matrix. +% endogenous variables' covariance matrix. +% +% INPUTS +% NumberOfSimulations [integer] scalar, number of simulations. +% type [string] 'prior' or 'posterior' +% dname [string] directory name where to save +% fname [string] name of the mod-file +% vartan [char] array of characters (with nvar rows). +% nvar [integer] nvar is the number of stationary variables. +% var1 [string] name of the first variable +% var2 [string] name of the second variable +% mh_conf_sig [double] 2 by 1 vector with upper +% and lower bound of HPD intervals +% oo_ [structure] Dynare structure where the results are saved. +% +% OUTPUTS +% oo_ [structure] Dynare structure where the results are saved. -% Copyright (C) 2008-2013 Dynare Team +% Copyright (C) 2008-2015 Dynare Team % % This file is part of Dynare. % diff --git a/matlab/dsge_simulated_theoretical_conditional_variance_decomposition.m b/matlab/dsge_simulated_theoretical_conditional_variance_decomposition.m index 7ef623b81..1c0441361 100644 --- a/matlab/dsge_simulated_theoretical_conditional_variance_decomposition.m +++ b/matlab/dsge_simulated_theoretical_conditional_variance_decomposition.m @@ -1,10 +1,13 @@ function [nvar,vartan,NumberOfConditionalDecompFiles] = ... dsge_simulated_theoretical_conditional_variance_decomposition(SampleSize,Steps,M_,options_,oo_,type) +% function [nvar,vartan,NumberOfConditionalDecompFiles] = ... +% dsge_simulated_theoretical_conditional_variance_decomposition(SampleSize,Steps,M_,options_,oo_,type) % This function computes the posterior or prior distribution of the conditional variance % decomposition of the endogenous variables (or a subset of the endogenous variables). % % INPUTS % SampleSize [integer] scalar, number of simulations. +% Steps [integers] horizons at which to conduct decomposition % M_ [structure] Dynare structure describing the model. % options_ [structure] Dynare structure defining global options. % oo_ [structure] Dynare structure where the results are saved. @@ -16,7 +19,7 @@ function [nvar,vartan,NumberOfConditionalDecompFiles] = ... % vartan [char] array of characters (with nvar rows). % NumberOfConditionalDecompFiles [integer] scalar, number of prior or posterior data files (for covariance). -% Copyright (C) 2009-2012 Dynare Team +% Copyright (C) 2009-2015 Dynare Team % % This file is part of Dynare. % @@ -47,6 +50,13 @@ else error() end +%delete old stale files before creating new ones +if posterior + delete_stale_file([M_.dname '/metropolis/' M_.fname '_PosteriorConditionalVarianceDecomposition*']) +else + delete_stale_file([M_.dname '/prior/moments/' M_.fname '_PriorConditionalVarianceDecomposition*']) +end + % Set varlist (vartan) if ~posterior if isfield(options_,'varlist') diff --git a/matlab/dsge_simulated_theoretical_correlation.m b/matlab/dsge_simulated_theoretical_correlation.m index 59ffa4e4e..265336dbb 100644 --- a/matlab/dsge_simulated_theoretical_correlation.m +++ b/matlab/dsge_simulated_theoretical_correlation.m @@ -1,21 +1,23 @@ function [nvar,vartan,CorrFileNumber] = dsge_simulated_theoretical_correlation(SampleSize,nar,M_,options_,oo_,type) +% function [nvar,vartan,CorrFileNumber] = dsge_simulated_theoretical_correlation(SampleSize,nar,M_,options_,oo_,type) % This function computes the posterior or prior distribution of the endogenous -% variables second order moments. +% variables' second order moments. % % INPUTS -% SampleSize [integer] -% nar [integer] -% M_ [structure] -% options_ [structure] -% oo_ [structure] -% type [string] +% SampleSize [integer] scalar, number of simulations. +% nar [integer] maximum number of autocorrelations to +% consider +% M_ [structure] Dynare structure describing the model. +% options_ [structure] Dynare structure defining global options +% oo_ [structure] Dynare structure where the results are saved. +% type [string] 'prior' or 'posterior' % % OUTPUTS -% nvar [integer] -% vartan [char] -% CorrFileNumber [integer] - -% Copyright (C) 2007-2012 Dynare Team +% nvar [integer] nvar is the number of stationary variables. +% vartan [char] array of characters (with nvar rows). +% CorrFileNumber [integer] scalar, number of prior or posterior data files (for correlation). + +% Copyright (C) 2007-2015 Dynare Team % % This file is part of Dynare. % @@ -48,6 +50,13 @@ else end NumberOfDrawsFiles = length(DrawsFiles); +%delete old stale files before creating new ones +if posterior + delete_stale_file([M_.dname '/metropolis/' M_.fname '_PosteriorCorrelations*']); +else + delete_stale_file([M_.dname '/prior/moments/' M_.fname '_PriorCorrelations*']); +end + % Set varlist (vartan) if ~posterior if isfield(options_,'varlist') diff --git a/matlab/dsge_simulated_theoretical_covariance.m b/matlab/dsge_simulated_theoretical_covariance.m index 5d39e77fb..38ef7c3b6 100644 --- a/matlab/dsge_simulated_theoretical_covariance.m +++ b/matlab/dsge_simulated_theoretical_covariance.m @@ -1,4 +1,5 @@ function [nvar,vartan,CovarFileNumber] = dsge_simulated_theoretical_covariance(SampleSize,M_,options_,oo_,type) +% function [nvar,vartan,CovarFileNumber] = dsge_simulated_theoretical_covariance(SampleSize,M_,options_,oo_,type) % This function computes the posterior or prior distribution of the endogenous % variables second order moments. % @@ -15,7 +16,7 @@ function [nvar,vartan,CovarFileNumber] = dsge_simulated_theoretical_covariance(S % vartan [char] array of characters (with nvar rows). % CovarFileNumber [integer] scalar, number of prior or posterior data files (for covariance). -% Copyright (C) 2007-2012 Dynare Team +% Copyright (C) 2007-2015 Dynare Team % % This file is part of Dynare. % @@ -48,6 +49,13 @@ else end NumberOfDrawsFiles = length(DrawsFiles); +%delete old stale files before creating new ones +if posterior + delete_stale_file([M_.dname '/metropolis/' M_.fname '_Posterior2ndOrderMoments*']) +else + delete_stale_file([M_.dname '/prior/moments/' M_.fname '_Prior2ndOrderMoments*']) +end + % Set varlist (vartan) if ~posterior if isfield(options_,'varlist') diff --git a/matlab/dsge_simulated_theoretical_variance_decomposition.m b/matlab/dsge_simulated_theoretical_variance_decomposition.m index 7059e6d13..74335840e 100644 --- a/matlab/dsge_simulated_theoretical_variance_decomposition.m +++ b/matlab/dsge_simulated_theoretical_variance_decomposition.m @@ -1,5 +1,7 @@ function [nvar,vartan,NumberOfDecompFiles] = ... dsge_simulated_theoretical_variance_decomposition(SampleSize,M_,options_,oo_,type) +% function [nvar,vartan,NumberOfDecompFiles] = ... +% dsge_simulated_theoretical_variance_decomposition(SampleSize,M_,options_,oo_,type) % This function computes the posterior or prior distribution of the variance % decomposition of the observed endogenous variables. % @@ -16,7 +18,7 @@ function [nvar,vartan,NumberOfDecompFiles] = ... % vartan [char] array of characters (with nvar rows). % CovarFileNumber [integer] scalar, number of prior or posterior data files (for covariance). -% Copyright (C) 2007-2012 Dynare Team +% Copyright (C) 2007-2015 Dynare Team % % This file is part of Dynare. % @@ -47,7 +49,13 @@ else disp('dsge_simulated_theoretical_variance_decomposition:: Unknown type!') error() end -NumberOfDrawsFiles = length(DrawsFiles); + +%delete old stale files before creating new ones +if posterior + delete_stale_file([M_.dname '/metropolis/' M_.fname '_PosteriorVarianceDecomposition*']); +else + delete_stale_file([M_.dname '/prior/moments/' M_.fname '_PosteriorVarianceDecomposition*']); +end % Set varlist (vartan) if ~posterior diff --git a/matlab/utilities/general/delete_stale_file.m b/matlab/utilities/general/delete_stale_file.m new file mode 100644 index 000000000..8ac8b7996 --- /dev/null +++ b/matlab/utilities/general/delete_stale_file.m @@ -0,0 +1,26 @@ +function delete_stale_file(fname) +% function delete_old_files(fname) +% Checks for presence of files and deletes them if necessary + +% Copyright (C) 2015 Dynare Team +% +% 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 . + +Files_info = dir(fname); +if length(Files_info)>0 + delete(fname) +end + diff --git a/matlab/variance_decomposition_mc_analysis.m b/matlab/variance_decomposition_mc_analysis.m index b4f3f570d..798b28afe 100644 --- a/matlab/variance_decomposition_mc_analysis.m +++ b/matlab/variance_decomposition_mc_analysis.m @@ -1,6 +1,28 @@ function oo_ = variance_decomposition_mc_analysis(NumberOfSimulations,type,dname,fname,exonames,exo,vartan,var,mh_conf_sig,oo_) +% function oo_ = variance_decomposition_mc_analysis(NumberOfSimulations,type,dname,fname,exonames,exo,vartan,var,mh_conf_sig,oo_) % This function analyses the (posterior or prior) distribution of the -% endogenous variance decomposition. +% endogenous variables' variance decomposition. +% +% INPUTS +% NumberOfSimulations [integer] scalar, number of simulations. +% type [string] 'prior' or 'posterior' +% dname [string] directory name where to save +% fname [string] name of the mod-file +% exonames [string] (n_exo*char_length) character array with names of exogenous variables +% exo [string] name of current exogenous +% variable +% vartan [string] (n_endo*char_length) character array with name +% of endogenous variables +% var [integer] index of the current +% endogenous variable +% mh_conf_sig [double] 2 by 1 vector with upper +% and lower bound of HPD intervals +% oo_ [structure] Dynare structure where the results are saved. +% +% OUTPUTS +% oo_ [structure] Dynare structure where the results are saved. + + % Copyright (C) 2008-2013 Dynare Team %