-
Notifications
You must be signed in to change notification settings - Fork 0
/
JMI4.m
97 lines (63 loc) · 4.88 KB
/
JMI4.m
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
function [selectedFeatures] = JMI4(data,labels, topK, arities)
% Summary
% JMI-4 algorithm for feature selection
% Inputs
% data: n x d matrix X, with categorical values for n examples and d features
% labels: n x 1 vector with the labels
% topK: Number of features to be selected
% arities: (d+1)x1 vector, that in the first d positions are the arities
% of the feature, and in the last of the label
numFeatures = size(data,2);
%%%%%%%%%% First feature
count = 1;
mi_score = zeros(1,numFeatures);
for index_feature = 1:numFeatures
score_per_feature(index_feature) = mi_Ind_JS(data(:,index_feature),labels,arities(index_feature),arities(end));
end
[val_max,selectedFeatures(1)]= max(score_per_feature);
mi_score(selectedFeatures(1)) = val_max;
not_selected_features = setdiff(1:numFeatures,selectedFeatures);
%%%%%%%%%% Second feature
count = 2;
score_per_feature = zeros(1,numFeatures);
score_per_feature(selectedFeatures(1)) = NaN;
for index_feature_ns = 1:length(not_selected_features)
score_per_feature(not_selected_features(index_feature_ns)) = score_per_feature(not_selected_features(index_feature_ns))+mi_Ind_JS([data(:,not_selected_features(index_feature_ns)),data(:, selectedFeatures(count-1))], labels,arities([not_selected_features(index_feature_ns) selectedFeatures(count-1)]),arities(end));
% score_per_feature(not_selected_features(index_feature_ns)) = score_per_feature(not_selected_features(index_feature_ns))+cmi_Ind_JS(data(:,not_selected_features(index_feature_ns)), labels,data(:, selectedFeatures(count-1)), arities(not_selected_features(index_feature_ns)),arities(end),arities(selectedFeatures(count-1)));
end
[val_max,selectedFeatures(count)]= nanmax(score_per_feature);
score_per_feature(selectedFeatures(count)) = NaN;
not_selected_features = setdiff(1:numFeatures,selectedFeatures);
%%%%%%%%%% Third feature
score_per_feature = zeros(1,numFeatures);
score_per_feature(selectedFeatures(1:2)) = NaN;
count = 3;
for index_feature_ns = 1:length(not_selected_features)
for index_feature_s = 1:(length(selectedFeatures)-1)
score_per_feature(not_selected_features(index_feature_ns)) = score_per_feature(not_selected_features(index_feature_ns))+mi_Ind_JS([data(:,not_selected_features(index_feature_ns)),data(:, selectedFeatures(count-1)),data(:, selectedFeatures(index_feature_s))], labels,arities([not_selected_features(index_feature_ns) selectedFeatures(count-1) selectedFeatures(index_feature_s)]),arities(end));
% score_per_feature(not_selected_features(index_feature_ns)) = score_per_feature(not_selected_features(index_feature_ns))+cmi_Ind_JS([data(:,not_selected_features(index_feature_ns))], labels,[data(:, selectedFeatures(count-1)) data(:, selectedFeatures(index_feature_s))], arities([not_selected_features(index_feature_ns)]),arities(end),arities([selectedFeatures(count-1) selectedFeatures(index_feature_s)]));
end
end
[val_max,selectedFeatures(count)]= nanmax(score_per_feature);
score_per_feature(selectedFeatures(count)) = NaN;
not_selected_features = setdiff(1:numFeatures,selectedFeatures);
%%%%%%%%%% Rest of the features
%%% Efficient implementation of the second step, at this point I will store
%%% the score of each feature. Whenever I select a feature I put NaN score
score_per_feature = zeros(1,numFeatures);
score_per_feature(selectedFeatures(1:3)) = NaN;
count = 4;
while count<=topK
for index_feature_ns = 1:length(not_selected_features)
for index_feature_s1 = 1:(length(selectedFeatures)-2)
for index_feature_s2 = (index_feature_s1+1):(length(selectedFeatures)-1)
score_per_feature(not_selected_features(index_feature_ns)) = score_per_feature(not_selected_features(index_feature_ns))+mi_Ind_JS([data(:,not_selected_features(index_feature_ns)),data(:, selectedFeatures(count-1)),data(:, selectedFeatures(index_feature_s1)),data(:, selectedFeatures(index_feature_s2))], labels,arities([not_selected_features(index_feature_ns) selectedFeatures(count-1) selectedFeatures(index_feature_s1) selectedFeatures(index_feature_s2)]),arities(end));
% score_per_feature(not_selected_features(index_feature_ns)) = score_per_feature(not_selected_features(index_feature_ns))+cmi_Ind_JS([data(:,not_selected_features(index_feature_ns))], labels,[data(:, selectedFeatures(count-1)) data(:, selectedFeatures(index_feature_s))], arities([not_selected_features(index_feature_ns)]),arities(end),arities([selectedFeatures(count-1) selectedFeatures(index_feature_s)]));
end
end
end
[val_max,selectedFeatures(count)]= nanmax(score_per_feature);
score_per_feature(selectedFeatures(count)) = NaN;
not_selected_features = setdiff(1:numFeatures,selectedFeatures);
count = count+1;
end