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 slwhiten_from_samples
Home > sltoolbox > stat > slwhiten_from_samples.m

slwhiten_from_samples

PURPOSE ^

SLWHITEN_FROM_SAMPLES Compute the whitening matrix from sample matrix

SYNOPSIS ^

function W = slwhiten_from_samples(X, varargin)

DESCRIPTION ^

SLWHITEN_FROM_SAMPLES Compute the whitening matrix from sample matrix

 $ Syntax $
   - W = slwhiten_from_samples(X)
   - W = slwhiten_from_samples(X, ...)

 $ Arguments $
   - X:            the sample matrix
   - W:            the computed whitening transform matrix

 $ Description $
   - W = slwhiten_from_samples(X) computes the whiten transform matrix
     from samples using the automatic-selection scheme.

   - W = slwhiten_from_samples(X, ...) computes the whiten transform
     matrix from samples according to the user-specified properties.
     \*   
     \t   Table 1. The properties of sample-whitening computation \\
     \h     name     &      description                   \\
           'scheme'  &  The scheme of computation procedure, 
                        default = 'auto' \\
           'evproc'  &  The {method, ...} form of eigenvalue processing. 
                        default = {'std'} \\
                        This will be input to the slinvevals function. \\
           'weights' &  The sample weights.  default = []. \\
     \*      
     The available schemes are listed as follows
     \* 
     \t   Table 2. The schemes of computing whitening matrix       \\
     \h     name   &     description                               \\
           'auto'  &  Automatically select a proper scheme for computing.
                      \\ 
           'std'   &  Standard scheme: first compute the covariance matrix
                      and then derive the whitening transform matrix. \\
           'svd'   &  SVD-based scheme. Using svd for eigen-decomposition.
           'trans' &  Use a transpose-based way. It is more efficient for
                      the case with high-dimensionality and small sample
                      size.                                            \\
     \*
     The methods for processing the eigenvalues, i.e. computing their
     reciprocals can be referred to the slinvevals function.

 $ Remarks $
   - It is a prerequisite that the samples are properly centered. 

 $ History $
   - Created by Lin Dahua on Apr 30, 2006
   - Modified by Dahua Lin on Sep 10, 2006
       - replace slmul by slmulvec to increase efficiency

CROSS-REFERENCE INFORMATION ^

This function calls:
  • slmulvec SLMULVEC multiplies a vector to columns or rows of a matrix
  • slnormalize SLNORMALIZE Normalize the sub-arrays
  • slsymeig SLSYMEIG Compute the eigenvalues and eigenvectors for symmetric matrix
  • slinvevals SLINVEVALS Compute the reciprocals of eigenvalues in a robust way
  • slparseprops SLPARSEPROPS Parses input parameters
This function is called by:
  • slfld SLFLD Performs Fisher Linear Discriminant Analysis

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function W = slwhiten_from_samples(X, varargin)
0002 %SLWHITEN_FROM_SAMPLES Compute the whitening matrix from sample matrix
0003 %
0004 % $ Syntax $
0005 %   - W = slwhiten_from_samples(X)
0006 %   - W = slwhiten_from_samples(X, ...)
0007 %
0008 % $ Arguments $
0009 %   - X:            the sample matrix
0010 %   - W:            the computed whitening transform matrix
0011 %
0012 % $ Description $
0013 %   - W = slwhiten_from_samples(X) computes the whiten transform matrix
0014 %     from samples using the automatic-selection scheme.
0015 %
0016 %   - W = slwhiten_from_samples(X, ...) computes the whiten transform
0017 %     matrix from samples according to the user-specified properties.
0018 %     \*
0019 %     \t   Table 1. The properties of sample-whitening computation \\
0020 %     \h     name     &      description                   \\
0021 %           'scheme'  &  The scheme of computation procedure,
0022 %                        default = 'auto' \\
0023 %           'evproc'  &  The {method, ...} form of eigenvalue processing.
0024 %                        default = {'std'} \\
0025 %                        This will be input to the slinvevals function. \\
0026 %           'weights' &  The sample weights.  default = []. \\
0027 %     \*
0028 %     The available schemes are listed as follows
0029 %     \*
0030 %     \t   Table 2. The schemes of computing whitening matrix       \\
0031 %     \h     name   &     description                               \\
0032 %           'auto'  &  Automatically select a proper scheme for computing.
0033 %                      \\
0034 %           'std'   &  Standard scheme: first compute the covariance matrix
0035 %                      and then derive the whitening transform matrix. \\
0036 %           'svd'   &  SVD-based scheme. Using svd for eigen-decomposition.
0037 %           'trans' &  Use a transpose-based way. It is more efficient for
0038 %                      the case with high-dimensionality and small sample
0039 %                      size.                                            \\
0040 %     \*
0041 %     The methods for processing the eigenvalues, i.e. computing their
0042 %     reciprocals can be referred to the slinvevals function.
0043 %
0044 % $ Remarks $
0045 %   - It is a prerequisite that the samples are properly centered.
0046 %
0047 % $ History $
0048 %   - Created by Lin Dahua on Apr 30, 2006
0049 %   - Modified by Dahua Lin on Sep 10, 2006
0050 %       - replace slmul by slmulvec to increase efficiency
0051 %
0052 
0053 %% parse and verify input arguments
0054 
0055 if ndims(X) ~= 2
0056     error('sltoolbox:invaliddims', ...
0057         'The sample matrix X should be a 2D matrix');
0058 end
0059 n = size(X, 2);
0060 
0061 % check options
0062 
0063 opts.scheme = 'auto';
0064 opts.evproc = {'std'};
0065 opts.weights = [];
0066 opts = slparseprops(opts, varargin{:});
0067 
0068 switch opts.scheme 
0069     case 'auto'
0070         fh_compW = @compute_whiten_auto;
0071     case 'std'
0072         fh_compW = @compute_whiten_std;
0073     case 'svd'
0074         fh_compW = @compute_whiten_svd;
0075     case 'trans'
0076         fh_compW = @compute_whiten_trans;
0077     otherwise
0078         error('sltoolbox:invalidarg', ...
0079             'Invalid whiten matrix computing scheme %s', opts.scheme);
0080 end
0081 
0082 if ~isempty(opts.weights)
0083     if ~isequal(size(opts.weights), [1, n])
0084         error('sltoolbox:sizmismatch', ...
0085             'The weights should be a 1 x n row vector');
0086     end
0087 end
0088 
0089 
0090 %% prepare the samples
0091 
0092 if ~isempty(opts.weights)
0093     X = slmulvec(X, sqrt(max(opts.weights, 0)), 2);
0094 end
0095 
0096 %% compute
0097 
0098 W = fh_compW(X, opts.evproc);
0099 
0100 %% The functions for computing whiten matrix
0101 
0102 function W = compute_whiten_auto(X, evproc)
0103 
0104 if size(X, 1) > size(X, 2)
0105     W = compute_whiten_trans(X, evproc);
0106 else
0107     W = compute_whiten_std(X, evproc);
0108 end
0109 
0110 function W = compute_whiten_std(X, evproc)
0111 
0112 S = X * X';
0113 [evs, U] = slsymeig(S);
0114 [revs, U] = proc_eigs(evs, U, evproc);
0115 W = slmulvec(U, sqrt(revs)', 2);
0116 
0117 function W = compute_whiten_svd(X, evproc)
0118 
0119 [U, D] = svd(X, 0);
0120 evs = diag(D) .^ 2;
0121 clear D;
0122 
0123 [revs, U] = proc_eigs(evs, U, evproc);
0124 W = slmulvec(U, sqrt(revs)', 2);
0125 
0126 function W = compute_whiten_trans(X, evproc)
0127 
0128 S = X' * X;
0129 [evs, V] = slsymeig(S);
0130 U = X * V; 
0131 clear V;
0132 [revs, U] = proc_eigs(evs, U, evproc);
0133 U = slnormalize(U);
0134 
0135 W = slmulvec(U, sqrt(revs)', 2);
0136 
0137 
0138 
0139 %% The auxiliary function for obtaining truncated eigen-reciprocals
0140 
0141 function [revs, U] = proc_eigs(evs, U, evproc)
0142 
0143 revs = slinvevals(evs, evproc{:});
0144 
0145 si = find(revs == 0);
0146 if ~isempty(si)
0147     revs(si) = [];
0148     U(:, si) = [];
0149 end
0150

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

Contact us at files@mathworks.com