1 %> @brief Random Sub-sampling base
class
5 %> @sa uip_sgs_randsub_base.m
7 properties(Access=
protected)
8 pvt_flag_fixed; %> when flag_balanced is true, will be true and pvt_bitess_fixed will be calculated
9 pvt_no_units_sel; %> matrix: one row per piece, one column per bite
13 %> =[.9, .1]: vectors of percentages.
15 %> ='simple'. String containing one of the following possibilities:
16 %> @arg @c 'simple' uses percentages in bites
17 %> @arg @c 'balanced' same number of units are picked within each class. Needs flag_perclass to be TRUE, otherwise will give error. The "bites" property will be used to calculate fixed number of units
18 %> @arg @c 'fixed' fixed number of units are picked. Uses bites_fixed
20 %> Used only if @c type is @c 'fixed', otherwise bites will be used.
22 %> =10. The number of repetitions.
26 methods(Access=protected)
27 %> Returns a 2D cell: rows are pieces, columns are bites, elements are indexes
28 function idxs = get_idxs_new(o)
30 idxs = cell(o.no_pieces, size(o.pvt_no_units_sel, 2));
31 for i = 1:o.no_pieces;
32 no_units_sel = o.pvt_no_units_sel(i, :); %> row vector containing number of units for each bite of the piece
33 p = randperm(o.no_unitss(i));
35 for j = 1:length(no_units_sel)
36 idxs{i, j} = p(ptr:ptr+no_units_sel(j)-1);
37 ptr = ptr+no_units_sel(j);
43 function idxs = get_repidxs(o)
44 idxs = cell(1, o.no_reps);
46 idxs{i} = o.get_idxs_new();
50 %> Parameter validation
51 function o = do_assert(o)
52 if strcmp(o.type, 'balanced') && ~o.flag_perclass
53 irerror('For balanced Random Subsampler, flag_perclass must be TRUE!')
56 if (strcmp(o.type, 'simple') || strcmp(o.type, 'balanced')) && sum(o.bites) > 1
57 irerror('Sum of all elements in the "bites" vector needs be <= 1!');
61 function o = do_setup(o)
62 o.pvt_flag_fixed = strcmp(o.type, 'fixed') || strcmp(o.type, 'balanced');
63 if strcmp(o.type, 'balanced')
64 minunits = min(o.no_unitss);
65 o.pvt_no_units_sel = repmat(
percs2no_unitss(o.bites, minunits), o.no_pieces, 1);
66 elseif strcmp(o.type, 'fixed')
67 minunits = min(o.no_unitss);
68 if sum(o.bites_fixed) > minunits
69 irerror(sprintf('Sum of number of fixed units is too big for dataset (should be <= %d)!', minunits));
71 o.pvt_no_units_sel = repmat(o.bites_fixed, o.no_pieces, 1);
73 o.pvt_no_units_sel = zeros(o.no_pieces, length(o.bites));
83 o.classtitle = 'Random Sub-sampling base class';
86 function idxs = get_obsidxs_new(o)
88 irerror('Must call setup() first!');
93 idxs = o.get_obsidxs();
Base Sub-dataset Generation Specification (SGS) class.
Random Sub-sampling base class.
function percs2no_unitss(in percs, in total)