IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
fsgt_infgain.m
Go to the documentation of this file.
1 %> Information Gain split criterion for tree classifiers
2 %>
3 %> @sa clssr_tree, fsgt
4 classdef fsgt_infgain < fsgt
5  methods
6  %> Credit:
7  %>
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)
12  [m,k] = size(X);
13  classes = classes+1;
14  c = max(classes);
15  mininfo = ones(k,2);
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
23  P = sort(X);
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
27  af = X(:,f);
28  JQ = find(Q(:,f));
29  SET = P(JQ,f)';
30  if JQ(1) ~= 1
31  SET = [P(JQ(1)-1,f), SET];
32  end
33  n = length(JQ);
34  if JQ(n) ~= m
35  SET = [SET, P(JQ(n)+1,f)];
36  end
37  n = length(SET) -1;
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
40  for j = 1:c
41  J = find(classes==j); mj = length(J);
42  if mj == 0
43  L(j,:) = realmin*ones(1,n); R(j,:) = L(j,:);
44  else
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;
47  end
48  end
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
54  end
55  grades = 1-mininfo(:,1)';
56  [finfo,idx] = min(mininfo(:,1)); % best over all features
57  threshold = mininfo(idx,2); % and its threshold
58  end;
59  end;
60 
61  methods
62  function o = fsgt_infgain(o)
63  o.classtitle = 'Information Gain Criterion';
64  end;
65  end;
66 end
Binary Decision Tree Classifier.
Definition: clssr_tree.m:4
Definition: fsgt.m:5