| Description of sllocaltanspace |
sllocaltanspace
PURPOSE 
SLLOCALTANSPACE Solves the local tangent spaces
SYNOPSIS 
function [LM, LP, LS] = sllocaltanspace(X0, G, dl)
DESCRIPTION 
CROSS-REFERENCE INFORMATION 
This function calls:
- sladdvec SLADDVEC adds a vector to columns or rows of a matrix
- 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
- sladjmat SLADJMAT Constructs the adjacency matrix representation of a graph
- slgraphinfo SLGRAPHINFO Extracts basic information of a given graph representation
- slmean SLMEAN Compute the mean vector of samples
This function is called by:
- slltsa SLLTSA Performs Local Tangent Space Alignment Learning
SUBFUNCTIONS 
SOURCE CODE 
0001 function [LM, LP, LS] = sllocaltanspace(X0, G, dl)
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 if ~isnumeric(X0) || ndims(X0) ~= 2
0041 error('sltoolbox:invalidarg', ...
0042 'The sample matrix X0 should be a 2D numeric matrix');
0043 end
0044 [d0, n0] = size(X0);
0045
0046 gi = slgraphinfo(G);
0047 if gi.n ~= n0
0048 error('sltoolbox:invalidarg', ...
0049 'The graph is not consistent with the sample number');
0050 end
0051 if ~strcmp(gi.form, 'adjmat')
0052 G = sladjmat(G, 'sparse', true);
0053 end
0054 n = gi.nt;
0055
0056 if dl >= d0 || dl >= n0
0057 error('sltoolbox:invalidarg', ...
0058 'The local dimension dl should be strictly less than d0 and n0');
0059 end
0060
0061 if nargout >= 3
0062 want_sp = true;
0063 else
0064 want_sp = false;
0065 end
0066
0067 if isnumeric(G)
0068 use_weights = true;
0069 else
0070 use_weights = false;
0071 end
0072
0073
0074
0075
0076 LM = zeros(d0, n);
0077 LP = zeros(d0, dl, n);
0078 if want_sp
0079 LS = zeros(dl, n);
0080 end
0081
0082
0083 for i = 1 : n
0084 localinds = find(G(:,i));
0085 if use_weights
0086 localw = G(localinds, i)';
0087 else
0088 localw = [];
0089 end
0090 localX = X0(:, localinds);
0091
0092 [cm, cp, csp] = solvelocalspace(localX, localw, d0, dl);
0093
0094 LM(:,i) = cm;
0095 LP(:,:,i) = cp;
0096 if want_sp
0097 LS(:,i) = csp;
0098 end
0099 end
0100
0101
0102
0103
0104 function [vmean, P, spectrum] = solvelocalspace(X, w, d0, dl)
0105
0106 n = size(X, 2);
0107 dm = min([dl, d0, n]);
0108
0109
0110 vmean = slmean(X, w, true);
0111 X = sladdvec(X, -vmean, 1);
0112 if ~isempty(w)
0113 X = slmulvec(X, w, 2);
0114 end
0115
0116
0117 if d0 <= n / 2
0118 C = X * X';
0119 [spectrum, P] = slsymeig(C, dm);
0120 else
0121 C = X' * X;
0122 [spectrum, P] = slsymeig(C, dm);
0123 P = slnormalize(X * P);
0124 end
0125
0126
0127 rk = sum(spectrum > n * eps(spectrum(1)));
0128 if rk < dm
0129 spectrum = spectrum(1:rk);
0130 P = P(:, 1:rk);
0131 end
0132 spectrum = spectrum / n;
0133
0134
0135 if rk < dl
0136 spectrum = [spectrum; zeros(dl-rk, 1)];
0137 P = [P, zeros(d0, dl-rk)];
0138 end
0139
Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003
|
|