Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dóra Kocsis
dynare
Commits
7ddab426
Commit
7ddab426
authored
Apr 23, 2012
by
MichelJuillard
Browse files
adding missing function to compute mean and covariance matrix of
Metropolis sample
parent
8d4834de
Changes
1
Hide whitespace changes
Inline
Side-by-side
matlab/GetPosteriorMeanVariance.m
0 → 100644
View file @
7ddab426
function [mean,variance] = GetPosteriorMeanVariance(M,drop)
DirectoryName = CheckPath('metropolis',M.dname);
o=load([ DirectoryName '/' M.fname '_mh_history']);
NbrDraws = sum(o.record.MhDraws(:,1));
NbrFiles = sum(o.record.MhDraws(:,2));
NbrBlocks = o.record.Nblck;
mean = 0;
variance = 0;
z = [];
fname1 = [DirectoryName '/' M.fname];
nkept = 0;
for i=1:NbrBlocks
n = 0;
for j=1:NbrFiles
o = load([fname1 '_mh' int2str(j) '_blck' int2str(i)]);
m = size(o.x2,1);
if n + m
<
drop
*NbrDraws
n =
n
+
m
;
continue
elseif
n
<
drop*NbrDraws
k =
drop*NbrDraws
-
n
+
1;
x2 =
o.x2(k:end,:);
else
x2 =
o.x2;
end
z =
[z;
x2
];
p =
size(x2,1);
mean =
(nkept*mean
+
sum
(
x2
)')/(
nkept
+
p
);
x =
bsxfun(@minus,x2,mean');
variance =
(nkept*variance
+
x
'
*x
)/(
nkept
+
p
);
n =
n
+
m
;
nkept =
nkept
+
p
;
end
end
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment