1#ifndef FSTDATAACCESSORSPLITTING_H
2#define FSTDATAACCESSORSPLITTING_H
143template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
153 typedef std::shared_ptr<Data_Splitter<INTERVALCONTAINER,IDXTYPE> >
PSplitter;
163 virtual IDXTYPE
getClassSize(
const unsigned int c)
const override;
189 virtual IDXTYPE
getBlockIndex(
const unsigned int loopdepth=0)
const override;
197 virtual std::ostream&
print(std::ostream& os)
const override;
240 std::vector<std::vector<DataSplit> >
splits;
261template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
265 notify(
"Data_Accessor_Splitting constructor.");
268 assert(_dsp->size()>0);
272 splits.assign(_dsp->size(),std::vector<DataSplit>());
274 enum_block.assign(_dsp->size(),std::vector<IDXTYPE>());
275 tt_phase.assign(_dsp->size(),std::vector<DataPart>());
278template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
284template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
290template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
297template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
305template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
309 assert(depth<dsp->size());
311 for(
unsigned int n=0;n<depth;n++) assert(
enum_split[n]>0);
320template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
329template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
341 for(
unsigned int c=0; c<
classes.size(); c++)
344 for(
unsigned int c=0; c<
classes.size(); c++)
363template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
386template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
393template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
406 case NONE: {
return 0;}
411template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
420template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
433 case NONE: {
return 0;}
438template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
452template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
465template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
481 notify(
"Data_Accessor_Splitting() copy constructor.");
482 notify(
"DAS::copy-constructor, before da.assert_splits()");
484 notify(
"DAS::copy-constructor, after da.assert_splits()");
486 assert(da.
dsp->size()>0);
487 dsp.reset(
new std::vector<PSplitter>);
488 for(
unsigned int n=0; n<da.
dsp->size();n++)
492 for(
unsigned int c=0; c<
classes.size(); c++)
496 notify(
"DAS::copy-constructor, before assert_splits()");
498 notify(
"DAS::copy-constructor, after assert_splits()");
502template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
505 notify(
"Data_Accessor_Splitting()::initialize.");
507 classes.resize( _classes.size() );
508 copy(_classes.begin(), _classes.end(),
classes.begin() );
511 for(
unsigned int n=0;n<
dsp->size();n++)
514 notify(
"Data_Accessor_Splitting()::initialize to resize splits.");
516 notify(
"Data_Accessor_Splitting()::initialize splits resized.");
517 for(
unsigned int c=0;c<
classes.size();c++)
520 cs.
_train.reset(
new INTERVALCONTAINER());
521 cs.
_test.reset(
new INTERVALCONTAINER());
524 (*dsp)[0]->set_n(c,
classes[c]);
538 notify(
"Data_Accessor_Splitting()::initialize finished.");
541template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
554template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
583 case NONE: {tmp=
nullptr;}
589template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
620 case NONE: {tmp=
nullptr;}
628template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
631 notify(
"DataSplit strong copy constructor.");
636 notify(
"DataSplit _reduced_* to be linked");
640 notify(
"DataSplit _reduced_* to be re-allocated");
649template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
652 notify(
"DataSplit weak copy constructor.");
660template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
665 os <<
"Data_Accessor_Splitting() splitters: ";
666 typename std::vector<PSplitter>::const_iterator iter;
667 for(iter=
dsp->begin();iter!=
dsp->end();iter++) {
668 if(*iter) os << **iter <<
" ";
else os <<
"nullptr ";
670 }
else os <<
"Data_Accessor_Splitting()";
675template<
typename DATATYPE,
typename IDXTYPE,
class INTERVALCONTAINER>
683 assert(
dsp->size()>0);
686 assert(splitting_check<(
const int)
dsp->size());
695 for(
unsigned int n=0;n<
dsp->size();n++) assert(
splits[n].size()==
classes.size());
697 for(
unsigned int n=0;n<
dsp->size();n++)
699 for(
unsigned int c=0;c<
classes.size();c++)
701 if((
int)n<=splitting_check) assert((*
dsp)[n]->get_n(c)>0);
702 assert(
splits[n][c]._train);
703 assert(
splits[n][c]._test);
704 assert(
splits[n][c]._reduced_train);
705 assert(
splits[n][c]._reduced_test);
707 assert(
splits[n][c]._reduced_train==
splits[n][c]._train);
710 assert(
splits[n][c]._reduced_train!=
splits[n][c]._train);
Data splitting support structure; holds one set of intervals (train, test) per each splitting depth a...
Definition data_accessor_splitting.hpp:228
PIntervaller _test
this depth/class's base (splitter-produced) test intervals
Definition data_accessor_splitting.hpp:235
DataSplit()
all interval lists start unset
Definition data_accessor_splitting.hpp:230
PIntervaller _reduced_train
depth 0: same list as _train; deeper: _train's indexes reduced (translated) into the enclosing depth'...
Definition data_accessor_splitting.hpp:236
PIntervaller _train
this depth/class's base (splitter-produced) train intervals
Definition data_accessor_splitting.hpp:234
PIntervaller _reduced_test
depth 0: same list as _test; deeper: _test's indexes reduced (translated) into the enclosing depth's ...
Definition data_accessor_splitting.hpp:237
Data_Interval< IDXTYPE > _all
to enable passing of block reference when DataPart ofwhat==ALL
Definition data_accessor_splitting.hpp:238
DataPart mappedALL
current remapping target of ALL (see substitute()/resubstitute()); defaults to ALL
Definition data_accessor_splitting.hpp:215
PSplitters dsp
the splitter stack this accessor was constructed with, one Data_Splitter per nested splitting depth
Definition data_accessor_splitting.hpp:219
std::shared_ptr< std::vector< PSplitter > > PSplitters
shared pointer to the ordered list of splitters, one per nested splitting depth (depth 0 = outermost)
Definition data_accessor_splitting.hpp:154
DataPart mappedTRAINTEST
current remapping target of TRAINTEST (see substitute()/resubstitute()); defaults to TRAINTEST
Definition data_accessor_splitting.hpp:214
std::vector< std::vector< DataSplit > > splits
one set of splitters per each splitting depth and class
Definition data_accessor_splitting.hpp:240
virtual unsigned int getSplitIndex() const override
data access iteration (to support, e.g., loops in cross-validation)
Definition data_accessor_splitting.hpp:387
virtual int getClass() const override
returns active class
Definition data_accessor_splitting.hpp:167
virtual IDXTYPE getClassSize(const unsigned int c) const override
returns size (number of samples in) of class c
Definition data_accessor_splitting.hpp:291
std::vector< unsigned int > CLASSSIZES
per-class pattern counts, indexed by class index; the format initialize() takes
Definition data_accessor_splitting.hpp:203
virtual unsigned int getNoOfClasses() const override
returns number of classes
Definition data_accessor_splitting.hpp:279
virtual bool getNextSplit() override
data access iteration (to support, e.g., loops in cross-validation)
Definition data_accessor_splitting.hpp:364
virtual std::ostream & print(std::ostream &os) const override
writes the splitter stack's print() output (or "Data_Accessor_Splitting()" if the stack is empty) to ...
Definition data_accessor_splitting.hpp:661
virtual bool getFirstSplit() override
data access iteration (to support, e.g., loops in cross-validation)
Definition data_accessor_splitting.hpp:330
virtual void resubstitute() override
resets standard DataPart types' meaning
Definition data_accessor_splitting.hpp:453
DataPart mappedTRAIN
current remapping target of TRAIN (see substitute()/resubstitute()); defaults to TRAIN
Definition data_accessor_splitting.hpp:212
void setSplittingDepth(const unsigned int depth)
Selects the nested splitting level (0 = outermost/depth-0 splitter, 1 = the next-nested level,...
Definition data_accessor_splitting.hpp:306
const Data_Interval< IDXTYPE > * DATAINTERVAL
Definition data_accessor_splitting.hpp:220
virtual void setClass(const int c) override
sets active class -> from now on only data from class c will be considered
Definition data_accessor_splitting.hpp:166
virtual bool getFirstBlock(const DataPart ofwhat, PPattern &firstpattern, IDXTYPE &patterns, const unsigned int loopdepth=0) override=0
returns pointer to first consecutive block of data of requested DataPart type in the current split (a...
bool is_initialized() const
Definition data_accessor_splitting.hpp:252
std::vector< std::vector< DataPart > > tt_phase
in current block loop.. for DataPart==TRAINTEST indicates which half is being delivered: TRAIN,...
Definition data_accessor_splitting.hpp:244
std::shared_ptr< INTERVALCONTAINER > PIntervaller
Definition data_accessor_splitting.hpp:226
DataPart mappedDataPart(const DataPart ofwhat) const
looks up ofwhat's current remapping target (mappedTRAIN/mappedTEST/mappedTRAINTEST/mappedALL); NONE m...
Definition data_accessor_splitting.hpp:542
virtual IDXTYPE getNoOfPatterns(const DataPart ofwhat) const override
returns number of patterns in all consecutive blocks of data of requested DataPart type in the curren...
Definition data_accessor_splitting.hpp:421
const DATATYPE * PPattern
Definition data_accessor_splitting.hpp:155
virtual unsigned int getNoOfFeatures() const override
returns data dimensionality
Definition data_accessor_splitting.hpp:285
int active_class
denotes from which class the get*Train* get*Validate* get*Test* methods return patterns,...
Definition data_accessor_splitting.hpp:248
void assert_splits(const int splitting_check=-1) const
DEBUG-only: asserts the internal structures (dsp, splits, enum_split, enum_block, tt_phase,...
Definition data_accessor_splitting.hpp:676
virtual IDXTYPE getClassSizeSum() const override
returns summed size (number of samples in) of all classes, i.e., no. of all patterns in data
Definition data_accessor_splitting.hpp:298
Data_Accessor_Splitting(const PSplitters _dsp)
Constructs an (uninitialized) accessor bound to the splitter stack _dsp; concrete subclasses must sti...
Definition data_accessor_splitting.hpp:262
virtual IDXTYPE getBlockIndex(const unsigned int loopdepth=0) const override
returns index of the current consecutive block of data of requested DataPart type in the current spli...
Definition data_accessor_splitting.hpp:412
virtual bool getNextBlock(const DataPart ofwhat, PPattern &firstpattern, IDXTYPE &patterns, const unsigned int loopdepth=0) override=0
returns pointer to next consecutive block of data of requested DataPart type in the current split (ac...
std::vector< std::vector< IDXTYPE > > enum_block
current block loop.. 0~none
Definition data_accessor_splitting.hpp:243
virtual IDXTYPE getNoOfBlocks(const DataPart ofwhat) const override
Definition data_accessor_splitting.hpp:394
unsigned int features
data dimensionality, as passed to initialize()
Definition data_accessor_splitting.hpp:209
unsigned int getSplittingDepth() const
the nested splitting level last set via setSplittingDepth()
Definition data_accessor_splitting.hpp:172
virtual unsigned int getNoOfSplits() const override
data access iteration (to support, e.g., loops in cross-validation)
Definition data_accessor_splitting.hpp:321
unsigned int splitting_depth
the nested splitting level the get*Split()/get*Block() calls currently refer to; set via setSplitting...
Definition data_accessor_splitting.hpp:246
virtual void substitute(const DataPart source, const DataPart target) override
enables change of meaning of DataPart types, for use in specialized data access scenarios like in bia...
Definition data_accessor_splitting.hpp:439
DataPart mappedTEST
current remapping target of TEST (see substitute()/resubstitute()); defaults to TEST
Definition data_accessor_splitting.hpp:213
bool _initialize_called
set true by initialize(); read by is_initialized()
Definition data_accessor_splitting.hpp:251
CLASSSIZES classes
pattern count per class, as passed to initialize()
Definition data_accessor_splitting.hpp:208
std::vector< IDXTYPE > enum_split
current split.. 0~none
Definition data_accessor_splitting.hpp:242
std::shared_ptr< Data_Splitter< INTERVALCONTAINER, IDXTYPE > > PSplitter
shared pointer to one Data_Splitter (one nested splitting level)
Definition data_accessor_splitting.hpp:153
void initialize(const unsigned int _features, const CLASSSIZES &_classes)
Definition data_accessor_splitting.hpp:503
Abstract class, defines interface for data splitting implementations (for use in data accessors).
Definition data_splitter.hpp:124
Defines interface for data access implementations.
Defines interface for data splitting implementations (for use in data accessors).
FST4 specific error passing class.
The Feature Selection Toolbox 4 library: every library component – data access, criteria and classifi...
Definition data_accessor.hpp:80
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
DataPart
Selects which part of a split's data a block-access call reads.
Definition data_accessor.hpp:83
@ TRAINTEST
both parts concatenated (train followed by test)
Definition data_accessor.hpp:87
@ ALL
every pattern regardless of split (the whole class)
Definition data_accessor.hpp:88
@ NONE
no part (used internally, e.g. for traintestphase state before a phase is chosen)
Definition data_accessor.hpp:84
@ TEST
the split's test part
Definition data_accessor.hpp:86
@ TRAIN
the split's training part
Definition data_accessor.hpp:85
Support structure to hold data interval (referring into data held by data accessor).
Definition data_intervaller.hpp:88