2007-05-19 18:54:39 +02:00
|
|
|
function [m0,s0] = compute_mh_covariance_matrix()
|
2008-01-17 12:10:12 +01:00
|
|
|
|
|
|
|
% function [m0,s0] = compute_mh_covariance_matrix()
|
2007-05-19 18:54:39 +02:00
|
|
|
% Estimation of the posterior covariance matrix and expectation.
|
2006-07-28 12:00:31 +02:00
|
|
|
%
|
|
|
|
% INPUTS
|
|
|
|
% None.
|
|
|
|
%
|
2007-05-19 18:54:39 +02:00
|
|
|
% OUTPUTS
|
|
|
|
% o m0 [double] (n*1) vector, posterior expectation of the parameters.
|
|
|
|
% o s0 [double] (n*n) matrix, posterior covariance of the parameters
|
|
|
|
% (computed from previous metropolis hastings).
|
2006-07-28 12:00:31 +02:00
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% None.
|
|
|
|
%
|
2008-01-17 12:10:12 +01:00
|
|
|
% part of DYNARE, copyright Dynare Team (2006-2008)
|
2006-07-28 12:00:31 +02:00
|
|
|
% Gnu Public License.
|
2008-01-17 12:10:12 +01:00
|
|
|
|
2007-05-19 18:54:39 +02:00
|
|
|
global M_ options_ estim_params_
|
2006-07-28 12:00:31 +02:00
|
|
|
|
2007-05-19 18:54:39 +02:00
|
|
|
n = estim_params_.np + ...
|
|
|
|
estim_params_.nvn+ ...
|
|
|
|
estim_params_.ncx+ ...
|
|
|
|
estim_params_.ncn+ ...
|
|
|
|
estim_params_.nvx;
|
2006-07-28 12:00:31 +02:00
|
|
|
nblck = options_.mh_nblck;
|
|
|
|
|
|
|
|
MhDirectoryName = CheckPath('metropolis');
|
|
|
|
load([ MhDirectoryName '/' M_.fname '_mh_history'])
|
|
|
|
|
|
|
|
FirstMhFile = record.KeepedDraws.FirstMhFile;
|
2007-05-19 18:54:39 +02:00
|
|
|
FirstLine = record.KeepedDraws.FirstLine;
|
2006-07-28 12:00:31 +02:00
|
|
|
TotalNumberOfMhFiles = sum(record.MhDraws(:,2));
|
|
|
|
|
2007-05-20 08:55:40 +02:00
|
|
|
params = zeros(1,n);
|
|
|
|
oldlogpo2 = -Inf;
|
2007-05-19 18:54:39 +02:00
|
|
|
offset = 0;
|
2007-05-20 08:55:40 +02:00
|
|
|
m0 = zeros(n,1);
|
|
|
|
s0 = zeros(n,n);
|
|
|
|
|
2006-07-28 12:00:31 +02:00
|
|
|
for n = FirstMhFile:TotalNumberOfMhFiles
|
|
|
|
for b = 1:nblck
|
|
|
|
load([ MhDirectoryName '/' M_.fname '_mh' int2str(n) '_blck' int2str(b)],'x2','logpo2');
|
2007-05-19 18:54:39 +02:00
|
|
|
[tmp,idx] = max(logpo2);
|
|
|
|
if tmp>oldlogpo2
|
|
|
|
oldlogpo2 = tmp;
|
|
|
|
params = x2(idx,:);
|
|
|
|
end
|
|
|
|
[m0,s0,offset] = recursive_moments(m0,s0,x2(FirstLine,:),offset);
|
2006-07-28 12:00:31 +02:00
|
|
|
end
|
2007-05-19 18:54:39 +02:00
|
|
|
FirstLine = 1;
|
2006-07-28 12:00:31 +02:00
|
|
|
end
|
2007-05-19 18:54:39 +02:00
|
|
|
|
|
|
|
xparam1 = params';
|
|
|
|
hh = inv(s0);
|
|
|
|
fval = oldlogpo2;
|
|
|
|
|
2007-05-20 08:55:40 +02:00
|
|
|
save([M_.fname '_mh_mode'],'xparam1','hh','fval');
|