| Description of slpartitionpca_apply |
slpartitionpca_apply
PURPOSE 
SLPARTITIONPCA_APPLY applies partition-based PCA to a set of arrays
SYNOPSIS 
function feas = slpartitionpca_apply(S, modeldir, data, n, k)
DESCRIPTION 
CROSS-REFERENCE INFORMATION 
This function calls:
- sladdvec SLADDVEC adds a vector to columns or rows of a matrix
- slreadarray SLREADARRAY Reads an array from an array file
- raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
- sladdpath SLADDPATH Adds dirpath to precede the filenames
- slrange2indcells SLRANGE2INDCELLS Converts a range array to indices cell array
This function is called by:
SUBFUNCTIONS 
SOURCE CODE 
0001 function feas = slpartitionpca_apply(S, modeldir, data, n, k)
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 if nargin < 4
0037 raise_lackinput('slpartitionpca_apply', 4);
0038 end
0039
0040 if ischar(S)
0041 S = load(S);
0042 elseif ~isstruct(S)
0043 error('sltoolbox:invalidarg', ...
0044 'The S should be the filename of the core file or the core struct');
0045 end
0046
0047 if ~isnumeric(data) && ~iscell(data)
0048 error('sltoolbox:invalidarg', ...
0049 'data should be an numeric array or a cell array of strings');
0050 end
0051
0052 if nargin < 5
0053 k = S.diminfo.feadim;
0054 else
0055 if k > S.diminfo.feadim
0056 error('k is higher than the dimension of the whole feature subspace');
0057 elseif k < S.diminfo.feadim && isempty(S.combprojfile)
0058 error('The feature space cannot be truncated without the combined model');
0059 end
0060 end
0061
0062
0063
0064
0065 NBlks = numel(S.blocks);
0066 intfeas = zeros(S.diminfo.intdim, n);
0067
0068 projpaths = sladdpath(S.projfiles, modeldir);
0069
0070 dc = 0;
0071 for ib = 1 : NBlks
0072
0073 curblock = S.blocks{ib};
0074 cursubdim = S.diminfo.subdims(ib);
0075 rgncell = slrange2indcells(curblock);
0076
0077 projmat = slreadarray(projpaths{ib});
0078
0079 V = generate_intfeature(S, data, n, rgncell, projmat);
0080 intfeas(dc+1:dc+cursubdim, :) = V;
0081 dc = dc + cursubdim;
0082
0083 clear projmat;
0084 end
0085
0086
0087
0088
0089 if ~isempty(S.combprojfile)
0090 combprojpath = sladdpath(S.combprojfile, modeldir);
0091
0092 P = slreadarray(combprojpath);
0093 if k < S.diminfo.feadim
0094 P = P(:, 1:k);
0095 end
0096 P = P';
0097
0098 feas = P * intfeas;
0099 else
0100 feas = intfeas;
0101 end
0102
0103
0104
0105
0106
0107 function V = generate_intfeature(S, data, n, rangecell, projmat)
0108
0109 [d0, d1] = size(projmat);
0110 nd = length(rangecell);
0111
0112 if isnumeric(data)
0113
0114 if size(data, nd+1) ~= n
0115 error('sltoolbox:sizmismatch', ...
0116 'The data size does not match the specified sample number');
0117 end
0118
0119 localarr = data(rangecell{:}, :);
0120 localarr = reshape(localarr, [d0, n]);
0121 localmean = S.meanarr(rangecell{:}, :);
0122 localmean = reshape(localmean, [d0, 1]);
0123
0124 localarr = sladdvec(localarr, -localmean, 1);
0125
0126 V = projmat' * localarr;
0127
0128 else
0129
0130 V = zeros(d1, n);
0131
0132 cf = 0;
0133 nfiles = length(data);
0134 for i = 1 : nfiles
0135 datapart = slreadarray(data{i});
0136 curn = size(datapart, nd+1);
0137 V(:, cf+1:cf+curn) = generate_intfeature(S, datapart, curn, rangecell, projmat);
0138 cf = cf + curn;
0139 end
0140
0141 if cf ~= n
0142 error('sltoolbox:sizmismatch', ...
0143 'The total number of units in the set of array files is not n');
0144 end
0145 end
0146
0147
0148
0149
0150
0151
Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003
|
|