IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
report_soitem_merger_fhg.m
Go to the documentation of this file.
1 %> @brief Histograms ane Biomarkers comparison tables - Several set-ups (including stabilizations). Comparisons using histograms, biomarker comparison tables/(heat maps).
3  properties
6  %> @ref biocomparer object
8 
10  %> Cell of subsetsprocessors to perform biomarkers comparisons using different subsetsprocessors. If used, the comparison will be per stab
11  %> Note that this property does not have a corresponding GUI input at the moment.
12  subsetsprocessors;
13 
14 
15  flag_draw_histograms = 1;
16  flag_draw_stability = 1;
17 
18  flag_biocomp_per_clssr = 1;
19  flag_biocomp_per_stab = 1;
20  flag_biocomp_all = 1;
21  %> Biomarkers comparison per subsetsprocessor
22  flag_biocomp_per_ssp = 1;
23  flag_nf4grades = 1;
24  %> =10. Stabilization number to be used in the "all" comparison
25  stab4all = 10;
26 
27  %> Whether to generate a table where the varying element will be the nf4grades of a fixed-nf4grades subsetsprocessor
28  flag_biocomp_nf4grades = 1;
29  end;
30 
31  methods
32  function o = report_soitem_merger_fhg()
33  o.classtitle = 'Several comparisons'; %Histograms and biomarkers comparison tables';
34  o.inputclass = 'soitem_merger_fhg';
35  o.flag_params = 1;
36  end;
37  end;
38 
39  methods(Access=protected)
40  function out = do_use(o, item)
41  out = log_html();
42  if o. flag_biocomp_per_clssr || o.flag_biocomp_per_stab || o.flag_biocomp_all || o.flag_nf4grades
43  item = item.calculate_stabilities(def_subsetsprocessor(o.subsetsprocessor));
44  end;
45 
46  s = o.get_standardheader(item);
47 
48  out.html = [s, o.get_html_graphics(item)];
49  out.title = item.get_description();
50  end;
51  end;
52 
53 
54  methods
55  %> Generates a table with the best in each architecture, with its respective time and confidence interval
56  %> @param item a soitem_merger_fhg object
57  function s = get_html_graphics(o, item)
58  s = '';
59 
60  ssp = def_subsetsprocessor(o.subsetsprocessor);
63 
64 
65  if o.flag_biocomp_per_clssr
66  % Finds out setups with more than one variation ("stabilizations")
67  groupidxs = item.find_methodologygroups();
68  n = numel(groupidxs);
69 
70  if n <= 0
71  % Giving no message at the moment
72  else
73  s = cat(2, s, '<h1>Stabilization comparison grouped by FHG-classifier setup</h1>', 10);
74  % Generates sub-reports for these groups separately
75  for i = 1:n
76  if i > 1; s = cat(2, s, '<hr />', 10); end;
77  s = cat(2, s, sprintf('<h2>FHG setup: "%s"</h2>\n', item.s_methodologies{groupidxs{i}(1)}), o.get_html_from_logs(item, groupidxs{i}));
78  end;
79 
80  s = cat(2, s, '<h2>FHG setups table merge</h2>', item.html_biocomparisontable_stab(ssp, pd, bc));
81 
82  s = cat(2, s, '<hr />', 10); % All sections divided by double HR
83  s = cat(2, s, '<hr />', 10);
84  end;
85  end;
86 
87  if o.flag_biocomp_per_stab
88  s = cat(2, s, '<h1>FHG setup comparison grouped by stabilization</h1>', 10);
89  stabs = unique(item.stabs);
90  for i = 1:numel(stabs)
91  s = cat(2, s, sprintf('<h2>Stabilization: "%d"</h2>\n', stabs(i)), o.get_html_from_logs(item, item.find_stab(stabs(i))));
92  end;
93  s = cat(2, s, '<hr />', 10);
94  s = cat(2, s, '<hr />', 10);
95  end;
96 
97  if o.flag_biocomp_all
98  % Picks one representant from each group
99  idxs = [item.find_stab(o.get_stab4all(item))]; %; item.find_stab(20)];
100  idxs = idxs(:)'; % makes 10, 20, 10, 20, ...
101  idxs = [idxs, item.find_single()];
102  s = cat(2, s, '<h1>Comparison of all setups</h1>', 10, ...
103  '<p>In this section, FHG-classifier setups will use stabilization=<b>', int2str(o.get_stab4all(item)), '</b></p>', 10, ...
104  o.get_html_from_logs(item, idxs));
105  % Generates one report for comparison among ALL different methodologies
106  s = cat(2, s, '<hr />', 10);
107  s = cat(2, s, '<hr />', 10);
108  end;
109 
110 
111  if o.flag_biocomp_nf4grades
112  ssp = def_subsetsprocessor(o.subsetsprocessor);
113  s = cat(2, s, '<h1>Comparison of number of selected features grouped per stabilization</h1>', 10, ...
114  '<p>Number of selected features varying from 1 to <b>', int2str(item.logs(1).nfmax), '</b></p>', 10, ...
115  '<p>Only the FHG-classifier setups are compared in this section. Each stabilization case summarizes all FHG-classifier set-ups.</p>', 10, ...
116  '<p>Base subsets processor used in this section (from which nf4grades will vary):<br>' , 10, ...
117  '<pre>', ssp.get_report(), '</pre></p>', 10);
118 
119 
120  stabs = unique(item.stabs);
121  stabs(stabs < 0) = [];
122  if isempty(stabs)
123  s = cat(2, s, '<p><font color=red>Comparison of number of selected features available for FHG-classifier set-ups (with stabilization) only.</font></p>');
124  else
125  for i = 1:numel(stabs)
126  s = cat(2, s, sprintf('<h2>Stabilization: %02d</h2>\n', stabs(i)));
127  s = cat(2, s, o.get_html_biocomp_nf4grades(item, item.find_stab(stabs(i)), ssp));
128  end;
129 
130  s = cat(2, s, sprintf('<h2>Stabilizations: all</h2>\n'));
131  s = cat(2, s, o.get_html_biocomp_nf4grades(item, find(item.stabs >= 0), ssp)); %#ok<FNDSB>
132  end;
133  s = cat(2, s, '<hr />', 10);
134  s = cat(2, s, '<hr />', 10);
135  end;
136 
137  if o.flag_biocomp_per_ssp
138  ssps = o.get_ssps();
139  s = cat(2, s, '<h1>Comparison of subsets processors</h1>', 10);
140 
141  stabs = unique(item.stabs);
142  stabs(stabs < 0) = [];
143  if isempty(stabs)
144  s = cat(2, s, '<p><font color=red>Comparison of subsets processors available for FHG-classifier setups (with stabilization) only</font></p>');
145  else
146  for i = 1:numel(stabs)
147  s = cat(2, s, sprintf('<h2>Stabilization: %02d</h2>\n', stabs(i)));
148  s = cat(2, s, o.get_html_biocomp_ssps(item, item.find_stab(stabs(i)), ssps));
149  end;
150 
151  s = cat(2, s, sprintf('<h2>Stabilization: all</h2>\n'));
152  s = cat(2, s, o.get_html_biocomp_ssps(item, find(item.stabs >= 0), ssps)); %#ok<FNDSB>
153  end;
154 
155 
156  % Reports the objects used
157  s = cat(2, s, '<h2>Subsets processors used in this section</h2>');
158  a = ssps;
159  for i = 1:numel(a)
160  obj = a{i};
161  s = cat(2, s, '<p><b>', obj.get_description, '</b></p>', 10, '<pre>', obj.get_report(), '</pre>', 10);
162  end;
163 
164  s = cat(2, s, '<hr />', 10);
165  s = cat(2, s, '<hr />', 10);
166  end;
167 
168 
169  % Average stability curves
170  if o.flag_draw_stability
171  idxs = find(item.stabs >= 0);
172  n = numel(idxs);
173  if n <= 0
174  s = cat(2, s, '<p><font color=red>Average stability curve per stabilization available for methodologies with stabilization only</font></p>');
175  else
176  for i = 1:n
177  log_rep = item.logs(idxs(i));
178  ds_stab(i) = log_rep.extract_dataset_stabilities(); %#ok<AGROW>
179  ds_stab(i).classlabels = {sprintf('stab%02d', item.stabs(idxs(i)))}; %#ok<AGROW>
180  end;
181  ds = o.merge_ds_stab(ds_stab);
182  ov = vis_hachures();
183  figure;
184  ov.use(ds);
185  maximize_window([], 1.8);
186  s = cat(2, s, '<h1>Average stability curve per stabilization</h1>', 10);
187  s = cat(2, s, o.save_n_close([], 0));
188  end;
189  s = cat(2, s, '<hr />', 10);
190  s = cat(2, s, '<hr />', 10);
191  end;
192 
193  if o.flag_nf4grades
194  %-----> nf for grades table
195  s = cat(2, s, '<h1>Number of informative features table</h1>', 10, ...
196  '<p>These numbers will only vary if the base subsetsprocessor provided nas nf4gradesmode=''stability''.</p>', 10, ...
197  o.get_html_nf4grades(item, 1:numel(item.logs)));
198  s = cat(2, s, '<hr />', 10);
199  s = cat(2, s, '<hr />', 10);
200  end;
201 
202  % Reports the objects used
203  s = cat(2, s, '<h1>Properties of some objects used</h1>');
204  a = {pd, bc};
205  for i = 1:numel(a)
206  obj = a{i};
207  s = cat(2, s, '<p><b>', obj.get_description, '</b></p>', 10, '<pre>', obj.get_report(), '</pre>', 10);
208  end;
209  s = cat(2, s, '<hr />', 10);
210  s = cat(2, s, '<hr />', 10);
211  end;
212 
213  %
214  function s = get_html_biocomp_nf4grades(o, item, idxs, ssp)
215  s = '';
216  [temp, M, titles] = item.html_biocomparisontable_nf4grades(idxs, ssp, o.peakdetector, o.biocomparer);
217  s = cat(2, s, temp);
218 
219  % Draws as image as well, easier to perceive
220  figure;
221  means = mean(M, 3);
222  imagesc(means);
223  xtick = 1:size(M, 1);
224  set(gca(), 'xtick', xtick, 'ytick', xtick, 'xticklabel', titles, 'yticklabel', titles);
225  hcb = colorbar();
226  format_frank([], [], hcb);
227  s = cat(2, s, o.save_n_close([], 0));
228  end;
229 
230  function s = get_html_biocomp_ssps(o, item, idxs, ssps)
231  s = '';
232  [temp, M, titles] = item.html_biocomparisontable_ssps(idxs, ssps, o.peakdetector, o.biocomparer); %#ok<NASGU,ASGLU>
233  s = cat(2, s, temp);
234  aa = arrayfun(@int2str, 1:numel(titles), 'UniformOutput', 0); % Makes ticks 1, 2, 3 ... because titles are too long
235 
236  % Draws as image as well, easier to perceive
237  figure;
238  means = mean(M, 3);
239  imagesc(means);
240  xtick = 1:size(M, 1);
241  set(gca(), 'xtick', xtick, 'ytick', xtick, 'xticklabel', aa, 'yticklabel', aa);
242  hcb = colorbar();
243  format_frank([], [], hcb);
244  s = cat(2, s, o.save_n_close([], 0));
245  end;
246 
247 
248  %
249  function s = get_html_from_logs(o, item, idxs)
250  s = '';
251  ssp = def_subsetsprocessor(o.subsetsprocessor);
252 
253  % Legend
254  if o.flag_draw_histograms
255  s = cat(2, s, '<h3>Histograms</h3>', 10);
256 
257  % Legend
258  log_rep = item.logs(idxs(1));
259  figure;
260  log_rep.draw_stackedhist_for_legend();
261  show_legend_only();
262  s = cat(2, s, o.save_n_close([], 0, []));
263  v = vis_stackedhists();
264  v.data_hint = []; % Could have a o.data_hint;
265  v.peakdetector = def_peakdetector(o.peakdetector);
266  end;
267 
268  n = numel(idxs);
269  for i = 1:n
270  log_rep = item.logs(idxs(i));
271  if o.flag_draw_histograms
272  hist = ssp.use(log_rep);
273  figure;
274  v.use(hist);
275  make_axis_gray();
276  legend off;
277  % Will occupy 70% of screen width, and render the IMG tag without size specification
278  maximize_window(gcf(), 4, .7);
279  s = cat(2, s, '<h3>', item.get_logdescription(idxs(i)), '</h3>', o.save_n_close([], 0));
280  end;
281 
282  if o.flag_draw_stability
283  % Stability curve
284  ds_stab(i) = log_rep.extract_dataset_stabilities(); %#ok<AGROW>
285  ds_stab(i).classlabels = {replace_underscores(sprintf('%s stab%02d', item.s_methodologies{idxs(i)}, item.stabs(idxs(i))))}; %#ok<AGROW>
286  end;
287  end;
288 
289  % Stability curves
290 % ds = o.merge_ds_stab(ds_stab);
291 % ov = vis_alldata();
292  if o.flag_draw_stability
293  for j = 1:2 % 1 pass for the legend, second for the graphics
294  figure;
295  for i = 1:n
296  plot(ds_stab(i).fea_x, ds_stab(i).X, 'Color', find_color(i), 'LineWidth', scaled(2)); % 'LineStyle', find_linestyle(i),
297  hold on;
298  end;
299  format_xaxis(ds_stab(1));
300  format_yaxis(ds_stab(1));
301  set(gca, 'xlim', get(gca, 'xlim'), 'ylim', get(gca, 'ylim')); % Just to switch to manual mode
302  make_box();
303 
304  if j == 1
305  legend(cat(2, ds_stab.classlabels));
306  format_frank();
307  show_legend_only();
308  else
309  format_frank();
310  end;
311  s = cat(2, s, o.save_n_close([], 0));
312  end;
313 
314  end;
315 
316  % Biomarkers coherence tables
317  s = cat(2, s, '<h3>Biomarkers coherence</h3>', 10, item.html_biocomparisontable(idxs, ssp, o.peakdetector, o.biocomparer));
318  end;
319 
320 
321  %> nf4grades table
322  function s = get_html_nf4grades(o, item, idxs)
323  ssp = def_subsetsprocessor(o.subsetsprocessor);
324  s = item.html_nf4grades(idxs, ssp);
325  end;
326  end;
327 
328  methods
329  %
330  function ssps = get_ssps(o)
331  if isempty(o.subsetsprocessors)
332  ssps = report_log_fselrepeater_histcomp.get_defaultsubsetsprocessors();
333  else
334  ssps = o.subsetsprocessors;
335  end;
336  end;
337 
338  %> Because o.stab4all may be out of the chart
339  %> If o.stab4all was not practiced, will return maximum
340  %> stabilization used.
341  function n = get_stab4all(o, item)
342  if any(item.stabs == o.stab4all)
343  n = o.stab4all;
344  else
345  n = max(item.stabs);
346  end;
347  end;
348  end;
349 
350  methods(Access=protected)
351  %> Merges datasets but first makes sure they all have same number of features
352  function ds = merge_ds_stab(o, daa) %#ok<MANU>
353  nf = max([daa.nf]);
354  for i = 1:numel(daa)
355  if daa(i).nf < nf
356  temp = daa(i).X;
357  [ro, co] = size(temp);
358  daa(i).X = NaN(ro, nf);
359  daa(i).X(1:ro, 1:co) = temp;
360  daa(i).fea_x = 1:nf;
361  daa(i) = daa(i).assert_fix(); % just in case
362  end;
363  end;
364  ds = data_merge_rows(daa);
365  end;
366  end;
367 end
Histograms ane Biomarkers comparison tables - Several set-ups (including stabilizations). Comparisons using histograms, biomarker comparison tables/(heat maps).
Peak Detector.
Definition: peakdetector.m:6
Pre-processing block base class.
Definition: pre.m:2
function def_peakdetector(in out)
Generated by irreport, carries HTML contents.
Definition: log_html.m:2
function def_subsetsprocessor(in out)
static function get_defaultsubsetsprocessors()
function def_biocomparer(in out)
Processor of a set of subsets of features.
Base for all reports that operate on a soitem object.
Definition: report_soitem.m:2