IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
as_fsel_forward.m
Go to the documentation of this file.
1 %> @brief Forward Feature Selection
2 %>
3 %> <h3>References</h3>
4 %>
5 %> [1] L. C. Molina, L. Belanche, and a. Nebot, “Feature selection algorithms: a survey and experimental evaluation,”
6 %> 2002 IEEE International Conference on Data Mining, 2002. Proceedings., pp. 306-313, 2002. <b>Section 2.2.2</b>
7 %>
8 %> @sa uip_as_fsel_forward.m
10  properties
11  %> Feature Subset Grader object.
12  fsg = [];
13  %> =10. Number of features to be selected
14  nf_select = 10;
15  end;
16 
17  methods
18  function o = as_fsel_forward()
19  o.classtitle = 'Forward';
20  o.flag_multiin = 1;
21  end;
22  end;
23 
24  methods(Access=protected)
25  function log = do_use(o, data)
26  o.fsg.data = data;
27  o.fsg = o.fsg.boot();
28  nf = data(1).nf;
29 
30  nf_eff = min(o.nf_select, nf); % Effective number of features to be selected
31  v_in = [];
32  v_left = 1:nf;
33  nfxgrade = zeros(1, nf_eff);
34  flag_first = 1;
35 
36  flag_progress = ~isempty(o.fsg.sgs);
37  if flag_progress
38  ipro = progress2_open('FSEL_forward', [], 0, nf_eff);
39  ii = 0;
40  end;
41 
42  for i = 1:nf_eff
43  if flag_first && ~flag_progress
44  t = tic(); % Will record time to see if the iteration is "slow" (i.e., takes more than 1 second). If so, will "activate" the progress bar
45  end;
46  irverbose(sprintf('Number of features: %d ...', i));
47 
48  % Creates candidates
49  v_candidates = arrayfun(@(x) [v_in, x], v_left, 'UniformOutput', 0);
50 
51  % Evaluates candidates
52  candidatesgrades = o.fsg.calculate_grades(v_candidates);
53  g = candidatesgrades(:, :, 1);
54  [val, idx] = max(g);
55 
56  % verifies whether there is more than one candidate with maximum grade
57  ima = find(g == val);
58  n_ima = length(ima);
59  if n_ima > 1
60  idx = ima(randi([1, n_ima])); % Random decision is probably the best that could be done here!
61  end;
62 
63  % Recordings
64  v_in = [v_in, v_left(idx)]; % Indexes of selected features
65  v_left(idx) = []; % Indexes of left features
66  nfxgrade(i) = val; % Recording of (nf)x(grade) sequence
67 
68  %---> Verboses
69  irverbose(['Selection so far: ', mat2str(v_in)], 1);
70  if flag_first && ~flag_progress
71  if toc(t) > 1
72  ipro = progress2_open('FSEL_forward', [], 0, nf_eff);
73  flag_progress = 1;
74  end;
75  end;
76  if flag_progress
77  ipro = progress2_change(ipro, [], [], i);
78  end;
79 
80  flag_first = 0;
81  end;
82  if flag_progress
83  progress2_close(ipro);
84  end;
85 
86  % Output
87  log = log_as_fsel_forward();
88  log.v = v_in;
89  log.nfxgrade = nfxgrade;
90  log.grades = zeros(1, nf);
91 % log.grades(log.v) = 1;
92  log.fea_x = data(1).fea_x;
93  log.xname = data(1).xname;
94  log.xunit = data(1).xunit;
95  log.yname = o.fsg.get_yname();
96  log.yunit = o.fsg.get_yunit();
97  end;
98  end;
99 end
function irverbose(in s, in level)
Log generated by a as_fsel_forward.
Base Sub-dataset Generation Specification (SGS) class.
Definition: sgs.m:6
function progress2_change(in prgrss, in title, in perc, in i, in n)
function progress2_open(in title, in perc, in i, in n)
Forward Feature Selection.
function progress2_close(in prgrss)
FSG - Feature Subset Grader.
Definition: fsg.m:6
Analysis Session that produces a log_as_fsel.
Definition: as_fsel.m:2