source: distools/nne.m @ 44

Last change on this file since 44 was 20, checked in by bduin, 13 years ago

updates for handling soft labels

File size: 901 bytes
RevLine 
[10]1%NNE Leave-one-out Nearest Neighbor Error on a Dissimilarity Matrix
2%
3%   [E,LAB] = NNE(D)
4%
5% INPUT
6%   D   NxN symmetric dissimilarity dataset
7%
8% OUTPUT
9%   E   Leave-one-out error
10%   LAB Nearest neighbor labels
11%
12% DESCRIPTION
13% Estimates the leave-one-out error of the 1-nearest neighbor rule
14% on the givven symmetric dissimilairy data.
15%
16
17% Copyright: Robert P.W. Duin, r.p.w.duin@prtools.org and
18% Elzbieta Pekalska, ela.pekalska@googlemail.com
19% Faculty EWI, Delft University of Technology and
20% School of Computer Science, University of Manchester
21
22
23function [e,NNlab] = nne(D)
24
25[m,n] = size(D);
26if m ~= n,
27  error('Distance matrix should be square.');
28end
29
30lab = getlab(D);
31[nlab,lablist] = renumlab(lab);
32D(1:m+1:end)   = inf;
33[d,M] = min(D');
34e     = mean(nlab(M) ~= nlab);
[20]35if islabtype(D,'crisp')
36        NNlab = lablist(nlab(M),:);
37else
38        labs = gettargets(D);
39        NNlab = labs(M,:);
40end
[10]41return;
Note: See TracBrowser for help on using the repository browser.