2007-05-19 18:50:20 +02:00
|
|
|
function [mu,sigma,offset] = recursive_moments(m0,s0,data,offset)
|
|
|
|
% Recursive estimation of order one and two moments (expectation and
|
|
|
|
% covariance matrix).
|
|
|
|
%
|
|
|
|
% INPUTS
|
|
|
|
% o m0 [double] (n*1) vector, the prior expectation.
|
|
|
|
% o s0 [double] (n*n) matrix, the prior covariance matrix.
|
|
|
|
% o data [double] (T*n) matrix.
|
|
|
|
% o offset [integer] scalar, number of observation previously
|
|
|
|
% used to compute m0 and s0.
|
|
|
|
%
|
|
|
|
% OUTPUTS
|
|
|
|
% o mu [double] (n*1) vector, the posterior expectation.
|
|
|
|
% o sigma [double] (n*n) matrix, the posterior covariance matrix.
|
|
|
|
% o offset [integer] = offset + T.
|
2005-02-18 20:54:39 +01:00
|
|
|
%
|
2007-05-19 18:50:20 +02:00
|
|
|
% ALGORITHM
|
|
|
|
% None.
|
2005-02-18 20:54:39 +01:00
|
|
|
%
|
2007-05-19 18:50:20 +02:00
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% None.
|
|
|
|
%
|
|
|
|
%
|
|
|
|
% part of DYNARE, copyright S. Adjemian, M. Juillard (2006)
|
|
|
|
% Gnu Public License.
|
|
|
|
|
|
|
|
[T,n] = size(data);
|
2005-02-18 20:54:39 +01:00
|
|
|
|
|
|
|
for t = 1:T
|
|
|
|
tt = t+offset;
|
|
|
|
m1 = m0 + (1/tt)*(data(t,:)'-m0);
|
2007-05-19 18:50:20 +02:00
|
|
|
qq = m1*m1';
|
|
|
|
s1 = s0 + (1/tt)*(data(t,:)'*data(t,:)-qq-s0) + ((tt-1)/tt)*(m0*m0'-qq');
|
2005-02-18 20:54:39 +01:00
|
|
|
m0 = m1;
|
|
|
|
s0 = s1;
|
|
|
|
end
|
|
|
|
|
2007-05-19 18:50:20 +02:00
|
|
|
mu = m1; sigma = s1;
|
|
|
|
offset = offset+T;
|