IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
log_celldata.m
Go to the documentation of this file.
1 %> @brief Learning curve: (percent dataset used for training)x(classification rate)
2 %>
3 %> The purpose of this class is to store a cell of vectors (the @ref celldata property). The vectors may vary in size.
4 %>
5 %> Each row has a different "name" (@ref rownames property).
6 %>
7 %> If generated by a @ref reptt_sgs, there will be one case only (first log) and the changing conditions are the different blocks.
8 %>
9 %> @sa as_dsperc_x_rate, reptt_sgs
10 classdef log_celldata < irlog
11  properties
12  %> X-axis. Related to the columns of celldata
13  fea_x;
14  %> X-axis label. Related to the columns of celldata
15  xname = '?';
16  %> X-axis unit. Related to the columns of celldata
17  xunit = '';
18  %> X-axis label. Related to the rows of celldata
19  yname = '?';
20  %> X-axis unit. Related to the rows of celldata
21  yunit = '';
22 
23  %> Cell of dimensions (number of cases)x(number of conditions per case)
24  %> @arg Option 1: Cell of estlogs to extract the rate from
25  %> @arg Option 2: Cell of vectors (of various sizes) whose averages will be taken
26  celldata;
27  %> Case names, for legend
28  rownames;
29  end;
30 
31  methods
32  function o = log_celldata()
33  o.classtitle = 'Cell data';
34  o.moreactions = [o.moreactions, {'extract_dataset'}];
35  o.flag_ui = 0;
36  end;
37 
38 
39 
40  %> Draws with hachures (optional)
41  %>
42  %> @param idx=all Indexes of cases
43  %> @param flag_std=1 Whether to draw the standard deviation as well
44  %> @param flag_perc_x=[] Whether to make the x-axis a percentage. If not passed, will use internal setup
45  %> @param flag_perc_y=[] Whether to make the y-axis a percentage. If not passed, will use internal setup
46  function draw(o, idx, flag_std)
47  if ~exist('idx', 'var') || isempty(idx)
48  idx = 1:size(o.celldata, 1);
49  end
50 
51  if ~exist('flag_std', 'var') || isempty(flag_std)
52  flag_std = 1;
53  end;
54 
55  nidx = numel(idx);
56  hh = [];
57  for i = 1:nidx
58  if size(o.celldata, 1) < idx(i)
59  irerror(sprintf('celldata property has less than %d cases(s)!', idx(i)));
60  end;
61 
62  allvalues = o.celldata(idx(i), :);
63  curve = cellfun(@(x) mean(x), allvalues);
64 
65  if flag_std
66  stds = cellfun(@(x) std(x), allvalues);
67  draw_stdhachure(o.fea_x, curve, stds, find_color(i));
68  hold on;
69  end;
70 
71  hh(i) = plot(o.fea_x, curve, 'Color', find_color(i), 'LineWidth', scaled(3));
72  legends{i} = o.rownames{idx(i)};
73 
74  hold on;
75 
76 % % Polynomial fit
77 % p = polyfit(MX*o.fea_x, MY*curve, 9);
78 % pv = polyval(p, MX*o.fea_x);
79 % plot(MX*o.fea_x, pv, 'k--', 'LineWidth', scaled(2));
80  end;
81 
82  if ~isempty(hh)
83  legend(hh, legends);
84  end;
85  title(o.get_description());
86  format_xaxis(o);
87  format_yaxis(o);
88  format_frank();
89  make_box();
90  end;
91 
92 
93 
94 
95  %> Extracts a dataset
96  %>
97  %> Dataset X will have same dimension of @ref celldata. Values will be the averages of each vector within @ref celldata
98  function data = extract_dataset(o)
99  [nrows, ncols] = size(o.celldata); %#ok<NASGU>
100  data = irdata();
101  data.X = cellfun(@(x) mean(x), o.celldata);
102  data.classes = (0:nrows-1)';
103  data.classes = zeros(nrows, 1);
104  data.classlabels = o.rownames;
105  data.fea_x = o.fea_x;
106  data.xname = o.xname;
107  data.xunit = o.xunit;
108  data.yname = o.yname;
109  data.yunit = o.yunit;
110  data.title = ['Dataset generated by ', o.get_description()];
111  data = data.assert_fix();
112  end;
113  end;
114 end
function make_box()
function find_color(in i)
function irerror(in s)
Dataset class.
Definition: irdata.m:30
function scaled(in i)
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
function draw_stdhachure(in xaxis, in curve, in stds, in color)
function format_xaxis(in par)
(dataset %) x (classification rate) curve
Learning curve: (percent dataset used for training)x(classification rate)
Definition: log_celldata.m:10