IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
log_as_fsel.m
Go to the documentation of this file.
1 %>@brief Log generated by an @ref as_fsel class
2 classdef log_as_fsel < irlog
3  properties
4  %> =[]. Indexes of selected features.
5  v = [];
6  %> Grades
7  grades;
8  %> x-values to which @ref grades are the y-values
9  fea_x;
10  %> (Cell of strings) Feature names. Same number of elements as fea_x
11  fea_names;
12  %> x-axis label
13  xname = '';
14  %> Unit of x-axis
15  xunit;
16  %> y-axis label (e.g., "classification rate", "-log_{10}(p-value)")
17  yname;
18  %> Unit of y-axis (unit of the values inside grades, e.g., "%")
19  yunit;
20  end;
21 
22  methods
23  function o = log_as_fsel()
24  o.classtitle = 'Feature Selection';
25  o.moreactions = [o.moreactions, {'extract_fsel'}];
26  o.flag_ui = 0;
27  end;
28 
29  %> @return an @ref fsel block with the selection in @ref fsel::v
30  function blk = extract_fsel(o)
31  blk = fsel();
32  blk = blk.copy_axes_from(o);
33  blk.v = o.v;
34  blk.grades = o.grades;
35  end;
36  end;
37 
38 
39  %----------ALL THIS DRAWING STUFF!
40  methods
41  function o = draw(o, data_hint, flag_mark)
42  if ~exist('data_hint', 'var')
43  data_hint = [];
44  end;
45 
46  if ~exist('flag_mark', 'var')
47  flag_mark = 0;
48  end;
49 
50  o.draw_grades(data_hint, 0);
51  if flag_mark
52  o.draw_markers();
53  end;
54 
55  o.draw_finish();
56  end;
57 
58  %> Gray columns for the features that were NOT selected
59  function draw_hachures(o, x, ymax)
60  if length(x) > 1
61  idxs = 1:length(o.grades);
62  idxs(o.v) = []; % I made the algorithm below in a complement fashion, then realized the mistake
63 
64  ni = length(idxs);
65 
66  for i = 1:ni+1
67  if i > ni && ni > 0 || (i > 1 && idxs(i)-idxs(i-1) > 1)
68 
69  if idxs(i1) == 1 % if feature is first one, picks distance between x-points from right
70  len = x(idxs(i1)+1)-x(idxs(i1));
71  else
72  len = x(idxs(i1))-x(idxs(i1)-1);
73  end;
74  x1 = x(idxs(i1))-len/4;
75 
76  i2 = i-1;
77  if idxs(i2) == length(x) % similar thing
78  len = x(idxs(i2))-x(idxs(i2)-1);
79  else
80  len = x(idxs(i2)+1)-x(idxs(i2));
81  end;
82  x2 = x(idxs(i2))+len/4;
83 
84 
85  if x2 < x1 % case when the x-axis is reversed
86  temp = x2;
87  x2 = x1;
88  x1 = temp;
89  end;
90  wid = x2-x1;
91  if wid < 0 % case when the x-axis is reversed
92  wid = -wid;
93  end;
94  draw_hachure([x1, 0, wid, ymax]);
95  hold on;
96  i1 = i;
97  elseif i == 1
98  i1 = i;
99  end;
100  end;
101  end;
102  end;
103 
104 
105  function o = draw_grades(o, data_hint, flag_histogram)
106  if any(o.grades ~= 0)
107  if ~isempty(data_hint)
108  xhint = data_hint.fea_x;
109  yhint = mean(data_hint.X);
110  else
111  xhint = [];
112  yhint = [];
113  end;
114 
115  draw_loadings(o.fea_x, o.grades, xhint, yhint, [], 0, [], 0, 0, 0, flag_histogram);
116  end;
117  end;
118 
119  function o = draw_markers(o)
120  if all(o.grades == 0)
121  plot(o.fea_x([1, end]), [0, 0], 'LineWidth', scaled(3), 'Color', [0, 0, 0]);
122  hold on;
123  draw_peaks(o.fea_x, o.grades, o.v, 0, find_color(1), 'p', scaled(20));
124  else
125  draw_peaks(o.fea_x, o.grades, o.v, 0);
126  end;
127  end;
128 
129  %> Takes care of axes, Frank, box
130  function o = draw_finish(o)
131  g = o.grades;
132  g(g == Inf) = [];
133  ymin = 0;
134  ymax = max(g)*1.05;
135  if ymax == 0
136  ymax = 1;
137  ymin = -1;
138  ylabel('');
139  set(gca, 'ytick', []);
140  else
141  format_yaxis(o);
142  end;
143  set(gca, 'ylim', [ymin, ymax]);
144  format_frank();
145  format_xaxis(o);
146 
147  make_box();
148  end;
149  end;
150 end
function draw_peaks(in x, in y, in indexes, in flag_text, in color, in marker, in markersize)
Feature Selection (FSel) class.
Definition: fsel.m:4
function make_box()
function find_color(in i)
Log generated by an as_fsel class.
Definition: log_as_fsel.m:2
Base Block class.
Definition: block.m:2
Property v
=[]. See get_feaidxs.m
Definition: fsel.m:10
function scaled(in i)
function draw_loadings(in x, in L, in x_hint, in hint, in legends, in flag_abs, in peakd, in flag_trace_minalt, in flag_draw_peaks, in flag_print_peaks, in flag_histogram, in flag_envelope, in colors)
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 format_yaxis(in par)
function format_frank(in F, in scale, in handles)
Analysis Session (AS) base class.
Definition: as.m:6
Log base class.
Definition: irlog.m:5
Analysis Session that produces a log_as_fsel.
Definition: as_fsel.m:2
function draw_hachure(in position)
function format_xaxis(in par)