Make naming in GetPosteriorMeanVariance.m more expressive

time-shift
Johannes Pfeifer 2016-10-03 22:36:25 +02:00
parent b2984f43c9
commit d5233336b5
1 changed files with 17 additions and 18 deletions

View File

@ -1,6 +1,6 @@
function [mean,variance] = GetPosteriorMeanVariance(M,drop) function [mean,variance] = GetPosteriorMeanVariance(M,drop)
% Copyright (C) 2012, 2013 Dynare Team % Copyright (C) 2012-2016 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
@ -26,29 +26,28 @@ function [mean,variance] = GetPosteriorMeanVariance(M,drop)
NbrBlocks = record.Nblck; NbrBlocks = record.Nblck;
mean = 0; mean = 0;
variance = 0; variance = 0;
z = [];
nkept = 0; NbrKeptDraws = 0;
for i=1:NbrBlocks for i=1:NbrBlocks
n = 0; NbrDrawsCurrentBlock = 0;
for j=1:NbrFiles for j=1:NbrFiles
o = load([BaseName '_mh' int2str(j) '_blck' int2str(i)]); o = load([BaseName '_mh' int2str(j) '_blck' int2str(i),'.mat']);
m = size(o.x2,1); NbrDrawsCurrentFile = size(o.x2,1);
if n + m <= drop*NbrDraws if NbrDrawsCurrentBlock + NbrDrawsCurrentFile <= drop*NbrDraws
n = n + m; NbrDrawsCurrentBlock = NbrDrawsCurrentBlock + NbrDrawsCurrentFile;
continue continue
elseif n < drop*NbrDraws elseif NbrDrawsCurrentBlock < drop*NbrDraws
k = ceil(drop*NbrDraws - n + 1); FirstDraw = ceil(drop*NbrDraws - NbrDrawsCurrentBlock + 1);
x2 = o.x2(k:end,:); x2 = o.x2(FirstDraw:end,:);
else else
x2 = o.x2; x2 = o.x2;
end end
z =[z; x2]; NbrKeptDrawsCurrentFile = size(x2,1);
p = size(x2,1); %recursively compute mean and variance
mean = (nkept*mean + sum(x2)')/(nkept+p); mean = (NbrKeptDraws*mean + sum(x2)')/(NbrKeptDraws+NbrKeptDrawsCurrentFile);
x = bsxfun(@minus,x2,mean'); x2Demeaned = bsxfun(@minus,x2,mean');
variance = (nkept*variance + x'*x)/(nkept+p); variance = (NbrKeptDraws*variance + x2Demeaned'*x2Demeaned)/(NbrKeptDraws+NbrKeptDrawsCurrentFile);
n = n + m; NbrDrawsCurrentBlock = NbrDrawsCurrentBlock + NbrDrawsCurrentFile;
nkept = nkept + p; NbrKeptDraws = NbrKeptDraws + NbrKeptDrawsCurrentFile;
end end
end end