source: distools/testpd.m @ 34

Last change on this file since 34 was 10, checked in by bduin, 14 years ago
File size: 2.1 KB
Line 
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
28function [e,F] = testkd(d,h,par)
29
30if nargin < 3 | isempty(par), par = 'all'; end
31if nargin < 2 | isempty(h), [w,h] = parzenddc(d); end
32
33isdataset(d);
34
35nlab     = getnlab(d);
36lablist  = getlablist(d);
37featlist = getfeat(d);
38[m,k,c]  = getsize(d);
39p        = getprior(d);
40
41[clab,classlist] = renumlab(featlist);
42c = 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
48J = matchlablist(classlist,lablist);
49classlist = lablist;
50clab = J(clab);
51
52if 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);
57elseif ~strcmp(par,'all')
58        error(['Unknown option ''' par ''''])
59end
60
61s = exp(-(d.^2)/(2*h*h));
62
63F = zeros(m,c);
64for 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
74end
75%F = F ./ (sum(F,2)*ones(1,c));
76F = setdata(d,F,classlist);
77e = F*testc;
Note: See TracBrowser for help on using the repository browser.