Home > matlab > dsge_simulated_theoretical_correlation.m

dsge_simulated_theoretical_correlation

PURPOSE ^

This function computes the posterior or prior distribution of the endogenous

SYNOPSIS ^

function [nvar,vartan,CorrFileNumber] = dsge_simulated_theoretical_correlation(SampleSize,nar,M_,options_,oo_,type)

DESCRIPTION ^

 This function computes the posterior or prior distribution of the endogenous
 variables second order moments.

 INPUTS
   SampleSize   [integer]
   nar          [integer]
   M_           [structure]
   options_     [structure]
   oo_          [structure]
   type         [string]

 OUTPUTS
   nvar           [integer]
   vartan         [char]
   CorrFileNumber [integer]

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [nvar,vartan,CorrFileNumber] = dsge_simulated_theoretical_correlation(SampleSize,nar,M_,options_,oo_,type)
0002 % This function computes the posterior or prior distribution of the endogenous
0003 % variables second order moments.
0004 %
0005 % INPUTS
0006 %   SampleSize   [integer]
0007 %   nar          [integer]
0008 %   M_           [structure]
0009 %   options_     [structure]
0010 %   oo_          [structure]
0011 %   type         [string]
0012 %
0013 % OUTPUTS
0014 %   nvar           [integer]
0015 %   vartan         [char]
0016 %   CorrFileNumber [integer]
0017 
0018 % Copyright (C) 2007-2009 Dynare Team
0019 %
0020 % This file is part of Dynare.
0021 %
0022 % Dynare is free software: you can redistribute it and/or modify
0023 % it under the terms of the GNU General Public License as published by
0024 % the Free Software Foundation, either version 3 of the License, or
0025 % (at your option) any later version.
0026 %
0027 % Dynare is distributed in the hope that it will be useful,
0028 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0029 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0030 % GNU General Public License for more details.
0031 %
0032 % You should have received a copy of the GNU General Public License
0033 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0034 
0035 nodecomposition = 1;
0036 
0037 % Get informations about the _posterior_draws files.
0038 if strcmpi(type,'posterior')
0039     DrawsFiles = dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]);
0040     posterior = 1;
0041 elseif strcmpi(type,'prior')
0042     DrawsFiles = dir([M_.dname '/prior/draws/' type '_draws*' ]);
0043     CheckPath('prior/moments',M_.dname);
0044     posterior = 0;
0045 else
0046     disp('dsge_simulated_theoretical_correlation:: Unknown type!');
0047     error()
0048 end
0049 NumberOfDrawsFiles = length(DrawsFiles);
0050 
0051 % Set varlist (vartan)
0052 if ~posterior
0053     if isfield(options_,'varlist')
0054         temp = options_.varlist;
0055     end
0056     options_.varlist = options_.prior_analysis_endo_var_list;
0057 end
0058 [ivar,vartan, options_] = set_stationary_variables_list(options_, M_);
0059 if ~posterior
0060     if exist('temp','var')
0061         options_.varlist = temp;
0062     end
0063 end
0064 nvar = length(ivar);
0065 
0066 % Set the size of the auto-correlation function to nar.
0067 oldnar = options_.ar;
0068 options_.ar = nar;
0069 
0070 % Number of lines in posterior data files.
0071 MaXNumberOfCorrLines = ceil(options_.MaxNumberOfBytes/(nvar*nvar*nar)/8);
0072 
0073 if SampleSize<=MaXNumberOfCorrLines
0074     Correlation_array = zeros(SampleSize,nvar,nvar,nar);
0075     NumberOfCorrFiles = 1;
0076 else
0077     Correlation_array = zeros(MaXNumberOfCorrLines,nvar,nvar,nar);
0078     NumberOfLinesInTheLastCorrFile = mod(SampleSize,MaXNumberOfCorrLines);
0079     NumberOfCorrFiles = ceil(SampleSize/MaXNumberOfCorrLines);
0080 end
0081 
0082 NumberOfCorrLines = rows(Correlation_array);
0083 CorrFileNumber = 1;
0084 
0085 % Compute 2nd order moments and save them in *_[Posterior, Prior]Correlations* files
0086 linea = 0;
0087 for file = 1:NumberOfDrawsFiles
0088     if posterior
0089         load([M_.dname '/metropolis/' DrawsFiles(file).name ]);
0090     else
0091         load([M_.dname '/prior/draws/' DrawsFiles(file).name]);
0092     end
0093     NumberOfDraws = rows(pdraws);
0094     isdrsaved = columns(pdraws)-1;
0095     for linee = 1:NumberOfDraws
0096         linea = linea+1;
0097         if isdrsaved
0098             dr = pdraws{linee,2};
0099         else
0100             set_parameters(pdraws{linee,1});
0101             [dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_);
0102         end
0103         tmp = th_autocovariances(dr,ivar,M_,options_,nodecomposition);
0104         for i=1:nar
0105             Correlation_array(linea,:,:,i) = tmp{i+1};
0106         end
0107         if linea == NumberOfCorrLines
0108             if posterior
0109                 save([ M_.dname '/metropolis/' M_.fname '_PosteriorCorrelations' int2str(CorrFileNumber) '.mat' ],'Correlation_array');
0110             else
0111                 save([ M_.dname '/prior/moments/' M_.fname '_PriorCorrelations' int2str(CorrFileNumber) '.mat' ],'Correlation_array');
0112             end
0113             CorrFileNumber = CorrFileNumber + 1;
0114             linea = 0;
0115             test = CorrFileNumber-NumberOfCorrFiles;
0116             if ~test% Prepare the last round...
0117                 Correlation_array = zeros(NumberOfLinesInTheLastCorrFile,nvar,nvar,nar);
0118                 NumberOfCorrLines = NumberOfLinesInTheLastCorrFile;
0119                 CorrFileNumber = CorrFileNumber - 1;
0120             elseif test<0;
0121                 Correlation_array = zeros(MaXNumberOfCorrLines,nvar,nvar,nar);
0122             else
0123                 clear('Correlation_array');
0124             end
0125         end
0126     end
0127 end
0128 
0129 options_.ar = oldnar;

Generated on Mon 21-May-2012 02:42:43 by m2html © 2005