1 %> @brief Base Sub-dataset Generation Specification (SGS) class
3 %> This class generates index maps to sub-datasets, formulating these maps according to various
4 %> criteria, including cross-validation, random sub-sampling, and weighted sub-sampling.
8 %> =0. Whether items from the same group (group) are to always remain together.
10 %> =0. Whether to perform on each class separately.
12 %> =0. Random seed. Only used if > 0.
13 %> if > 0, MATLAB's rand('twister', o.randseed) will be called before. This can be used to repeat sequences.
22 properties(Access=protected)
26 %> Number of "units" in dataset. This may be a single value containing
27 %> the number of observations or groups, depending on .flag_group, or
28 %> a vector containing that information for each class, if .flag_perclass is
33 %> Calculated upon setup, will be zero if flag_group but dataset has no groups
38 methods(Access=private)
39 %> Builds a 2D cell where rows are repetitions and columns are bites
40 %> repidxs is 1 1D cell of 2D cells. Within each 2D cells, rows are pieces and columns are bites, and elements
42 function obsidxs = convert_to_obs(o, repidxs)
43 no_reps = length(repidxs);
44 no_bites = size(repidxs{1}, 2);
45 obsidxs = cell(no_reps, no_bites);
46 flag_verbose = o.no_reps > 20;
52 flag_mergeobs = 0; %> Switch
for the second task inside the loop
56 %> In the grouped, per-
class case, converts to per-piece observation to later use the common
60 repidxs{i}{k, j} = o.pieces(k).get_obsidxs_from_groupidxs(repidxs{i}{k, j});
66 obsidxs{i, j} = o.data.get_obsidxs_from_groupidxs(repidxs{i}{1, j});
74 obsidxs(i, :) = repidxs{i}(1, :);
79 idxs_onerep = repidxs{i};
80 nos = arrayfun(@(a) length(a{1}), idxs_onerep);
81 no_perbite = sum(nos, 1);
84 obsidxs{i, j} = zeros(1, no_perbite(j));
89 obsidxs{i, j}(ptr:ptr+nos(k, j)-1) = o.maps{k}(idxs_onerep{k, j});
107 methods(Access=
protected)
108 %> Must be implemented at the descendants,
this is essentially what is different
for every different
sgs method
109 %> This
function is group-or-observation-unaware
110 %> Returns a 1D cell array or 2D cell arrays. Each element/2D cell array contains one row per piece and one
112 %> This
function does not know
if it is working with groups or observations
113 function idxs = get_repidxs(o)
116 %> Must be implemented at the descendants
117 function o = do_setup(o)
120 %> Data-independent validation
121 function o = do_assert(o)
127 o.classtitle = 'Sub-dataset Generation Specs';
128 o.color = [164, 100, 100]/255;
131 %> If hasn't been setup yet, will return a NaN
132 function z = get.no_pieces(o)
135 elseif isempty(o.pieces)
136 z = NaN; %
irerror('Did not have contact with dataset yet!');
138 z = length(o.pieces);
142 function o = setup(o, data)
147 o.pr_flag_group = o.flag_group && ~isempty(data.groupcodes) && data.no_groups < data.no;
148 if o.flag_group && isempty(data.groupcodes)
149 irverbose('INFO: will not group rows because data groupcodes is empty!');
151 if o.flag_group && data.no_groups == data.no
152 irverbose('INFO: will not group rows because number of groups equals number of spectra.');
155 %> Solves o.no_unitss
159 for i = 1:o.no_pieces
160 o.no_unitss(i) = o.pieces(i).no_groups;
161 if o.no_unitss(i) == 0;
irerror('Number of groups in dataset piece is zero!'); end;
164 for i = 1:o.no_pieces
165 o.no_unitss(i) = o.pieces(i).no;
166 if o.no_unitss(i) == 0;
irerror('Dataset piece has no rows!'); end;
171 o.no_unitss = o.data.no_groups;
172 if o.no_unitss == 0;
irerror('Number of groups in dataset is zero!'); end;
175 o.no_unitss = o.data.no;
176 if o.no_unitss == 0;
irerror('Dataset has no rows!'); end;
180 o = o.do_setup(); %> class-specific setup
187 function obsidxs = get_obsidxs(o, data)
190 s = RandStream.getDefaultStream; % Random stream used in random functions (default one).
192 % 20150414 -- Above has been renamed; preserving
193 % backwards compatibility
196 s = RandStream.getGlobalStream;
198 save_State = s.State; % Saves state to restore later.
199 reset(s, o.randomseed); % Resets state to one made from o.randomseed
203 % Of course I have to always call setup!
206 idxs = o.get_repidxs();
207 obsidxs = o.convert_to_obs(idxs);
210 set(s, 'State', save_State); % Restores default stream state so that random numbers can be generated
as if nothing really happened here.
214 %> Data-independent validation. Can be used at the GUI to check for parameter inconsistencies.
215 function o = assert(o)
function irverbose(in s, in level)
Base Sub-dataset Generation Specification (SGS) class.
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 progress2_close(in prgrss)
function data_split_classes(in data, in hierarchy)
Analysis Session (AS) base class.