IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
log_fselrepeater.m
Go to the documentation of this file.
1 %> @brief Generated by @ref fselrepeater, carries subsets of features
3  properties
4  %> Extracted from data
5  fea_x;
6  %> Extracted from data
7  xname;
8  %> Extracted from data
9  xunit;
10  %> Array of log_as_fsel objects
11  logs;
12  end;
13 
14  properties(Dependent)
15  %> (Read-only) Cell containing the features selected at each repetition. This will be the base to build a histogram.
16  %> @note This has to be a cell because the number of selected features may not be fixed at each repetition. For example, feature selection
17  %> methods that pick peaks of the grades curve may find the grades curve to have eventually more or less peaks.
18  %>
19  %> Dimensions [number of repetitions]; each element is a vector of dimension [o.as_fsel.nf_select (maximum)]
20  subsets;
21  %> Meaning (Number of features)x(rate);
22  %> Dimensions [number of repetitions]x[o.as_fsel.nf_select]
23  %> The numbers are the calculated "grades"
24  nfxgrade;
25  %> Maximum number of features selected
26  nfmax;
27  end;
28 
29  methods
30  function o = log_fselrepeater()
31  o.classtitle = 'Subsets log';
32  o.moreactions = [o.moreactions, {'extract_dataset_nfxgrade', 'extract_dataset_stabilities'}];
33  o.flag_ui = 0;
34  end;
35 
36 
37  function n = get.nfmax(o)
38  n = max(cellfun(@numel, o.subsets));
39  end;
40 
41 
42  %> @returns A cell of vectors
43  function out = get.subsets(o)
44  n = numel(o.logs);
45  out = cell(1, n);
46  for i = 1:n
47  out{i} = o.logs(i).v;
48  end;
49  end;
50 
51  %> @returns A matrix [number of repetitions]x[number of features selected]
52  function out = get.nfxgrade(o)
53  n = numel(o.logs);
54  nf = o.nfmax;
55  out = NaN(n, nf);
56  for i = 1:n
57  temp = o.logs(i).nfxgrade;
58  out(i, 1:numel(temp)) = temp;
59  end;
60  end;
61  end;
62 
63 
64  % *-*-*-*-*-*-* TOOLS
65  methods
66  %> Returns a (feature position)x(stability curve)
67  %>
68  %> @param type Type of stability measure (e.g., 'kun')
69  %> @param type2 'uni' or 'mul'
70  %>
71  %> @sa featurestability.m
72  function z = get_stabilities(o, type, type2)
73  if ~isempty(o.pvt_z) && strcmp(o.pvt_type, type) && strcmp(o.pvt_type2, type2)
74  z = o.pvt_z;
75  else
76  z = featurestability(o.subsets, numel(o.fea_x), type, type2);
77  end;
78  end;
79 
80 
81  %> Extract dataset to visualize FFS progress
82  %>
83  %> Each row of the dataset shows the performance progression of a Forward Feature Selection (FFS) run.
84  function out = extract_dataset_nfxgrade(o)
85  if isempty(o.logs)
86  irerror('Empty logs');
87  end;
88  if ~isprop(o.logs(1), 'nfxgrade')
89  irerror(sprintf('Logs of wrong class: "%s"', class(o.logs(1))));
90  end;
91 
92  out = irdata();
93  out.X = o.nfxgrade;
94  out.classlabels = {'Grade'};
95  out.fea_x = 1:size(o.nfxgrade, 2);
96  out.xname = 'Number of features';
97  out.xunit = '';
98  out.yname = 'Grade';
99  out.yunit = '';
100  out.title = 'Number of features X Grades';
101  out = out.assert_fix();
102  end;
103 
104  %> Extract dataset with one row containing stability measures
105  %>
106  %> @param type Type of stability measure (e.g. 'kun'). See @ref featurestability.m
107  %> @param type2 'uni' or 'mul'. See @ref featurestability.m
108  %>
109  %> @sa featurestability.m
110  function out = extract_dataset_stabilities(o, type, type2)
111  if nargin < 3 || isempty(type)
112  type = 'kun';
113  end;
114  if nargin < 3 || isempty(type2)
115  type2 = 'uni';
116  end;
117  if isempty(o.logs)
118  irerror('Empty logs');
119  end;
120 
121  out = irdata();
122  out.X = o.get_stabilities(type, type2);
123  out.classlabels = {'Stability'};
124  out.fea_x = 1:size(out.X, 2);
125  out.xname = iif(type2 == 'uni', 'Feature rank', 'Number of features');
126  out.xunit = '';
127  out.yname = 'Stability';
128  out.yunit = '';
129  out.title = sprintf('Stabilities (''%s'', ''%s'')', type, type2);
130  out = out.assert_fix();
131  end;
132 
133  %> Draws stacked histogram for legend purpose only
134  function o = draw_stackedhist_for_legend(o)
135  ds_hint = [];
136  ssp = subsetsprocessor();
137  pd = def_peakdetector();
138  hist = ssp.use(o);
139  hist.draw_stackedhists(ds_hint, {[], [.8, .8, .8]}, pd);
140  freezeColors();
141  end;
142  end;
143 
144 
145 
146  %> This system was set to speed up the report generation. Stability vectors won't have to be recalculated
147  %>
148  %> However, note that if o.subsets is reset, the following properties will get out of sync. So, use carefully.
149  properties(Access=private)
150  pvt_z;
151  pvt_type;
152  pvt_type2;
153  end;
154 
155  methods
156  %> @brief Stores stabilities vector to prevent frequent recalculation
157  function o = calculate_stabilities(o, type, type2)
158  o.pvt_z = o.get_stabilities(type, type2);
159  o.pvt_type = type;
160  o.pvt_type2 = type2;
161  end;
162  end;
163 end
function irerror(in s)
Dataset class.
Definition: irdata.m:30
Log generated by an as_fsel class.
Definition: log_as_fsel.m:2
function def_peakdetector(in out)
Analysis Session - Feature Selection Repeater.
Definition: fselrepeater.m:4
Generated by fselrepeater, carries subsets of features.
function iif(in cond, in x1, in x2)
Property flag_ui
(GUI setting) Whether to "publish" in blockmenu and datatool. Note that a class can be "published" wi...
Definition: irobj.m:60
function featurestability(in subsets, in nf, in type, in type2)
Processor of a set of subsets of features.
Log base class.
Definition: irlog.m:5
Property fea_x
feature x-axis
Definition: irdata.m:77