1 | %DISPC Dissimilarity based Parzen classifier |
---|
2 | % |
---|
3 | % W = dispc(A) |
---|
4 | % |
---|
5 | % A should be a dissimilarity based dataset with class labels as |
---|
6 | % feature labels. |
---|
7 | % |
---|
8 | % $Id: dispc.m,v 1.2 2001/07/10 16:35:58 pavel Exp $ |
---|
9 | |
---|
10 | % Copyright: R.P.W. Duin, duin@ph.tn.tudelft.nl |
---|
11 | % Faculty of Applied Physics, Delft University of Technology |
---|
12 | % P.O. Box 5046, 2600 GA Delft, The Netherlands |
---|
13 | |
---|
14 | function w = dispc(a,v) |
---|
15 | |
---|
16 | if nargin < 1 | isempty(a) % empty call (untrained classifier) |
---|
17 | w = prmapping('dispc'); |
---|
18 | |
---|
19 | elseif nargin == 1 % training |
---|
20 | [nlab,lablist,m,k,c,p] = prdataset(a); |
---|
21 | [nn,nf,fl] = renumlab(lablist,getfeat(a)); |
---|
22 | if c < 2 |
---|
23 | error('Dataset should containf more than one class') |
---|
24 | end |
---|
25 | if max(nf) > c |
---|
26 | error('Feature labels of dataset do not match with class labels') |
---|
27 | end |
---|
28 | w = []; |
---|
29 | for j=1:c |
---|
30 | F = find(nf==j); |
---|
31 | L = find(nlab==j); |
---|
32 | n = ceil(sqrt(length(L))); |
---|
33 | [b,r] = sort(+a(L,F)); |
---|
34 | for f=1:length(F) |
---|
35 | h(F(f)) = b(r(n,f),F(f)); |
---|
36 | end |
---|
37 | |
---|
38 | b = {+a(find(nlab==nf(j)),j) +a(find(nlab~=nf(j)),j)}; |
---|
39 | w = [w; prmapping('distrc',b,fl(nf(j),:),1,1,1)]; |
---|
40 | end |
---|
41 | |
---|
42 | % w = cnormc(w,a); forget normalisation and apriori probs for the moment |
---|
43 | |
---|
44 | elseif nargin == 2 % evaluation |
---|
45 | [m,k] = size(a); |
---|
46 | b = +v; b1 = b{1}; b2 = b{2}; |
---|
47 | n1 = length(b1); n2 = length(b2); |
---|
48 | w1 = zeros(m,1); w2 = zeros(m,1); |
---|
49 | [d R1] = sort([b1;+a]); |
---|
50 | [d R2] = sort([b2;+a]); |
---|
51 | L1 = find(R1>n1); |
---|
52 | L2 = find(R2>n2); |
---|
53 | w1(R1(L1)-n1) = (n1+2-(L1-[1:m]'))/(n1+2); |
---|
54 | w2(R2(L2)-n2) = (n2+2-(L2-[1:m]'))/(n2+2); |
---|
55 | % disp([w1;w2]) |
---|
56 | w = invsig(prdataset((w1+w2)/2,getlab(a),getfeat(v))); |
---|
57 | else |
---|
58 | error('Illegal call') |
---|
59 | end |
---|
60 | |
---|