| Description of slvechist |
slvechist
PURPOSE 
SLVECHIST Makes the histogram on prototype vectors by voting
SYNOPSIS 
function H = slvechist(X0, X, varargin)
DESCRIPTION 
CROSS-REFERENCE INFORMATION 
This function calls:
- annsearch ANNSEARCH Approximate Nearest Neighbor Search
- slmetric_pw SLMETRIC_PW Compute the metric between column vectors pairwisely
- slvote SLVOTE Builds histogram by voting (or fuzzy voting)
- slnngraph SLNNGRAPH Constructs a nearest neighborhood based graph
- raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
- slparseprops SLPARSEPROPS Parses input parameters
This function is called by:
SUBFUNCTIONS 
- function V = do_vote(X0, X, fvote, cvf, Vform)
- function V = evaldist_one(X0, X, usecvalue, clsmethod, fhmetric)
- function V = evaldist_multi(X0, X, usecvalue, nnparams, fhmetric)
- function V = evaldist_all(X0, X, usecvalue, fhmetric)
- function fh = get_metricfunc(m)
SOURCE CODE 
0001 function H = slvechist(X0, 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
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103 if nargin < 2
0104 raise_lackinput('slvechist', 2);
0105 end
0106
0107 if ~isnumeric(X0) || ndims(X0) ~= 2
0108 error('sltoolbox:invalidarg', 'X0 should be a 2D numeric matrix');
0109 end
0110 if ~isnumeric(X) || ndims(X) ~= 2
0111 error('sltoolbox:invalidarg', 'X should be a 2D numeric matrix');
0112 end
0113
0114 [d, m] = size(X0);
0115 [d2, n] = size(X);
0116 if d ~= d2
0117 error('sltoolbox:sizmismatch', 'The dimensions of X and X0 are mismatched');
0118 end
0119
0120
0121 opts.countrule = 'nm';
0122 opts.clsmethod = 'pwcomp';
0123 opts.nnparams = [];
0124 opts.metric = 'eucdist';
0125 opts.cfunc = [];
0126 opts.evalfunctor = [];
0127 opts.weights = [];
0128 opts.normalized = false;
0129 opts = slparseprops(opts, varargin{:});
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141 if isempty(opts.evalfunctor)
0142
0143 switch opts.countrule
0144 case {'nm', 'nmx'}
0145 Vform = 0;
0146 usecvalue = strcmp(opts.countrule, 'nmx');
0147 fhmetric = get_metricfunc(opts.metric);
0148 fvote = @(x, y) evaldist_one(x, y, usecvalue, opts.clsmethod, fhmetric);
0149
0150 case {'mmc', 'mms', 'mmns'}
0151 usecvalue = ~strcmp(opts.countrule, 'mmc');
0152 fhmetric = get_metricfunc(opts.metric);
0153 if isempty(opts.nnparams)
0154 Vform = 2;
0155 fvote = @(x, y) evaldist_all(x, y, usecvalue, fhmetric);
0156 else
0157 Vform = 1;
0158 fvote = @(x, y) evaldist_multi(x, y, usecvalue, opts.nnparams, fhmetric);
0159 end
0160
0161 otherwise
0162 error('sltoolbox:invalidarg', ...
0163 'Unknown counting rule: %s', opts.countrule);
0164 end
0165
0166 if usecvalue
0167 if isempty(opts.cfunc)
0168 error('sltoolbox:invalidarg', ...
0169 'In current rule, the confidence function is required.');
0170 end
0171 if ischar(opts.cfunc) && strcmp(opts.cfunc, 'um')
0172 cvf = [];
0173 elseif isa(opts.cfunc, 'function_handle')
0174 cvf = opts.cfunc;
0175 else
0176 error('sltoolbox:invalidarg', 'Illegal form of cfunc');
0177 end
0178 else
0179 cvf = [];
0180 end
0181
0182 evalfunctor = {@do_vote, fvote, cvf, Vform};
0183
0184 else
0185 evalfunctor = opts.evalfunctor;
0186 end
0187
0188
0189 H = slvote(X0, m, X, n, evalfunctor, opts.countrule, ...
0190 'weights', opts.weights, ...
0191 'normalized', opts.normalized);
0192
0193
0194
0195
0196 function V = do_vote(X0, X, fvote, cvf, Vform)
0197
0198 V = fvote(X0, X);
0199 if ~isempty(cvf)
0200 if Vform == 0
0201 V(2,:) = cvf(V(2,:));
0202 else
0203 V = cvf(V);
0204 end
0205 end
0206
0207
0208 function V = evaldist_one(X0, X, usecvalue, clsmethod, fhmetric)
0209
0210 switch clsmethod
0211 case 'pwcomp'
0212 D = fhmetric(X0, X);
0213 [vals, si] = min(D, [], 1);
0214 case 'kdtree'
0215 [si, vals] = annsearch(X0, X, 1);
0216 otherwise
0217 error('sltoolbox:invalidarg', ...
0218 'Invalid clsmethod: %s', clsmethod);
0219 end
0220
0221 if ~usecvalue
0222 V = si;
0223 else
0224 V = [si; vals];
0225 end
0226
0227
0228 function V = evaldist_multi(X0, X, usecvalue, nnparams, fhmetric)
0229
0230 switch nnparams{1}
0231 case {'knn', 'eps'}
0232 use_nnparams = [nnparams, {'metric', fhmetric}];
0233 case 'ann'
0234 use_nnparams = nnparams;
0235 otherwise
0236 error('sltoolbox:invalidarg', ...
0237 'Invalid neighborhood finding method: %s', nnparams{1});
0238 end
0239
0240 if usecvalue
0241 valtype = 'numeric';
0242 else
0243 valtype = 'logical';
0244 end
0245
0246 V = slnngraph(X0, X, use_nnparams, 'sparse', true, 'valtype', valtype);
0247
0248
0249 function V = evaldist_all(X0, X, usecvalue, fhmetric)
0250
0251 V = fhmetric(X0, X);
0252
0253 if ~usecvalue
0254 V = (V ~= 0);
0255 end
0256
0257
0258
0259
0260
0261 function fh = get_metricfunc(m)
0262
0263 if ischar(m)
0264 fh = @(X, Y) slmetric_pw(X, Y, m);
0265 elseif iscell(m)
0266 fh = @(X, Y) slmetric_pw(X, Y, m{:});
0267 elseif isa(m, 'function_handle')
0268 fh = m;
0269 else
0270 error('sltoolbox:invalidarg', 'The metric is specified incorrectly');
0271 end
0272
0273
0274
0275
0276
Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003
|
|