| Description of slwhiten_from_samples |
slwhiten_from_samples
PURPOSE 
SLWHITEN_FROM_SAMPLES Compute the whitening matrix from sample matrix
SYNOPSIS 
function W = slwhiten_from_samples(X, varargin)
DESCRIPTION 
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
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 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
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
0091
0092 if ~isempty(opts.weights)
0093 X = slmulvec(X, sqrt(max(opts.weights, 0)), 2);
0094 end
0095
0096
0097
0098 W = fh_compW(X, opts.evproc);
0099
0100
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
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
|
|