1 | %TESTPD Test Parzen classifier for dissimilarity data
|
---|
2 | %
|
---|
3 | % [E,C] = TESTPD(D,H,PAR)
|
---|
4 | %
|
---|
5 | % INPUT
|
---|
6 | % D Dissimilarity dataset. Object labels are assumed to be the
|
---|
7 | % true labels. Feature labels are assumed to be the labels of
|
---|
8 | % the objects they are related to.
|
---|
9 | % H Desired smoothing parameter.
|
---|
10 | % PAR 'loo' - leave-one-out option. This should be used if
|
---|
11 | % the objects are related to themselves. If D is not square,
|
---|
12 | % it is assumed that the first sets of objects in columns and
|
---|
13 | % rows match.
|
---|
14 | % 'all' - use all objects (default).
|
---|
15 | %
|
---|
16 | % OUTPUT
|
---|
17 | % E Estimated error
|
---|
18 | % C Matrix with confidences, size M x N, if D has size M x L and
|
---|
19 | % the labels are given for N classes.
|
---|
20 | %
|
---|
21 | % SEE ALSO
|
---|
22 | % DATASETS, KNND, TESTKD
|
---|
23 |
|
---|
24 | % Copyright: R.P.W. Duin, r.p.w.duin@prtools.org
|
---|
25 | % Faculty EWI, Delft University of Technology
|
---|
26 | % P.O. Box 5031, 2600 GA Delft, The Netherlands
|
---|
27 |
|
---|
28 | function [e,F] = testkd(d,h,par)
|
---|
29 |
|
---|
30 | if nargin < 3 | isempty(par), par = 'all'; end
|
---|
31 | if nargin < 2 | isempty(h), [w,h] = parzenddc(d); end
|
---|
32 |
|
---|
33 | isdataset(d);
|
---|
34 |
|
---|
35 | nlab = getnlab(d);
|
---|
36 | lablist = getlablist(d);
|
---|
37 | featlist = getfeat(d);
|
---|
38 | [m,k,c] = getsize(d);
|
---|
39 | p = getprior(d);
|
---|
40 |
|
---|
41 | [clab,classlist] = renumlab(featlist);
|
---|
42 | c = max(clab);
|
---|
43 | %[cl,nc,labl] = renumlab(classlist,lablist);
|
---|
44 | %if size(labl,1) > c
|
---|
45 | % error('Object labels do not match representation set')
|
---|
46 | %end
|
---|
47 | % correct for different classlist - lablist orders
|
---|
48 | J = matchlablist(classlist,lablist);
|
---|
49 | classlist = lablist;
|
---|
50 | clab = J(clab);
|
---|
51 |
|
---|
52 | if strcmp(par,'loo')
|
---|
53 | % get rid of leave-one-out problems
|
---|
54 | km = min(k,m);
|
---|
55 | dmax=max(max(+d))*100;
|
---|
56 | d(1:km,1:km) = d(1:km,1:km) + dmax*eye(km);
|
---|
57 | elseif ~strcmp(par,'all')
|
---|
58 | error(['Unknown option ''' par ''''])
|
---|
59 | end
|
---|
60 |
|
---|
61 | s = exp(-(d.^2)/(2*h*h));
|
---|
62 |
|
---|
63 | F = zeros(m,c);
|
---|
64 | for j=1:c
|
---|
65 | L = find(clab==j);
|
---|
66 | F(:,j) = mean(s(:,L),2)*p(j);
|
---|
67 | if strcmp(par,'loo')
|
---|
68 | if length(L) == 1
|
---|
69 | F(L,j) = 0;
|
---|
70 | else
|
---|
71 | F(L,j) = length(L)*F(L,j)/(length(L)-1); % correct for LOO
|
---|
72 | end
|
---|
73 | end
|
---|
74 | end
|
---|
75 | %F = F ./ (sum(F,2)*ones(1,c));
|
---|
76 | F = setdata(d,F,classlist);
|
---|
77 | e = F*testc; |
---|