IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
rater.m
Go to the documentation of this file.
1 %> @brief "Rater" class
2 %>
3 %> This class makes simple the job evaluating a classifier performance through cross-validation. It fills in all
4 %> properties with default values, except from @c data:
5 %> @arg Default postpr_est
6 %> @arg Default postpr_test
7 %> @arg Default sgs
8 %> @arg Default ttlog
9 %> @arg Even default classifier
10 %>
11 %> A more complex (but complete) alternative is @ref reptt_blockcube
12 %>
13 %> @sa uip_rater.m, demo_rater.m
14 classdef rater < as
15  properties
16  clssr;
17  %> (Optional). If two datasets are passed, a SGS is not created, but the datasets are used instead for a single train-test
18  sgs;
19  %> (Optional) Block to post-process the test data.
20  postpr_test;
21  %> Block to post-process the estimation issued by the classifier.
22  postpr_est;
23  ttlog;
24  end;
25 
26  properties(SetAccess=protected)
27  flag_sgs;
28  end;
29 
30 
31  methods
32  function o = rater()
33  o.classtitle = 'Rater';
34  end;
35  end;
36 
37  methods(Access=protected)
38  %> Returns the object with its ttlog ready to have its get_rate() called.
39  function log = do_use(o, data)
40  o = o.check(data);
41 
42  if o.flag_sgs
43  obsidxs = o.sgs.get_obsidxs(data);
44  datasets = data.split_map(obsidxs(:, [1, 2]));
45 
46  no_reps = size(obsidxs, 1);
47 
48  log = o.ttlog.allocate(no_reps);
49  ipro = progress2_open('RATER', [], 0, no_reps);
50  for i = 1:no_reps
51  log = traintest(log, o.clssr, datasets(i, 1), datasets(i, 2), o.postpr_test, o.postpr_est);
52  ipro = progress2_change(ipro, [], [], i);
53  end;
54  progress2_close(ipro);
55  else
56  log = o.ttlog.allocate(1);
57  log = traintest(log, o.clssr, data(1), data(2), o.postpr_test, o.postpr_est);
58  end;
59  end;
60 
61  function z = get_rate(o)
62  o = o.go();
63  z = o.ttlog.get_rate();
64  end;
65 
66  function z = get_rate_with_clssr(o, x)
67  o.clssr = x;
68  log = o.go();
69  z = log.get_rate();
70  end;
71 
72  function o = check(o, data)
73  o.clssr = def_clssr(o.clssr);
74  if isempty(o.postpr_est)
75  o.postpr_est = def_postpr_est();
76  o.postpr_test = def_postpr_test(); % Overrides pospr_test because need a harmonic pair
77  end;
78 
79  o.flag_sgs = 1;
80  if isempty(o.sgs)
81  if numel(data) == 1
82  irverbose('Rater is creating default SGS', 2);
83  o.sgs = def_sgs();
84  else
85  o.flag_sgs = 0;
86  end;
87  end;
88 
89  if isempty(o.ttlog)
90  irverbose('Rater is creating default ttlog estlog_classxclass', 2);
91  z = estlog_classxclass();
92  z.estlabels = data(1).classlabels;
93  z.testlabels = z.estlabels;
94  o.ttlog = z;
95  end;
96  end;
97  end;
98 end
function irverbose(in s, in level)
Base Sub-dataset Generation Specification (SGS) class.
Definition: sgs.m:6
"Rater" class
Definition: rater.m:14
function progress2_change(in prgrss, in title, in perc, in i, in n)
function progress2_open(in title, in perc, in i, in n)
function def_sgs(in out)
function traintest(in logs, in blk, in ds_train, in ds_test, in postpr_test, in postpr_est)
Records (test class)x([rejected, estimation class]) hits.
Classifiers base class.
Definition: clssr.m:6
function progress2_close(in prgrss)
Analysis Session (AS) base class.
Definition: as.m:6
function def_clssr(in out)
function def_postpr_test(in out)
function def_postpr_est(in out)
REpeated Train-Test - Block Cube.
Train-Test Log.
Definition: ttlog.m:4