IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
factorscurve.m
Go to the documentation of this file.
1 %> @brief Used to calculate (number of factors)x(performance) curves
2 %>
3 %> This class uses a reptt_sgs and a fcon block (@ref fcon_mold) that has the @c no_factors property.
4 %>
5 %> It populates the reptt_sgs block with many replications of @c fcon_mold, with increasing values in the @c no_factors property
6 %>
7 %> It has a @ref extract_reptt_sgs function for the GUI. However, a property box is not implemented at the moment.
8 %>
9 %> Please note that a Standardization block will be automatically inserted between the Feature Extraction block and the Classifier.
10 classdef factorscurve < as
11  properties
12  fcon_mold;
13  %> The classifier
14  clssr;
15  %> =(1:nf in dataset). Vector with a list of numbers of factors to try.
16  no_factorss = [];
17 
18  %> SGS object. It is optional if @ref data has more than 1 element. If @ref cube is passed, this property is ignored altogether.
19  sgs;
20  %> =[]. See @reptt
21  postpr_test;
22  %> =decider(). See @ref reptt
23  postpr_est = decider();
24 
25  %> Mold fcon block with the no_factors property
26  %> = 0. Whether to parallelize the calculation
27  flag_parallel = 0;
28  end;
29 
30  methods
31  function o = factorscurve()
32  o.classtitle = '(#factors)x(performance) curve';
33  o.moreactions = [o.moreactions, {'go', 'extract_reptt'}];
34  end;
35 
36  function u = create_cube(o, data)
37  l1 = estlog_classxclass();
38  l1.estlabels = data.classlabels;
39  l1.testlabels = data.classlabels;
40  l1.title = 'rates';
41 
42  u = reptt_blockcube();
43  u.log_mold = {l1};
44  if numel(data) == 1
45  u.sgs = def_sgs(o.sgs);
46  end;
47  u.flag_parallel = o.flag_parallel;
48 
49  u.postpr_test = o.postpr_test;
50  u.postpr_est = o.postpr_est;
51  end;
52  end;
53 
54  methods(Access=protected)
55  %> @return irdata object
56  function out = do_use(o, data)
57 
58  if isempty(o.no_factorss)
59  nff = 1:data.nf;
60  else
61  nff = o.no_factorss;
62  if any(nff > data.nf)
63  irverbose('INFO: trimmed verctor of numbers of factors because there were values above the number of features in the input dataset');
64  end;
65  nff(nff > data.nf) = [];
66  end;
67  neff = numel(nff);
68  ss = pre_std(); % Standardization block
69  bb = cell(1, neff); % Cell array of blocks
70  cl = def_clssr(o.clssr);
71  for i = 1:neff
72  btemp = o.fcon_mold;
73  btemp.no_factors = nff(i);
74 
75  blk = block_cascade();
76  blk.title = sprintf('%d factor%s', i, iif(i == 1, '', 's'));
77  blk.blocks = {btemp, ss, cl};
78 
79  bb{i} = blk;
80  end;
81 
82  u = o.create_cube(data);
83  u.block_mold = bb;
84  log = u.use(data);
85 
86  sov = sovalues();
87  sov = sov.read_log_cube(log);
88 
89  out = irdata();
90  out.title = [data.title, iif(isempty(data.title), '', ' - '), '(#factors)x(%rate) curve - ', o.fcon_mold.classtitle, '->', o.clssr.classtitle];
91  out.xname = 'Number of factors';
92  out.xunit = '';
93  out.yname = 'Classification rate';
94  out.yunit = '%';
95  out.fea_x = nff;
96  out.X = permute(sov.get_Y('rates'), [3, 2, 1]);
97  out.classes = zeros(size(out.X, 1), 1);
98  out.classlabels = {o.fcon_mold.get_description()};
99  out = out.assert_fix();
100  end;
101  end;
102 end
Cascade block: final instantializable class.
Definition: block_cascade.m:4
function irverbose(in s, in level)
Standardization (trained)
Definition: pre_std.m:4
Base Sub-dataset Generation Specification (SGS) class.
Definition: sgs.m:6
Dataset class.
Definition: irdata.m:30
Block that resolves estimato posterior probabilities into classes.
Definition: decider.m:10
function use(in o, in data)
Applies block to data.
function def_sgs(in out)
Base Block class.
Definition: block.m:2
Records (test class)x([rejected, estimation class]) hits.
Feature Construction (FCon) base class.
Definition: fcon.m:2
Classifiers base class.
Definition: clssr.m:6
Used to calculate (number of factors)x(performance) curves.
Definition: factorscurve.m:10
function iif(in cond, in x1, in x2)
REPeated Train-Test.
Definition: reptt.m:8
Analysis Session (AS) base class.
Definition: as.m:6
function def_clssr(in out)
REpeated Train-Test - Block Cube.