IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
fsgt_maxentr.m
Go to the documentation of this file.
1 %> Maximum entropy split criterion for tree classifiers
2 %>
3 %> Reference:
4 %>
5 %> L. Breiman, J.H. Friedman, R.A. Olshen, and C.J. Stone,
6 %> Classification and regression trees, Wadsworth, California, 1984.
7 %>
8 %> @sa clssr_tree, fsgt
9 classdef fsgt_maxentr < fsgt
10  methods
11  %> Credits:
12  %>
13  %> Copyright: R.P.W. Duin, duin@ph.tn.tudelft.nl
14  %> Faculty of Applied Physics, Delft University of Technology
15  %> P.O. Box 5046, 2600 GA Delft, The Netherlands
16  function [grades, idx, threshold] = test(o, X, classes)
17  [m,k] = size(X);
18  c = max(classes);
19  % -variable threshold is an (2c)x k matrix containing:
20  % minimum feature values class 1
21  % maximum feature values class 1
22  % minimum feature values class 2
23  % maximum feature values class 2
24  % etc.
25  % -variable R (same size) contains:
26  % fraction of objects which is < min. class 1.
27  % fraction of objects which is > max. class 1.
28  % fraction of objects which is < min. class 2.
29  % fraction of objects which is > max. class 2.
30  % etc.
31  % These values are collected and computed in the next loop:
32  threshold = zeros(2*c,k); R = zeros(2*c,k);
33  for j = 1:c
34  L = (classes == j);
35  if sum(L) == 0
36  threshold([2*j-1:2*j],:) = zeros(2,k);
37  R([2*j-1:2*j],:) = zeros(2,k);
38  else
39  threshold(2*j-1,:) = min(X(L,:),[],1);
40  R(2*j-1,:) = sum(X < ones(m,1)*threshold(2*j-1,:),1);
41  threshold(2*j,:) = max(X(L,:),[],1);
42  R(2*j,:) = sum(X > ones(m,1)*threshold(2*j,:),1);
43  end
44  end
45  % From R the purity index for all features is computed:
46  G = R .* (m-R);
47  % and the best feature is found:
48  [gmax,tmax] = max(G,[],1);
49  [grades,idx] = max(gmax);
50  Tmax = tmax(idx);
51  if Tmax ~= 2*floor(Tmax/2)
52  threshold = (threshold(Tmax,idx) + max(X(find(X(:,idx) < threshold(Tmax,idx)),idx)))/2;
53  else
54  threshold = (threshold(Tmax,idx) + min(X(find(X(:,idx) > threshold(Tmax,idx)),idx)))/2;
55  end
56  if isempty(threshold)
57  irerror('Maximum Entropy Criterion not feasible for this decision tree!');
58  end;
59  end;
60  end;
61 
62  methods
63  function o = fsgt_maxentr(o)
64  o.classtitle = 'Maximum Entropy Criterion';
65  end;
66  end;
67 end
function irerror(in s)
Binary Decision Tree Classifier.
Definition: clssr_tree.m:4
Definition: fsgt.m:5