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 slpartitionpca_construct
Home > sltoolbox > subspace_ex > slpartitionpca_construct.m

slpartitionpca_construct

PURPOSE ^

SLPARTITIONPCA_CONSTRUCT Constructs the array from features

SYNOPSIS ^

function A = slpartitionpca_construct(S, modeldir, feas)

DESCRIPTION ^

SLPARTITIONPCA_CONSTRUCT Constructs the array from features 

 $ Syntax $
   - A = slpartitionpca_construct(S, modeldir, feas)

 $ Arguments $
   - S:            the partition-based PCA model struct or model core file
   - modeldir:     the directory path of the projection files
   - feas:         the partition PCA features
   - A:            the constructed arrays in original space

 $ Description $
   - A = slpartitionpca_construct(S, modeldir, feas) constructs the 
     array units in the original space from the extracted partiton PCA
     features. Here, S can be a struct loaded from core file or the core 
     filename. modeldir is the directory of the corefile and the related 
     projection matrix files.

 $ Remarks $
   - When the combined model is learned, the dimension of features can be
     lower than the dimension of feature subspace of the PCA model. In 
     this case, only the first k principal components are used.

 $ History $
   - Created by Dahua Lin, on Jul 30th, 2006
   - Modified by Dahua Lin, on Sep 10, 2006
       - replace sladd by sladdvec to increase efficiency

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:

SOURCE CODE ^

0001 function A = slpartitionpca_construct(S, modeldir, feas)
0002 %SLPARTITIONPCA_CONSTRUCT Constructs the array from features
0003 %
0004 % $ Syntax $
0005 %   - A = slpartitionpca_construct(S, modeldir, feas)
0006 %
0007 % $ Arguments $
0008 %   - S:            the partition-based PCA model struct or model core file
0009 %   - modeldir:     the directory path of the projection files
0010 %   - feas:         the partition PCA features
0011 %   - A:            the constructed arrays in original space
0012 %
0013 % $ Description $
0014 %   - A = slpartitionpca_construct(S, modeldir, feas) constructs the
0015 %     array units in the original space from the extracted partiton PCA
0016 %     features. Here, S can be a struct loaded from core file or the core
0017 %     filename. modeldir is the directory of the corefile and the related
0018 %     projection matrix files.
0019 %
0020 % $ Remarks $
0021 %   - When the combined model is learned, the dimension of features can be
0022 %     lower than the dimension of feature subspace of the PCA model. In
0023 %     this case, only the first k principal components are used.
0024 %
0025 % $ History $
0026 %   - Created by Dahua Lin, on Jul 30th, 2006
0027 %   - Modified by Dahua Lin, on Sep 10, 2006
0028 %       - replace sladd by sladdvec to increase efficiency
0029 %
0030 
0031 %% parse and verify input arguments
0032 
0033 if nargin < 3
0034     raise_lackinput('slpartitionpca_apply', 3);
0035 end
0036 
0037 if ischar(S)
0038     S = load(S);
0039 elseif ~isstruct(S)
0040     error('sltoolbox:invalidarg', ...
0041         'The S should be the filename of the core file or the core struct');
0042 end
0043 
0044 [k, n] = size(feas);
0045 if k > S.diminfo.feadim
0046     error('sltoolbox:sizmismatch', ...
0047         'k is larger than the dimension of feature space');
0048 elseif k < S.diminfo.feadim && isempty(S.combprojfile)
0049     error('sltoolbox:sizmismatch', ...
0050         'When the combined model is not learned, k should be exactly the same as the dimension of feature space');
0051 end
0052 
0053 %% Construct Intermediate features
0054 
0055 if ~isempty(S.combprojfile)
0056    
0057     combprojpath = sladdpath(S.combprojfile, modeldir);
0058     P = slreadarray(combprojpath);
0059     if k < S.diminfo.feadim
0060         P = P(:, 1:k);
0061     end
0062     intfeas = P * feas;
0063     clear P;
0064     
0065 else
0066     intfeas = feas;
0067     
0068 end
0069     
0070 %% Construct Array Units
0071 
0072 A = zeros([size(S.meanarr), n]);
0073 NBlks = numel(S.blocks);
0074 projpaths = sladdpath(S.projfiles, modeldir);
0075 
0076 dc = 0;
0077 for ib = 1 : NBlks
0078     
0079     curblock = S.blocks{ib};
0080     rgncell = slrange2indcells(curblock);
0081     
0082     cursiz = curblock(2,:) - curblock(1,:) + 1;
0083     curdim = prod(cursiz);
0084     cursubdim = S.diminfo.subdims(ib);
0085     
0086     curfeasec = intfeas(dc+1:dc+cursubdim, :);        
0087     curproj = slreadarray(projpaths{ib});
0088     
0089     localmean = S.meanarr(rgncell{:});
0090     localmean = reshape(localmean, [curdim, 1]);
0091     
0092     localarr = curproj * curfeasec;
0093     clear curproj;
0094     
0095     localarr = sladdvec(localarr, localmean, 1);
0096     localarr = reshape(localarr, [cursiz, n]);
0097     
0098     A(rgncell{:}, :) = localarr;    
0099     
0100     clear localarr localmean;
0101     
0102     dc = dc + cursubdim;
0103     
0104 end
0105 
0106 
0107 
0108 
0109     
0110

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

Contact us at files@mathworks.com