85template<
class BINTYPE,
typename DIMTYPE>
88template<
class BINTYPE,
typename DIMTYPE>
103template<
class BINTYPE,
typename DIMTYPE>
130 void select(
const DIMTYPE i);
131 void select(
const DIMTYPE _from,
const DIMTYPE _to) {assert(_to>_from); assert(_to<
get_n());
for(DIMTYPE i=_from;i<=_to;i++)
select(i);}
134 void deselect(
const DIMTYPE _from,
const DIMTYPE _to) {assert(_to>_from); assert(_to<
get_n());
for(DIMTYPE i=_from;i<=_to;i++)
deselect(i);}
147 DIMTYPE
get_d_raw()
const {DIMTYPE d=0;
for(DIMTYPE i=0;i<
_n;i++)
if(
_bin[i]>0) ++d;
return d;}
186 bool getFirstFeature(DIMTYPE &feat,
bool selected=
true,
const int looplevel=0);
248 const std::unique_ptr<BINTYPE[]>
_bin;
269template<
class BINTYPE,
typename DIMTYPE>
279 notify(
"Subset constructor.");
283template<
class BINTYPE,
typename DIMTYPE>
284Subset<BINTYPE,DIMTYPE>::~Subset()
286 notify(
"Subset destructor.");
290template<
class BINTYPE,
typename DIMTYPE>
294 for(DIMTYPE i=0;i<
_n;i++)
_bin[i]=sub.
_bin[i];
300 notify(
"Subset copy-constructor.");
304template<
class BINTYPE,
typename DIMTYPE>
320template<
class BINTYPE,
typename DIMTYPE>
327 while(eq && fidx<
_n)
if((
_bin[fidx]<=0 && sub.
_bin[fidx]>0)||(
_bin[fidx]>0 && sub.
_bin[fidx]<=0)) eq=
false;
else ++fidx;
331template<
class BINTYPE,
typename DIMTYPE>
347template<
class BINTYPE,
typename DIMTYPE>
362template<
class BINTYPE,
typename DIMTYPE>
374template<
class BINTYPE,
typename DIMTYPE>
386template<
class BINTYPE,
typename DIMTYPE>
390 assert(d>=1 && d<=
get_n());
402template<
class BINTYPE,
typename DIMTYPE>
405 assert(lo_d>=1 && lo_d<=
get_n());
406 assert(hi_d>=1 && hi_d<=
get_n());
409 d=lo_d+(DIMTYPE)
fst_rand_below((
unsigned long)(hi_d-lo_d+1)); assert(lo_d<=d && d<=hi_d);
413template<
class BINTYPE,
typename DIMTYPE>
417 assert(d_prob>0.0 && d_prob<=1.0);
427template<
class BINTYPE,
typename DIMTYPE>
443template<
class BINTYPE,
typename DIMTYPE>
459template<
class BINTYPE,
typename DIMTYPE>
475template<
class BINTYPE,
typename DIMTYPE>
488template<
class BINTYPE,
typename DIMTYPE>
492 assert(g>=1 && g<=
_n);
501template<
class BINTYPE,
typename DIMTYPE>
506 DIMTYPE beg, piv, pom;
542template<
class BINTYPE,
typename DIMTYPE>
548 assert(g>=1 && g<
_n);
550 DIMTYPE ecnt=0;
for(DIMTYPE i=0;i<
_n;i++)
if(
_bin[i]==id_empty) ++ecnt;
552 if(g==1)
return ecnt;
556template<
class BINTYPE,
typename DIMTYPE>
568template<
class BINTYPE,
typename DIMTYPE>
579template<
class BINTYPE,
typename DIMTYPE>
589template<
class BINTYPE,
typename DIMTYPE>
594 if(k==0 || n==k)
return 1;
596 const unsigned long long kk=((
unsigned long long)k<=(
unsigned long long)(n-k))?(
unsigned long long)k:(
unsigned long long)(n-k);
600 unsigned long long result=1, tempcheck;
601 for(
unsigned long long i=1;i<=kk;i++) {
602 const unsigned long long factor=(
unsigned long long)n-kk+i;
603 tempcheck=result*factor;
604 if(tempcheck/factor!=result)
throw FST::fst_error(
"Subset::get_combinations() numeric representation overflow.");
607 DIMTYPE dimresult=(DIMTYPE)result;
608 if((
unsigned long long)dimresult!=result)
throw FST::fst_error(
"Subset::get_combinations() numeric representation overflow.");
616template<
class BINTYPE,
typename DIMTYPE>
623 os <<
"Subset<n=" << tdb.
_n <<
", d=" << d_raw <<
">: ";
625 for(DIMTYPE i=0;i<tdb.
_n;i++) {os << (int)tdb.
_bin[i] <<
" ";}
628 if(d_raw==0) os <<
"empty";
629 else for(DIMTYPE i=0;i<tdb.
_n;i++) {
if(tdb.
_bin[i]>0) os << i <<
" ";}
Forward iterator over raw feature indices matching a Kind, skipping non-matching ones.
Definition subset.hpp:219
bool match() const
whether the current index matches this iterator's Kind
Definition subset.hpp:227
bool operator!=(const iterator &o) const
range-for only ever compares against end(); true until the index reaches end()'s
Definition subset.hpp:225
DIMTYPE _i
the current raw feature index
Definition subset.hpp:230
void advance()
skips forward from the current index to the next match (or to end())
Definition subset.hpp:228
const Subset * _s
the subset iterated
Definition subset.hpp:229
Kind _k
which Kind is matched
Definition subset.hpp:231
iterator(const Subset *s, const DIMTYPE i, const Kind k)
Positions at feature index i or the first matching feature at or after it (advance() skips non-matche...
Definition subset.hpp:222
DIMTYPE operator*() const
the current (raw) feature index
Definition subset.hpp:223
iterator & operator++()
advances to the next matching feature index
Definition subset.hpp:224
Read-only forward range over feature indices.
Definition subset.hpp:211
Kind _k
which kind of feature this range selects
Definition subset.hpp:239
iterator begin() const
an iterator positioned at the first matching feature, or already at end() if there are none
Definition subset.hpp:235
Kind
Which raw features a Feature_Range/iterator matches.
Definition subset.hpp:214
@ SELECTED
features with a positive raw marker (selected, frozen, or under traversal; matches get_d_raw(),...
Definition subset.hpp:215
@ TEMPORARY
features currently marked tmp_id_traverse by an in-progress getFirstCandidateSubset()/getNextCandidat...
Definition subset.hpp:216
const Subset * _s
the subset iterated
Definition subset.hpp:238
Feature_Range(const Subset *s, const Kind k)
Constructs a range over s's features of the given k (SELECTED or TEMPORARY).
Definition subset.hpp:234
iterator end() const
the sentinel end iterator
Definition subset.hpp:236
Stores the info on currently selected features, enables generating permutations, etc.
Definition subset.hpp:104
DIMTYPE _gen_features
the g-tuple size of the getFirstCandidateSubset() traversal in progress, or 0 if none
Definition subset.hpp:263
void select_all_raw()
mark all features (including frozen ones) as selected
Definition subset.hpp:142
bool getFirstTemporaryFeature(DIMTYPE &feat)
Definition subset.hpp:557
BINTYPE id_traverse
the marker value for a feature in the g-tuple currently being traversed by getFirstCandidateSubset()/...
Definition subset.hpp:252
void deselect_all()
mark all (non-frozen) features as deselected
Definition subset.hpp:135
bool getFirstFeature(DIMTYPE &feat, bool selected=true, const int looplevel=0)
Definition subset.hpp:460
DIMTYPE get_n() const
the number of features select()/deselect() address: get_n_raw() minus currently frozen features
Definition subset.hpp:136
void select_all()
mark all (non-frozen) features as selected
Definition subset.hpp:132
BINTYPE tmp_id_sel
id_sel/id_desel/id_traverse as resolved for the CURRENT getFirstCandidateSubset() call's reverse dire...
Definition subset.hpp:254
DIMTYPE getNoOfTemporaryFeatures()
the number of features currently marked tmp_id_traverse (the g-tuple size of the CandidateSubset trav...
Definition subset.hpp:580
void set_frozen_mode(const bool freeze=false)
Freezes (or unfreezes) the currently selected features, excluding them from further select()/deselect...
Definition subset.hpp:444
void set_forward_mode(const bool forward=true)
Flips the sign convention of id_sel/id_desel/id_traverse/id_frozen (forward: selected>0; backward: se...
Definition subset.hpp:428
const DIMTYPE _n
max. No. of features (full set size)
Definition subset.hpp:247
bool getFirstCandidateSubset(const DIMTYPE g, bool reverse=false)
begins traversal of all g-tuples of currently DESELECTED features (candidates to ADD) if reverse is f...
Definition subset.hpp:489
bool get_forward_mode() const
true if in forward mode (the constructor default); see set_forward_mode()
Definition subset.hpp:169
DIMTYPE get_d_raw() const
number of features whose raw marker is positive: selected/traversed/frozen in forward mode,...
Definition subset.hpp:147
DIMTYPE _enum_temporary
cursor state for the deprecated getFirstTemporaryFeature()/getNextTemporaryFeature() pair
Definition subset.hpp:264
DIMTYPE get_combinations(const DIMTYPE n, const DIMTYPE k)
Number of size-k combinations of n features (n choose k); throws if the result overflows DIMTYPE (or ...
Definition subset.hpp:590
bool _frozen_mode
set by set_frozen_mode(); read by get_frozen_mode()
Definition subset.hpp:261
void select(const DIMTYPE i)
mark i-th feature as selected
Definition subset.hpp:332
BINTYPE id_frozen
the marker value for a frozen feature (see set_frozen_mode())
Definition subset.hpp:253
bool getNextTemporaryFeature(DIMTYPE &feat)
Definition subset.hpp:569
Feature_Range temporary_features() const
reentrant range over temporary features in the current CandidateSubset (as with getFirstTemporaryFeat...
Definition subset.hpp:244
Subset(const DIMTYPE n)
Definition subset.hpp:270
void deselect(const DIMTYPE i)
mark i-th feature as deselected
Definition subset.hpp:348
bool equivalent(const Subset< BINTYPE, DIMTYPE > &sub)
tests whether sub represents the same subset (ignoring internal state)
Definition subset.hpp:321
BINTYPE id_desel
the marker value for a deselected feature; sign flips with set_forward_mode()
Definition subset.hpp:251
bool get_frozen_mode() const
true if currently frozen; see set_frozen_mode()
Definition subset.hpp:179
BINTYPE tmp_id_desel
see tmp_id_sel; local to get*CandidateSubset()
Definition subset.hpp:255
void deselect_raw(const DIMTYPE i)
mark i-th feature as deselected
Definition subset.hpp:143
DIMTYPE get_d() const
number of currently selected, non-frozen features (get_d_raw() minus frozen ones)
Definition subset.hpp:137
bool getNextFeature(DIMTYPE &feat)
Definition subset.hpp:476
DIMTYPE getNoOfCandidateSubsets(const DIMTYPE g, bool reverse=false)
Definition subset.hpp:543
BINTYPE tmp_id_traverse
Definition subset.hpp:256
void deselect_all_raw()
mark all features (including frozen ones) as deselected
Definition subset.hpp:145
void stateless_copy(Subset< BINTYPE, DIMTYPE > &sub)
Overwrites this subset's selection state from sub's currently selected features (via getFirstFeature(...
Definition subset.hpp:305
DIMTYPE _enum_selected
cursor state for the deprecated getFirstFeature()/getNextFeature() pair
Definition subset.hpp:266
BINTYPE id_sel
the marker value for a selected feature; sign flips with set_forward_mode()
Definition subset.hpp:250
const std::unique_ptr< BINTYPE[]> _bin
default format to store subset info
Definition subset.hpp:248
bool _forward_mode
set by set_forward_mode(); read by get_forward_mode()
Definition subset.hpp:260
void deselect(const DIMTYPE _from, const DIMTYPE _to)
mark features _from,..,_to as deselected
Definition subset.hpp:134
void select_raw(const DIMTYPE i)
mark i-th feature as selected
Definition subset.hpp:140
Feature_Range selected_features() const
reentrant range over all currently selected features (id_sel, id_frozen, id_traverse - as with getFir...
Definition subset.hpp:242
void select(const DIMTYPE _from, const DIMTYPE _to)
mark features _from,..,_to as selected
Definition subset.hpp:131
void make_random_subset(const DIMTYPE d)
Generate random subset of exactly d features. Draws from the library PRNG (FST::fst_rand(),...
Definition subset.hpp:387
bool selected_raw(const DIMTYPE i) const
true if raw feature index i is currently selected (or frozen); false (not an error) for an out-of-ran...
Definition subset.hpp:148
bool getNextCandidateSubset()
advances to the next g-tuple begun by getFirstCandidateSubset(); returns false once exhausted
Definition subset.hpp:502
DIMTYPE get_n_raw() const
the full allocation size (max_n passed to the constructor), regardless of frozen features
Definition subset.hpp:146
FST4 specific error passing class.
Definition error.hpp:61
FST4 specific error passing class.
FST4-owned pseudo-random number generator (UCRT-compatible LCG), replacing platform-specific std::ran...
The Feature Selection Toolbox 4 library: every library component – data access, criteria and classifi...
Definition data_accessor.hpp:80
int fst_rand()
Returns the next pseudo-random draw in 0..FST_RAND_MAX; use instead of std::rand().
Definition fst_rand.hpp:93
unsigned long fst_rand_below(const unsigned long n)
Returns a pseudo-random index in 0..n-1 (n >= 1); use instead of fst_rand()n.
Definition fst_rand.hpp:112
const int FST_RAND_MAX
Maximum value fst_rand() can return; use instead of the libc macro RAND_MAX.
Definition fst_rand.hpp:101
void notify(const std::string msg)
Prints msg followed by a newline via syncout::print(); a no-op unless the preprocessor macro DEBUG is...
Definition global.hpp:112
std::ostream & operator<<(std::ostream &os, const Data_Intervaller< CONTAINER, IDXTYPE > &ia)
Streams every contained interval as "si:<startidx>, c:<count>" lines to os.
Definition data_intervaller.hpp:152