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

slrangespace

PURPOSE ^

SLRANGESPACE Determines the subspace of the range of X

SYNOPSIS ^

function [U, Uc] = slrangespace(tar, varargin)

DESCRIPTION ^

SLRANGESPACE Determines the subspace of the range of X

 $ Syntax $
   - U = slrangespace(tar)
   - U = slrangespace(tar, ...)
   - [U, Uc] = slrangespace(...)

 $ Arguments $
   - tar:      the target, can be a sample matrix or covariance
   - U:        the basis for the range space
   - Uc:       the basis for the orthogonal complement of the range

 $ Description $
   - U = slrangespace(tar) determines the range space of tar in default 
     settings. That is to set the dimension to be the rank of tar. Note
     that tar can have two forms: a sample matrix or a covariance
     given by the syntax {'cov', C}.

   - U = slrangespace(tar, ...) determines the range space of X using
     the specified dimension determination schemes. The arguments 
     input following X will be delivered to sldim_by_eigval for dimension
     determination.

   - [U, Uc] = slrangespace(...) also returns orthogonal complement of U.

 $ History $
   - Created by Dahua Lin on Apr 25, 2005

CROSS-REFERENCE INFORMATION ^

This function calls:
  • slsymeig SLSYMEIG Compute the eigenvalues and eigenvectors for symmetric matrix
  • sldim_by_eigval SLDIM_BY_EIGVAL Determines the dimension of principal subspace by eigenvalues
This function is called by:
  • sldlda SLDLDA Performs Direct Linear Discriminant Analysis
  • slnullspace SLRANGESPACE Determines the null-space of the range of X

SOURCE CODE ^

0001 function [U, Uc] = slrangespace(tar, varargin)
0002 %SLRANGESPACE Determines the subspace of the range of X
0003 %
0004 % $ Syntax $
0005 %   - U = slrangespace(tar)
0006 %   - U = slrangespace(tar, ...)
0007 %   - [U, Uc] = slrangespace(...)
0008 %
0009 % $ Arguments $
0010 %   - tar:      the target, can be a sample matrix or covariance
0011 %   - U:        the basis for the range space
0012 %   - Uc:       the basis for the orthogonal complement of the range
0013 %
0014 % $ Description $
0015 %   - U = slrangespace(tar) determines the range space of tar in default
0016 %     settings. That is to set the dimension to be the rank of tar. Note
0017 %     that tar can have two forms: a sample matrix or a covariance
0018 %     given by the syntax {'cov', C}.
0019 %
0020 %   - U = slrangespace(tar, ...) determines the range space of X using
0021 %     the specified dimension determination schemes. The arguments
0022 %     input following X will be delivered to sldim_by_eigval for dimension
0023 %     determination.
0024 %
0025 %   - [U, Uc] = slrangespace(...) also returns orthogonal complement of U.
0026 %
0027 % $ History $
0028 %   - Created by Dahua Lin on Apr 25, 2005
0029 %
0030 
0031 %% parse and verify input arguments
0032 
0033 if isnumeric(tar)   
0034     target_type = 1;        % target is sample
0035     
0036     if ndims(tar) ~= 2
0037         error('sltoolbox:invalidarg', ...
0038             'When tar is sample matrix, it should be a 2D matrix');
0039     end
0040     
0041     X = tar;
0042     d = size(X, 1);
0043     
0044 elseif iscell(tar)
0045     
0046     if length(tar) == 2 && ischar(tar{1}) ...
0047             && strcmpi(tar{1}, 'cov')
0048         
0049         target_type = 2;        % target is covariance
0050         
0051         C = tar{2};
0052         d = size(C, 1);
0053         
0054         if ~isequal(size(C), [d d])
0055             error('sltoolbox:invalidarg', ...
0056                 'A covariance matrix should be square');
0057         end
0058         
0059     else        
0060         error('sltoolbox:invalidarg', ...
0061             'The target should be a sample matrix or a covariance given by cell');        
0062     end
0063     
0064 else
0065     
0066     error('sltoolbox:invalidarg', ...
0067         'The target should be a sample matrix or a covariance given by cell');        
0068 end
0069 
0070 if nargout == 0
0071     return;
0072 elseif nargout == 1
0073     need_complement = false;
0074 else
0075     need_complement = true;
0076 end
0077     
0078 
0079 %% compute
0080 
0081 switch target_type
0082     
0083     case 1      % sample matrix
0084         
0085         if ~need_complement
0086             [U, D] = svd(X, 0);
0087         else
0088             [U, D] = svd(X);
0089         end
0090         
0091         evals = diag(D) .^ 2;
0092         clear D;
0093                                         
0094     case 2      % covariance
0095         
0096         [evals, U] = slsymeig(C);
0097         
0098 end
0099     
0100 evals = max(evals, 0);
0101 k = sldim_by_eigval(evals, varargin{:});
0102 
0103 %% output
0104 
0105 if ~need_complement
0106     U = U(:, 1:k);
0107 else
0108     if k == size(U, 2)
0109         Uc = zeros(d, 0);
0110     else
0111         Uc = U(:, k+1:end);
0112         U  = U(:, 1:k);
0113     end
0114 end
0115

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

Contact us at files@mathworks.com