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 slcopca
Home > sltoolbox > subspace > slcopca.m

slcopca

PURPOSE ^

SLCOPCA Performs Coupled PCA Learning

SYNOPSIS ^

function [P1, P2, spectrum] = slcopca(X1, X2, d, varargin)

DESCRIPTION ^

SLCOPCA Performs Coupled PCA Learning

 $ Syntax $
   - [P1, P2] = slcopca(X1, X2, sch, ...)
   - [P1, P2, spectrum] = slcopca(...)

 $ Arguments $
   - X1:       The samples in the first modality
   - X2:       The samples in the second modality
   - d:        The target space dimension
   - P1:       The projection matrix (bases) of the first modality space
   - P2:       The projection matrix (bases) of the second modality space
   - spectrum: The covariance energy along dimensions of target space
   
 $ Description $
   - [P1, P2] = slcopca(X1, X2, sch, ...) performs coupled PCA learning
     for two correlated sample spaces. The learning objective is to
     pursue two subspaces such that they are maximally correlated. The
     objective function is formulated as

       maximize trace( P1^T * C_12 * P2 * P2^T * C_21 * P1 ) / n
           s.t. P1^T * P1 = I, and  P2^T * P2 = I
       where C_12 is the covariance between X1 and X2, 
             C_21 is the covariance between X2 and X1

     Suppose the dimensions for the two spaces are d1 and d2 respectively, 
     and n pairs of corresponding samples are given in X1 and X2. Then X1 
     and X2 should be d1 x n and d2 x n matrices respectively. 
     You can further specify the following properties to control the
     learning procedure:
       - 'weights':    The weights of the samples, default = []
       - 'mean1':      The pre-computed mean vector for X1, default = []
                       if mean1 is set as 0, then it means that X1 has 
                       been centralized.
       - 'mean2':      The pre-computed mean vector for X2, default = []
       
   - [P1, P2, spectrum] = slcopca(...) also outputs the spectrum. You
     can specify the following properties to control the type of the
     output spectrum:
       - 'spectype':   The type of output spectrum
                       - 'normal': The average energies along target
                                   dimensions.
                       - 'ratio':  The ratio of preserved energy along
                                   target dimensions to the total
                                   energy.
                       default = 'normal'.
 
 $ History $
   - Created by Dahua Lin, on Sep 16, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
  • sladdvec SLADDVEC adds a vector to columns or rows of a matrix
  • slmulvec SLMULVEC multiplies a vector to columns or rows of a matrix
  • slmean SLMEAN Compute the mean vector of samples
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
  • slparseprops SLPARSEPROPS Parses input parameters
This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [P1, P2, spectrum] = slcopca(X1, X2, d, varargin)
0002 %SLCOPCA Performs Coupled PCA Learning
0003 %
0004 % $ Syntax $
0005 %   - [P1, P2] = slcopca(X1, X2, sch, ...)
0006 %   - [P1, P2, spectrum] = slcopca(...)
0007 %
0008 % $ Arguments $
0009 %   - X1:       The samples in the first modality
0010 %   - X2:       The samples in the second modality
0011 %   - d:        The target space dimension
0012 %   - P1:       The projection matrix (bases) of the first modality space
0013 %   - P2:       The projection matrix (bases) of the second modality space
0014 %   - spectrum: The covariance energy along dimensions of target space
0015 %
0016 % $ Description $
0017 %   - [P1, P2] = slcopca(X1, X2, sch, ...) performs coupled PCA learning
0018 %     for two correlated sample spaces. The learning objective is to
0019 %     pursue two subspaces such that they are maximally correlated. The
0020 %     objective function is formulated as
0021 %
0022 %       maximize trace( P1^T * C_12 * P2 * P2^T * C_21 * P1 ) / n
0023 %           s.t. P1^T * P1 = I, and  P2^T * P2 = I
0024 %       where C_12 is the covariance between X1 and X2,
0025 %             C_21 is the covariance between X2 and X1
0026 %
0027 %     Suppose the dimensions for the two spaces are d1 and d2 respectively,
0028 %     and n pairs of corresponding samples are given in X1 and X2. Then X1
0029 %     and X2 should be d1 x n and d2 x n matrices respectively.
0030 %     You can further specify the following properties to control the
0031 %     learning procedure:
0032 %       - 'weights':    The weights of the samples, default = []
0033 %       - 'mean1':      The pre-computed mean vector for X1, default = []
0034 %                       if mean1 is set as 0, then it means that X1 has
0035 %                       been centralized.
0036 %       - 'mean2':      The pre-computed mean vector for X2, default = []
0037 %
0038 %   - [P1, P2, spectrum] = slcopca(...) also outputs the spectrum. You
0039 %     can specify the following properties to control the type of the
0040 %     output spectrum:
0041 %       - 'spectype':   The type of output spectrum
0042 %                       - 'normal': The average energies along target
0043 %                                   dimensions.
0044 %                       - 'ratio':  The ratio of preserved energy along
0045 %                                   target dimensions to the total
0046 %                                   energy.
0047 %                       default = 'normal'.
0048 %
0049 % $ History $
0050 %   - Created by Dahua Lin, on Sep 16, 2006
0051 %
0052 
0053 %% parse and verify input arguments
0054 
0055 if nargin < 3
0056     raise_lackinput('slcopca', 3);
0057 end
0058 
0059 if ~isnumeric(X1) || ~isnumeric(X2) || ndims(X1) ~= 2 || ndims(X2) ~= 2
0060     error('sltoolbox:invalidarg', ...
0061         'X1 and X2 should be 2D numeric matrices');
0062 end
0063 
0064 [d1, n] = size(X1);
0065 [d2, n2] = size(X2);
0066 if n ~= n2
0067     error('sltoolbox:sizmismatch', ...
0068         'The numbers of samples in X1 and X2 do not match');
0069 end
0070 
0071 dmax = min(d1, d2);
0072 if d > dmax
0073     error('sltoolbox:invalidarg', ...
0074         'The target dimension d should not exceed d1 or d2');
0075 end
0076 
0077 opts.weights = [];
0078 opts.mean1 = [];
0079 opts.mean2 = [];
0080 opts.spectype = 'normal';
0081 opts = slparseprops(opts, varargin{:});
0082 
0083 w = opts.weights;
0084 if ~isempty(w)
0085     if ~isequal(size(w), [1, n])
0086         error('sltoolbox:sizmismatch', ...
0087             'w should be a 1 x n row vector');
0088     end
0089 end
0090 
0091 vmean1 = opts.mean1;
0092 vmean2 = opts.mean2;
0093 if ~isempty(vmean1) && ~isequal(vmean1, 0) && ~isequal(size(vmean1), [d1, 1])
0094     error('sltoolbox:sizmismatch', ...
0095         'The size of mean1 is illegal');
0096 end
0097 if ~isempty(vmean2) && ~isequal(vmean2, 0) && ~isequal(size(vmean2), [d2, 1])
0098     error('sltoolbox:sizmismatch', ...
0099         'The size of mean1 is illegal');
0100 end
0101 
0102 %% main skeleton
0103 
0104 % preprocess sample matrices
0105 
0106 X1 = preprocess_samples(X1, vmean1, w);
0107 X2 = preprocess_samples(X2, vmean2, w);
0108 
0109 % construct problem
0110 S = X1 * X2';
0111 
0112 switch opts.spectype
0113     case 'normal'
0114         if isempty(w)
0115             tw = n;
0116         else
0117             tw = sum(w);
0118         end
0119     case 'ratio'
0120         tw = trace(S * S');
0121     otherwise
0122         error('sltoolbox:invalidarg', ...
0123             'Invalid spectrum type: %s', opts.spectype);
0124 end
0125 
0126 
0127 if d > dmax / 3;
0128     [P1, D, P2] = svd(S, 'econ');
0129     spectrum = diag(D);
0130     spectrum = spectrum(1:d);
0131     P1 = P1(:, 1:d);
0132     P2 = P2(:, 1:d);
0133 else
0134     [P1, D, P2] = svds(S, d);
0135     spectrum = diag(D);
0136 end
0137 
0138 % post-process spectrum
0139 if nargout >= 3
0140     spectrum = spectrum .* spectrum / tw;
0141 end
0142 
0143 
0144 %% Auxiliary functions
0145 
0146 function Xp = preprocess_samples(X, vmean, w)
0147 
0148 if ~isequal(vmean, 0)
0149     if isempty(vmean)
0150         vmean = slmean(X, w, true);
0151     end
0152     Xp = sladdvec(X, -vmean, 1);
0153 else
0154     Xp = X;
0155 end
0156 
0157 if ~isempty(w) 
0158     Xp = slmulvec(Xp, w, 2);
0159 end
0160 
0161 
0162     
0163     
0164     
0165 
0166 
0167 
0168 
0169 
0170 
0171 
0172 
0173 
0174  
0175  
0176

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

Contact us at files@mathworks.com