IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
ttlog_props.m
Go to the documentation of this file.
1 %> @brief Records properties from a block
2 classdef ttlog_props < ttlog
3  properties
4  %> Properties to record
5  propnames = [];
6  %> (Optional) Units corresponding to each element in propnames. Will be used by get_unit(), but this function is very tolerant
7  propunits = [];
8  %> (Vector of booleans, same size of ttlog_props::propnames). Whether the properties represent percentages or not. If this property is not assigned properly, 0 will be assumed whenever there
9  %> is a lack of information.
10  flag_perc = [];
11  %> Index of property to be used by the get_rate() method
12  idx_default = 1;
13  end;
14 
15  properties(SetAccess=protected)
16  %> Classifier's relevant properties. This is a structure array ((fields))x(time)
17  propvalues = {};
18  end;
19 
20  methods(Access=private)
21  function z = get_flag_perc_(o, idx)
22  if (~isempty(o.flag_perc) && numel(o.flag_perc) >= idx)
23  z = o.flag_perc(idx);
24  else
25  z = 0;
26  end;
27  end;
28  end;
29 
30  methods(Access=protected)
31  %> Returns cell of strings for table header
32  function ss = get_collabels(o)
33  ss = fields(o.propvalues);
34  end;
35 
36  %>
37  function o = do_allocate(o, tt)
38  vtemp = zeros(1, tt);
39  o.propvalues = cell(1, numel(o.propnames));
40  for i = 1:numel(o.propnames)
41  o.propvalues{i} = vtemp;
42  end;
43  end;
44  end;
45 
46  methods
47  function o = ttlog_props()
48  o.classtitle = 'Properties';
49  o.flag_params = 0;
50  o.moreactions = [o.moreactions, {'extract_dataset'}];
51  o.flag_ui = 0;
52  end;
53 
54 % @todo Better to implement something to show detailed information in the future. In the meantime, this is NOT the solution
55 % function s = get_description(o)
56 % ss = '';
57 % if ~isempty(o.propnames)
58 % ss = [' propnames = ' cell2str(o.propnames)];
59 % end;
60 % s = replace_underscores([class(o) ss]);
61 % end;
62 
63  %> @param pars Structure with a @c .clssr field.
64  function o = record(o, pars)
65  clssr = pars.clssr;
66 
67  o.t = o.t+1;
68  % Records relevant properties from the classifier.
69  for i = 1:numel(o.propnames)
70  o.propvalues{i}(o.t) = clssr.(o.propnames{i});
71  end;
72  end;
73 
74  %> @brief Returns recorded information
75  %>
76  %> Each column corresponds to a different property.
77  %>
78  %> @param aggr See below
79  %> <ul>
80  %> <li>Aggregation:<ul>
81  %> <li>@c 0 - INVALID</li>
82  %> <li>@c 1 - Sum</li>
83  %> <li>@c 2 - INVALID</li>
84  %> <li>@c 3 - Mean</li>
85  %> <li>@c 4 - Standard Deviation</li></ul></li>
86  %> <li>@c 5 - Minimum</li></ul></li>
87  %> <li>@c 6 - Maximum</li></ul></li>
88  %> </ul>
89  function X = get_X(o, aggr)
90  n = numel(o.propnames);
91  X = zeros(o.t, n);
92  for j = 1:n
93  X(:, j) = o.propvalues{j}';
94  end;
95 
96  if exist('aggr', 'var') && aggr > 0
97  switch (aggr)
98  case 1
99  X = sum(X, 1);
100  case 3
101  X = mean(X, 1);
102  case 4
103  X = std(X, [], 1);
104  case 5
105  X = min(X, [], 1);
106  case 6
107  X = max(X, [], 1);
108  otherwise
109  irerror(sprintf('Invalid option: %d', aggr));
110  end;
111  end;
112  end;
113 
114  function s = get_insane_html(o, pars)
115  s = stylesheet();
116  ff = o.get_collabels();
117 
118  s = cat(2, s, '<h1>Classifier Properties</h1>', 10);
119 
120  % Table header
121  s = cat(2, s, '<table><tr><td class="tdhe"></td>', 10);
122  for i = 1:numel(ff)
123  s = cat(2, s, '<td class="tdhe">', ff{i}, '</td>', 10);
124  end;
125  s = cat(2, s, '</tr>', 10);
126 
127  aa = {'Mean', 'Std', 'Min', 'Max'};
128  bb = [3, 4, 5, 6];
129  for i = 1:numel(aa)
130  X = o.get_X(bb(i));
131  s = cat(2, s, '<tr><td class="tdle">', aa{i}, '</td>', 10);
132  for j = 1:size(X, 2)
133  s = cat(2, s, '<td class="tdnu">', num2str(X(1, j)), '</td>', 10);
134  end;
135  s = cat(2, s, '</tr>', 10);
136  end;
137  s = cat(2, s, '</table>');
138  end;
139 
140  %> Generates one dataset with columns being propnames.
141  function d = extract_dataset(o)
142  d = irdata;
143  d.title = ['Classifier properties'];
144  d.fea_x = 1:nf;
145  d.fea_names = o.propnames;
146  d.X = o.get_X();
147  end;
148  end;
149 
150 
151  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152  %%% OVERWRITTEN BEHAVIOUR
153  methods
154  %> Returns average recorded value for the property specified by ttlog_props::idx_default
155  %> Pleas note that the name "rate" is unlikely to be the best denomination of what is actually returned (more likely to be time, or
156  %> number of rules etc). Of course, the name makes more sense in the @ref estlog class
157  function z = get_rate(o)
158  z = mean(o.propvalues{o.idx_default});
159  end;
160 
161  %> Returns whether the value returned by get_rate() is a percentage or not
162  function z = get_flag_perc(o)
163  z = o.get_flag_perc_(o.idx_default);
164  end;
165 
166  %> Returns string
167  %>
168  %> Returns property name specified by ttlog_props::idx_default. The @c title property can also be used. If the ttlog's title is a
169  %> string, will return the title instead
170  function z = get_legend(o)
171  if ischar(o.title)
172  z = o.title;
173  else
174  z = replace_underscores(o.propnames{o.idx_default});
175  end;
176  end;
177 
178  %> Returns all recorded values of property specified by ttlog_props::idx_default
179  function z = get_rates(o)
180  z = o.propvalues{o.idx_default};
181  end;
182 
183  function z = get_unit(o)
184  if iscell(o.propunits) && numel(o.propunits) >= o.idx_default
185  z = o.propunits{o.idx_default};
186  else
187  z = '?';
188  end;
189  end;
190  end;
191 end
Base class for all ensemble classifiers.
Definition: aggr.m:6
function irerror(in s)
Dataset class.
Definition: irdata.m:30
Estimation logs base class.
Definition: estlog.m:4
Base Block class.
Definition: block.m:2
function replace_underscores(in s)
function stylesheet()
Records properties from a block.
Definition: ttlog_props.m:2
Property idx_default
Index of property to be used by the get_rate() method.
Definition: ttlog_props.m:18
Property propnames
Properties to record.
Definition: ttlog_props.m:8
Train-Test Log.
Definition: ttlog.m:4