IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
grag.m
Go to the documentation of this file.
1 %> @file
2 %> @ingroup groupgroup
3 
4 %> @brief Group Aggregator - combines data rows outputting one row per group
5 classdef grag < rowaggr
6  properties(Access=protected)
7  %> Temporary storage, released after @c use()' d
8  indata;
9  %> Temporary storage, released after @c use()' d
10  outdata;
11  %> Row pointer
12  no_out;
13  end;
14 
15  methods
16  function o = grag(o)
17  o.classtitle = 'Group aggregator';
18  o.flag_trainable = 0;
19  o.flag_params = 0;
20  end;
21  end;
22 
23  methods(Access=protected)
24  %> Abstract. Core. Task is to assign data properties of row @c no_out .
25  function o = process_group(o, idxs)
26  end;
27 
28  %> Needs to pre-allocate the relevant row fields of @c outdata .
29  function o = dim_outdata(o, ng)
30  end;
31 
32  function out = do_use(o, data)
33  if isempty(data.groupcodes)
34  irerror('Dataset groupcodes is empty!');
35  end;
36 
37  % Really didn't make much of a difference, actually it seems that comparing strings is even faster
38  if 1
39  o.indata = data;
40 
41  % Determines the groups
42  codes = unique(data.groupcodes);
43  ng = numel(codes);
44 
45  % Prepares output dataset
46  o.outdata = data.copy_emptyrows();
47  o.no_out = 0;
48  o.outdata.groupcodes = cell(ng, 1);
49  o = o.dim_outdata(ng);
50 
51 
52  for i = 1:ng
53  o.no_out = o.no_out+1;
54 
55  % Half the bottleneck is here
56  idxs = find(strcmp(codes{i}, data.groupcodes)); % observation indexes
57  o.outdata.groupcodes{o.no_out} = o.indata.groupcodes{idxs(1)};
58 
59  % The other half is here
60  o = o.process_group(idxs);
61  end;
62 
63  else
64  o.indata = data;
65 
66  % Determines the groups
67  numbers = unique(data.groupnumbers);
68  ng = numel(numbers);
69 
70  % Prepares output dataset
71  o.outdata = data.copy_emptyrows();
72  o.no_out = 0;
73  o.outdata.groupcodes = cell(ng, 1);
74  o = o.dim_outdata(ng);
75 
76 
77  for i = 1:ng
78  o.no_out = o.no_out+1;
79  idxs = find(numbers(i) == data.groupnumbers);
80  o.outdata.groupcodes{o.no_out} = o.indata.groupcodes{idxs(1)};
81  o.outdata.groupnumbers(o.no_out) = o.indata.groupnumbers(idxs(1));
82  o = o.process_group(idxs);
83  end;
84  end;
85 
86 
87  out = o.outdata;
88  o.indata = [];
89  o.outdata = [];
90  end;
91  end;
92 end
function irerror(in s)
Definition: rowaggr.m:6
Pre-processing block base class.
Definition: pre.m:2
Group Aggregator - combines data rows outputting one row per group.
Definition: grag.m:5