1 | %MCLASSDC Multi-Class Dissimilarity-based Classifier from Two-Class Discriminants |
---|
2 | % |
---|
3 | % W = MCLASSDC(D,CLASSF,MODE) |
---|
4 | % |
---|
5 | % INPUT |
---|
6 | % D Dissimilarity dataset |
---|
7 | % CLASSF Untrained dissimilarity-based classifier |
---|
8 | % MODE Way of handling multi-class problems: 'SINGLE' or 'MULTI' |
---|
9 | % (optional; default: 'SINGLE') |
---|
10 | % |
---|
11 | % OUTPUT |
---|
12 | % W Combined classifier |
---|
13 | % |
---|
14 | % DEFAULT |
---|
15 | % MODE = 'SINGLE' |
---|
16 | % |
---|
17 | % DESCRIPTION |
---|
18 | % For the default MODE = 'SINGLE', the untrained classifier CLASSF is called to |
---|
19 | % compute C classifiers between each of the C classes in the dataset D and |
---|
20 | % the remaining C-1 classes. The result is stored into the combined |
---|
21 | % classifier W. There is no combining rule added. The default rule, MAXC |
---|
22 | % might be replaced by adding one, e.g. W = W*MEANC. |
---|
23 | % |
---|
24 | % For the MODE = 'MULTI', the untrained classifier CLASSF is trained between |
---|
25 | % all pairs of classes as well as between each class and all other classes. |
---|
26 | % This total set of C^2 classifiers is combined by MINC. The use of soft labels |
---|
27 | % is supported. |
---|
28 | % The pairwise classifiers are trained by using a representation set based |
---|
29 | % on the traing objects of the corresponding classes only (just in case of |
---|
30 | % crisp labels). This is the only difference with the use of MCLASSC. |
---|
31 | % |
---|
32 | % EXAMPLE |
---|
33 | % W = MCLASSDC(DISTM(GENDATM(100)),QDC([],0.01),'MULTI') |
---|
34 | % |
---|
35 | % SEE ALSO |
---|
36 | % DATASETS, MAPPINGS, MAXC, MINC |
---|
37 | |
---|
38 | % Copyright: R.P.W. Duin, r.duin@ieee.org |
---|
39 | % Faculty EWI, Delft University of Technology |
---|
40 | |
---|
41 | |
---|
42 | function varargout = mclassdc(D,classf,mode) |
---|
43 | |
---|
44 | prtrace(mfilename); |
---|
45 | if nargin < 3, |
---|
46 | mode = 'single'; |
---|
47 | end |
---|
48 | if nargin < 2, |
---|
49 | classf = []; |
---|
50 | end |
---|
51 | if nargin < 1 | isempty(D) |
---|
52 | w = prmapping(mfilename,{classf,mode}); |
---|
53 | return |
---|
54 | end |
---|
55 | |
---|
56 | if ~ismapping(classf) | ~isuntrained(classf) |
---|
57 | error('Second parameter should be an untrained mapping.') |
---|
58 | end |
---|
59 | |
---|
60 | islabtype(D,'crisp','soft'); |
---|
61 | isvaldset(D,1,2); % At least 1 object per class and two classes |
---|
62 | |
---|
63 | [m,k,c] = getsize(D); |
---|
64 | |
---|
65 | varout = {}; |
---|
66 | if c == 2 |
---|
67 | varargout = prmap(D,classf); |
---|
68 | return |
---|
69 | end |
---|
70 | lablist = getlablist(D); |
---|
71 | |
---|
72 | |
---|
73 | switch lower(mode) |
---|
74 | case 'single' |
---|
75 | w = []; |
---|
76 | % lablist = getlablist(D); |
---|
77 | for i=1:c |
---|
78 | if islabtype(D,'crisp') |
---|
79 | mlab = 2 - (getnlab(D) == i); |
---|
80 | DD = setlabels(D,mlab); |
---|
81 | elseif islabtype(D,'soft') |
---|
82 | Dtargets = gettargets(D); |
---|
83 | targets = [Dtargets(:,i) 1-Dtargets(:,i)]; |
---|
84 | DD = prdataset(+D,mlab,targets,'lablist',[1 2]'); |
---|
85 | end |
---|
86 | if nargout(classf.mapping_file) > 1 |
---|
87 | [v,varo] = prmap(DD,classf); |
---|
88 | varout = [varout {varo}]; |
---|
89 | else |
---|
90 | v = prmap(DD,classf); |
---|
91 | end |
---|
92 | w = [w,setlabels(v(:,1),lablist(i,:))]; |
---|
93 | end |
---|
94 | |
---|
95 | |
---|
96 | case 'multi' |
---|
97 | w = []; |
---|
98 | nlab = getnlab(D); |
---|
99 | [nl,clab,list] = renumlab(getlablist(D),getfeatlab(D)); |
---|
100 | for z=1:c |
---|
101 | lab = lablist(z,:); |
---|
102 | |
---|
103 | J1 = find(nlab==z); |
---|
104 | L1 = find(clab==z); |
---|
105 | if islabtype(D,'crisp') |
---|
106 | mlab = ones(m,1); |
---|
107 | mlab(J1) = zeros(length(J1),1); |
---|
108 | DD = setlabels(D,mlab); |
---|
109 | else |
---|
110 | problab = gettargets(D); |
---|
111 | mlab = [problab(:,i1) sum(problab,2)-problab(:,z)]; |
---|
112 | DD = settargets(D,mlab,[1 2]'); |
---|
113 | end |
---|
114 | I1 = setdiff([1:c],z); |
---|
115 | if nargout(classf.mapping_file) > 1 |
---|
116 | [v,varo] = prmap(DD,classf); |
---|
117 | varout = [varout {varo}]; |
---|
118 | else |
---|
119 | v = prmap(DD,classf); |
---|
120 | end |
---|
121 | w = [w,setlabels(v(:,1),lab)]; |
---|
122 | |
---|
123 | for t = I1 |
---|
124 | if islabtype(D,'crisp') |
---|
125 | J2 = find(nlab==t); |
---|
126 | L2 = find(clab==t); |
---|
127 | v = featsel(k,[L1;L2])*(DD([J1;J2],[L1;L2])*classf); |
---|
128 | %disp([z,t]); |
---|
129 | %parsc(v); |
---|
130 | else |
---|
131 | mlab2 = problab(:,[z t]); |
---|
132 | v = setlabels(DD,mlab2)*classf; |
---|
133 | end |
---|
134 | w = [w,setlabels(v(:,1),lab)]; |
---|
135 | end |
---|
136 | end |
---|
137 | w = minc(w); |
---|
138 | |
---|
139 | otherwise |
---|
140 | error('Unknown mode') |
---|
141 | end |
---|
142 | |
---|
143 | w = setname(w,getname(classf)); |
---|
144 | w = setsize(w,[k,c]); |
---|
145 | w = setcost(w,D); |
---|
146 | varargout = {w varout}; |
---|
147 | return |
---|