Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of slpoolcov
Home > sltoolbox > stat > slpoolcov.m

slpoolcov

PURPOSE ^

SLPOOLCOV Compute the pooled covariance

SYNOPSIS ^

function C = slpoolcov(Cs, w)

DESCRIPTION ^

SLPOOLCOV Compute the pooled covariance 

 $ Syntax $
   - C = slpoolcov(Cs)
   - C = slpoolcov(Cs, w)

 $ Arguments $
   - Cs        the stack of covariance matrices for all components
   - w:        the weights for components
   - C:        the pooled covariance matrix

 $ Description $
   - C = slpoolcov(Cs) computes the average covariance matrix.

   - C = slpoolcov(Cs, w) computes the weighted pooled covariance matrix
     with the component weights specified in w.

 $ History $
   - Created by Dahua Lin on Dec 19th, 2004
   - Modified by Dahua Lin on Apr 22nd, 2004
       - Give an much more efficient implementation using matrix product
         and reshaping.

CROSS-REFERENCE INFORMATION ^

This function calls:
This function is called by:
  • slregcov SLREGCOV Regularizes covariance matrices

SOURCE CODE ^

0001 function C = slpoolcov(Cs, w)
0002 %SLPOOLCOV Compute the pooled covariance
0003 %
0004 % $ Syntax $
0005 %   - C = slpoolcov(Cs)
0006 %   - C = slpoolcov(Cs, w)
0007 %
0008 % $ Arguments $
0009 %   - Cs        the stack of covariance matrices for all components
0010 %   - w:        the weights for components
0011 %   - C:        the pooled covariance matrix
0012 %
0013 % $ Description $
0014 %   - C = slpoolcov(Cs) computes the average covariance matrix.
0015 %
0016 %   - C = slpoolcov(Cs, w) computes the weighted pooled covariance matrix
0017 %     with the component weights specified in w.
0018 %
0019 % $ History $
0020 %   - Created by Dahua Lin on Dec 19th, 2004
0021 %   - Modified by Dahua Lin on Apr 22nd, 2004
0022 %       - Give an much more efficient implementation using matrix product
0023 %         and reshaping.
0024 %
0025 
0026 %% parse and verify input arguments
0027 [d1, d2, n] = size(Cs);
0028 if d1 ~= d2
0029     error('sltoolbox:notsquaremat', ...
0030         'the covariance matrices should be square');
0031 end
0032 d = d1;
0033 if nargin < 2 || isempty(w)
0034     isweighted = false;
0035 else
0036     isweighted = true;
0037     if numel(w) ~= n
0038         error('sltoolbox:argmismatch', ...
0039             'the size of w does not match that of Cs');
0040     end
0041 end
0042 
0043 %% compute
0044 if n == 1
0045     C = Cs;
0046 else
0047     if ~isweighted
0048         Cs = reshape(Cs, [d*d, n]);
0049         C = reshape(sum(Cs, 2), [d, d]);
0050     else        
0051         w = w(:) / sum(w(:));
0052         Cs = reshape(Cs, [d*d, n]);
0053         C = reshape(Cs * w, [d, d]);
0054     end
0055 end
0056 
0057 
0058 
0059 
0060 
0061     
0062 
0063 
0064

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com