1 %> Information Gain split criterion
for tree classifiers
8 %> Copyright: R.P.W. Duin, duin@ph.tn.tudelft.nl
9 %> Faculty of Applied Physics, Delft University of Technology
10 %> P.O. Box 5046, 2600 GA Delft, The Netherlands
11 function [grades, idx, threshold] = test(o, X, classes)
16 % determine feature domains of interest
17 [sn,ln] = min(X,[],1);
18 [sx,lx] = max(X,[],1);
19 JN = (classes(:,ones(1,k)) == ones(m,1)*classes(ln)
') * realmax;
20 JX = -(classes(:,ones(1,k)) == ones(m,1)*classes(lx)') * realmax;
21 S = sort([sn; min(X+JN,[],1); max(X+JX,[],1); sx]);
22 % S(2,:) to S(3,:) are interesting feature domains
24 Q = (P >= ones(m,1)*S(2,:)) & (P <= ones(m,1)*S(3,:));
25 % these are the feature values in those domains
26 for f=1:k, % repeat for all features
31 SET = [P(JQ(1)-1,f), SET];
35 SET = [SET, P(JQ(n)+1,f)];
38 T = (SET(1:n) + SET(2:n+1))/2; % all possible thresholds
39 L = zeros(c,n); R = L; % left and right node
object counts per class
41 J = find(classes==j); mj = length(J);
43 L(j,:) = realmin*ones(1,n); R(j,:) = L(j,:);
45 L(j,:) = sum(repmat(af(J),1,n) <= repmat(T,mj,1)) + realmin;
46 R(j,:) = sum(repmat(af(J),1,n) > repmat(T,mj,1)) + realmin;
49 infomeas = - (sum(L .* log10(L./(ones(c,1)*sum(L)))) ...
50 + sum(R .* log10(R./(ones(c,1)*sum(R))))) ...
51 ./ (log10(2)*(sum(L)+sum(R))); % criterion value for all thresholds
52 [mininfo(f,1),j] = min(infomeas); % finds the best
53 mininfo(f,2) = T(j); % and its threshold
55 grades = 1-mininfo(:,1)';
56 [finfo,idx] = min(mininfo(:,1)); % best over all features
57 threshold = mininfo(idx,2); % and its threshold
63 o.classtitle = 'Information Gain Criterion';
Binary Decision Tree Classifier.