IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
fselrepeater.m
Go to the documentation of this file.
1 %> @brief Analysis Session - Feature Selection Repeater
2 %>
3 %> This is the starting point to generate a histogram
4 classdef fselrepeater < as
5  properties
6  %> Subset Generation Specs to guide generation of different datasets to be passed to the Feature selection object.
7  sgs;
8  %> Feature selection object.
9  as_fsel;
10  %> Feature extractor to be used before passing the dataset to the feature selector. This may be used, e.g., if you want to
11  %> produce a histogram of the best, e.g., Principal Component Analysis factors. Instead of passing an already PCA-transformed
12  %> dataset to the as_fselrep, you can pass the PCA block in the @c fext property, so that at each iteration, the PCA block
13  %> will be trained with the training set of that iteration only, not the whole dataset.
14  fext;
15  %> =0. Whether to parallelize the Feature Selection repetitions
16  flag_parallel = 0;
17  end;
18 
19  methods
20  function o = fselrepeater()
21  o.classtitle = 'Feature Selection Repeater';
22  end;
23  end;
24 
25  methods(Access=protected)
26  %> Creates a @ref log_fselrepeater object
27  %>
28  %> This function may pass 1 or 2 datasets to the @ref as_fsel, depending on the @ref sgs property. It
29  %> does not check whether the @ref as_fselrep::as_fsel needs one or two datasets.
30  function log = do_use(o, data)
31  flag_fext = ~isempty(o.fext);
32  if flag_fext
33  ff = o.fext.boot();
34  else
35  ff = [];
36  end;
37 
38  obsidxs = o.sgs.get_obsidxs(data);
39  [no_reps, no_bites] = size(obsidxs); %#ok<NASGU>
40 
41  if ~o.flag_parallel
42  %---> Non-parallel version
43  ipro = progress2_open('Feature Selection Repeater', [], 0, no_reps);
44  for i_rep = 1:no_reps % Cross-validation loop
45  % #SAMECODE begin
46  datanow = data.split_map(obsidxs(i_rep, :), [], ff);
47  fsel_ = o.as_fsel;
48  log = fsel_.use(datanow); % GO!
49  logs(i_rep) = log;
50  % #SAMECODE end
51 
52  ipro = progress2_change(ipro, [], [], i_rep);
53  end;
54  progress2_close(ipro);
55  else
56  %---> PARALLEL version
57  parallel_open();
58  t = tic();
59 
60  parfor i_rep = 1:no_reps % Cross-validation loop
61  % #SAMECODE begin
62  datanow = data.split_map(obsidxs(i_rep, :), [], ff); %#ok<PFBNS>
63  fsel_ = o.as_fsel;
64  fsel_.data = datanow;
65  log = fsel_.go(); % GO!
66  logs(i_rep) = log;
67  % #SAMECODE end
68 
69  irverbose(sprintf('Done run %d/%d; ellapsed %10.1f seconds', i_rep, no_reps, toc(t)));
70  end;
71 
73  end;
74 
75  log = log_fselrepeater();
76  log.fea_x = data.fea_x;
77  log.xname = data.xname;
78  log.xunit = data.xunit;
79  log.logs = logs;
80  end;
81  end;
82 end
function irverbose(in s, in level)
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 parallel_close()
function progress2_open(in title, in perc, in i, in n)
Feature Extraction (Fext) base class.
Definition: fext.m:4
Base Block class.
Definition: block.m:2
Analysis Session - Feature Selection Repeater.
Definition: fselrepeater.m:4
Generated by fselrepeater, carries subsets of features.
function progress2_close(in prgrss)
Analysis Session (AS) base class.
Definition: as.m:6
function parallel_open(in no_labs)
Analysis Session that produces a log_as_fsel.
Definition: as_fsel.m:2