aboutsummaryrefslogtreecommitdiff
path: root/FEAST/MIToolbox/demonstration_algorithms/DISR.m
blob: c8f5669eac34f44eab40ca2c921671428e7d8512 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
function selectedFeatures = DISR(k, featureMatrix, classColumn)
%function selectedFeatures = DISR(k, featureMatrix, classColumn)
%
%Computers optimal features according to DISR algorithm from 
%On the Use of variable "complementarity for feature selection" 
%by P Meyer, G Bontempi (2006)
%
%Computes the top k features from
%a dataset featureMatrix with n training examples and m features
%with the classes held in classColumn.
%
%DISR - arg(Xi) max(sum(Xj mem XS)(SimRel(Xij,Y)))
%where SimRel = MI(Xij,Y) / H(Xij,Y)

totalFeatures = size(featureMatrix,2);
classMI = zeros(totalFeatures,1);
unselectedFeatures = ones(totalFeatures,1);
score = 0;
currentScore = 0;
innerScore = 0;
iMinus = 0;
answerFeatures = zeros(k,1);
highestMI = 0;
highestMICounter = 0;
currentHighestFeature = 0;

%create a matrix to hold the SRs of a feature pair. 
%initialised to -1 as you can't get a negative SR.
featureSRMatrix = -(ones(k,totalFeatures));

for n = 1 : totalFeatures
	classMI(n) = mi(featureMatrix(:,n),classColumn);
	if classMI(n) > highestMI
		highestMI = classMI(n);
		highestMICounter = n;
	end
end

answerFeatures(1) = highestMICounter;
unselectedFeatures(highestMICounter) = 0;

for i = 2 : k
	score = 0;
	currentHighestFeature = 0;
	iMinus = i-1;
  for j = 1 : totalFeatures
		if unselectedFeatures(j) == 1
			%DISR - arg(Xi) max(sum(Xj mem XS)(SimRel(Xij,Y)))
			%where SimRel = MI(Xij,Y) / H(Xij,Y)
			currentScore = 0;
			for m = 1 : iMinus
        if featureSRMatrix(m,j) == -1
          unionedFeatures = joint([featureMatrix(:,answerFeatures(m)),featureMatrix(:,j)]);
				  tempUnionMI = mi(unionedFeatures,classColumn);
				  tempTripEntropy = h([unionedFeatures,classColumn]);
				  featureSRMatrix(m,j) = tempUnionMI/tempTripEntropy;
        end
        
				currentScore =  currentScore + featureSRMatrix(m,j);
			end
			if (currentScore > score)
				score = currentScore;
				currentHighestFeature = j;
			end
		end
	end
	%now highest feature is selected in currentHighestFeature
	%store it
	unselectedFeatures(currentHighestFeature) = 0;
	answerFeatures(i) = currentHighestFeature;
end

selectedFeatures = answerFeatures;