IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
log_cube.m
Go to the documentation of this file.
1 %> @brief Log generated by a @ref reptt_blockcube
2 %>
3 %> This has a 4-D cell of @ref irlog
4 %>
5 %> Each slice logs(:, :, :, i) accounts for a different log class
6 %>
7 %> @sa reptt_blockcube
8 %>
9 classdef log_cube < irlog
10  properties
11  logs;
12  blocks;
13  end;
14 
15  properties(SetAccess=protected)
16  no_datasets;
17  end;
18 
19  methods
20  function o = log_cube()
21  o.classtitle = 'Cube log';
22  o.flag_ui = 0;
23  o.moreactions{end+1} = 'extract_sovalues';
24  end;
25 
26  %> Creates a sovalues object
27  %>
28  %> Only works if the @ref log_cube::logs property has dimension [n, 1, 1, *]
29  %>
30  %> @return a @ref sovalues object
31  function sov = extract_sovalues(o)
32  [a, b, c, d] = size(o.logs); %#ok<*NASGU>
33  if b > 1 || c > 1
34  irerror('Extraction of sovalues only works if the cube was a single column!');
35  end;
36 
37  sov = sovalues();
38  sov.ax(2) = raxisdata_singleton('Singleton');
39  sov.ax(1) = raxisdata();
40  sov.ax(1).label = 'Case';
41  sov.ax(1).values = 1:size(o.logs, 1);
42  sov.values = sovalues.read_logss(o.logs);
43  specs = cellfun(@(x) x.get_description(), o.blocks(:, :, :, 1), 'UniformOutput', 0);
44  sov = sov.set_field('spec', specs);
45 
46  end;
47 
48  %> Pre-allocates the @ref log property; prepares to record.
49  %>
50  %> @param log_mold a cell of @ref irlog objects
51  %> @param block_mold a cell of @ref block objects. Only used to get allocation dimensions
52  %> @param no_reps Number of repetitions, such as "k" from a k-fold cross-validation
53  function o = allocate_logs(o, log_mold, block_mold, no_reps)
54 
55  % Makes sure that all log_mold elements have a title that can be used as a field name
56  for i = 1:numel(log_mold)
57  log = log_mold{i};
58  try
59  a.(log.title) = 10; % Checks validity of log title as field name
60  catch ME
61  if isempty(log.title)
62  irerror('Log title is empty!');
63  end;
64  irerror(sprintf('log title "%s" cannot be used as a field name!', log.title));
65  end;
66  end;
67 
68  [ni, nj, nk] = size(block_mold);
69  nl = numel(log_mold);
70 
71  for il = 1:nl
72  for ii = 1:ni
73  for ij = 1:nj
74  for ik = 1:nk
75  if ~isempty(block_mold{ii, ij, ik})
76  o.logs{ii, ij, ik, il} = log_mold{il}.allocate(no_reps);
77  else
78  o.logs{ii, ij, ik, il} = [];
79  end;
80  end;
81  end;
82  end;
83  end;
84  end;
85  end;
86 end
Property logs
Definition: log_cube.m:14
Log generated by a reptt_blockcube.
Definition: log_cube.m:9
function irerror(in s)
Base Block class.
Definition: block.m:2
Analysis Session (AS) base class.
Definition: as.m:6
Log base class.
Definition: irlog.m:5
REpeated Train-Test - Block Cube.