Home > matlab > recursive_moments.m

recursive_moments

PURPOSE ^

Recursive estimation of order one and two moments (expectation and

SYNOPSIS ^

function [mu,sigma,offset] = recursive_moments(m0,s0,data,offset)

DESCRIPTION ^

 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.

 ALGORITHM 
   None.       

 SPECIAL REQUIREMENTS
   None.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [mu,sigma,offset] = recursive_moments(m0,s0,data,offset)
0002 % Recursive estimation of order one and two moments (expectation and
0003 % covariance matrix).
0004 %
0005 % INPUTS
0006 %   o m0         [double]    (n*1) vector, the prior expectation.
0007 %   o s0         [double]    (n*n) matrix, the prior covariance matrix.
0008 %   o data       [double]    (T*n) matrix.
0009 %   o offset     [integer]   scalar, number of observation previously
0010 %                            used to compute m0 and s0.
0011 % OUTPUTS
0012 %   o mu         [double]    (n*1) vector, the posterior expectation.
0013 %   o sigma      [double]    (n*n) matrix, the posterior covariance matrix.
0014 %   o offset     [integer]   = offset + T.
0015 %
0016 % ALGORITHM
0017 %   None.
0018 %
0019 % SPECIAL REQUIREMENTS
0020 %   None.
0021 
0022 % Copyright (C) 2006-2009 Dynare Team
0023 %
0024 % This file is part of Dynare.
0025 %
0026 % Dynare is free software: you can redistribute it and/or modify
0027 % it under the terms of the GNU General Public License as published by
0028 % the Free Software Foundation, either version 3 of the License, or
0029 % (at your option) any later version.
0030 %
0031 % Dynare is distributed in the hope that it will be useful,
0032 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0033 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0034 % GNU General Public License for more details.
0035 %
0036 % You should have received a copy of the GNU General Public License
0037 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0038 
0039 [T,n] = size(data);
0040 
0041 for t = 1:T
0042     tt = t+offset;
0043     m1 = m0 + (data(t,:)'-m0)/tt;
0044     qq = m1*m1';
0045     s1 = s0 + ( (data(t,:)'*data(t,:)-qq-s0) + (tt-1)*(m0*m0'-qq') )/tt;
0046     m0 = m1;
0047     s0 = s1;
0048 end
0049 
0050 mu = m1; 
0051 sigma = s1;
0052 offset = offset+T;

Generated on Tue 22-May-2012 02:40:23 by m2html © 2005