| Description of slcopca |
slcopca
PURPOSE 
SLCOPCA Performs Coupled PCA Learning
SYNOPSIS 
function [P1, P2, spectrum] = slcopca(X1, X2, d, varargin)
DESCRIPTION 
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
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
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
0103
0104
0105
0106 X1 = preprocess_samples(X1, vmean1, w);
0107 X2 = preprocess_samples(X2, vmean2, w);
0108
0109
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
0139 if nargout >= 3
0140 spectrum = spectrum .* spectrum / tw;
0141 end
0142
0143
0144
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
|
|