Feature Selection Toolbox FST4
UTIA · Czech Academy of Sciences
Loading...
Searching...
No Matches
FST::Data_Splitter_TrainRandom_TestFixed< INTERVALCONTAINER, IDXTYPE, BINTYPE > Class Template Reference

Implements train/test data splitting: equal to Data_Splitter_RandomRandom except that the same test data is returned in each loop. More...

#include <data_splitter_randfix.hpp>

Inheritance diagram for FST::Data_Splitter_TrainRandom_TestFixed< INTERVALCONTAINER, IDXTYPE, BINTYPE >:
FST::Clonable_Impl< Data_Splitter_TrainRandom_TestFixed< INTERVALCONTAINER, IDXTYPE, BINTYPE >, Data_Splitter_RandomRandom< INTERVALCONTAINER, IDXTYPE, BINTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP > FST::Data_Splitter_RandomRandom< INTERVALCONTAINER, IDXTYPE, BINTYPE > FST::Clonable_Impl< Data_Splitter_RandomRandom< INTERVALCONTAINER, IDXTYPE, BINTYPE >, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP > FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE > FST::Clonable

Public Types

typedef Data_Splitter_RandomRandom< INTERVALCONTAINER, IDXTYPE, BINTYPE > parent
 the base class this splitter reuses fill_randomly()/fill()/translate() and _data/_n_max from
typedef Clonable_Impl< Data_Splitter_TrainRandom_TestFixed, parent, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP > parent_impl
 implements stateless_clone(); clone/sharing_clone throw in Data_Splitter
Public Types inherited from FST::Data_Splitter_RandomRandom< INTERVALCONTAINER, IDXTYPE, BINTYPE >
typedef Clonable_Impl< Data_Splitter_RandomRandom, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP > parent_impl
Public Types inherited from FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >
typedef std::shared_ptr< INTERVALCONTAINER > PIntervaller
 shared pointer to one class's list of train/test data intervals

Public Member Functions

 Data_Splitter_TrainRandom_TestFixed (const IDXTYPE _splits, const IDXTYPE _perctrain, const IDXTYPE _perctest, const bool randomize=false)
 same parameters as Data_Splitter_RandomRandom; the test part is always the fixed trailing _perctest % interval of each class
 Data_Splitter_TrainRandom_TestFixed (const Data_Splitter_TrainRandom_TestFixed &dsp)
 copies configuration
virtual std::ostream & print (std::ostream &os) const override
 writes a human-readable identification of the splitter and its configuration; base default writes nothing
Public Member Functions inherited from FST::Clonable_Impl< Data_Splitter_TrainRandom_TestFixed< INTERVALCONTAINER, IDXTYPE, BINTYPE >, Data_Splitter_RandomRandom< INTERVALCONTAINER, IDXTYPE, BINTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP >
Data_Splitter_RandomRandom< INTERVALCONTAINER, IDXTYPE, BINTYPE > * clone () const override
 dispatches to the DEEP_KIND mechanism (default CLONE_DEEP: Derived's copy-constructor)
Data_Splitter_RandomRandom< INTERVALCONTAINER, IDXTYPE, BINTYPE > * sharing_clone () const override
 dispatches to the SHARING_KIND mechanism (default CLONE_INHERIT: defers to Base, which throws by family convention)
Data_Splitter_RandomRandom< INTERVALCONTAINER, IDXTYPE, BINTYPE > * stateless_clone () const override
 dispatches to the STATELESS_KIND mechanism (default CLONE_INHERIT: defers to Base, which throws by family convention)
Public Member Functions inherited from FST::Data_Splitter_RandomRandom< INTERVALCONTAINER, IDXTYPE, BINTYPE >
 Data_Splitter_RandomRandom (const IDXTYPE _splits, const IDXTYPE _perctrain, const IDXTYPE _perctest, const bool randomize=false)
 _splits splits, each drawing _perctrain % of each class for training and _perctest % for testing (non-overlapping); randomize selects a per-instance engine seeded from std::random_device instead of the reproducible library PRNG (see the class warning).
 Data_Splitter_RandomRandom (const Data_Splitter_RandomRandom &dsp)
 Copy constructor. It deliberately does NOT inherit RNG state: in the randomize==true mode each copy seeds its own engine in prepareFirstSplit(), which is what keeps worker-thread clones from all drawing the same "random" splits. Configuration and the split counter transfer.
virtual IDXTYPE getNoOfSplits () const override
Public Member Functions inherited from FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >
 Data_Splitter (const Data_Splitter &dsp)
 Deep-copies every class's TClassSplitter (own train/test interval lists, not shared with dsp).
void assign (const unsigned int _clsidx, const PIntervaller _train, const PIntervaller _test)
 Registers class _clsidx's train/test interval lists (growing csplit as needed); the caller retains ownership via the shared pointers.
void set_n (const unsigned int _clsidx, const IDXTYPE _n)
 Sets class _clsidx's pattern count, which getNoOfSplits() and the concrete prepare*‍/splitClass* hooks size their splits against (growing csplit as needed).
IDXTYPE get_n (const unsigned int _clsidx) const
 the pattern count previously set for class _clsidx via set_n()
bool makeFirstSplit ()
 Produces the first split: prepareFirstSplit(), then splitClassFirst() per class, then finishSplit().
bool makeNextSplit ()
 Produces the next split: prepareNextSplit(), then splitClassNext() per class, then finishSplit().
Data_Splitter * clone () const override
Data_Splitter * sharing_clone () const override
Public Member Functions inherited from FST::Clonable
bool is_clone () const
bool is_sharing () const
 true if this instance is a sharing_clone() result (referencing, not owning, the source's structures)
bool is_sharing_clone () const
 true if this instance is BOTH a clone and sharing – i.e. specifically a sharing_clone() result, not a clone()/stateless_clone() one

Protected Types

typedef Data_Splitter< INTERVALCONTAINER, IDXTYPE > TCC
Protected Types inherited from FST::Data_Splitter_RandomRandom< INTERVALCONTAINER, IDXTYPE, BINTYPE >
typedef Data_Splitter< INTERVALCONTAINER, IDXTYPE > TCC
Protected Types inherited from FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >
typedef std::shared_ptr< TClassSplitter > PClassSplitter
 shared pointer to one class's TClassSplitter
typedef std::vector< PClassSplitter >::const_iterator ClassIterator
 iterator over csplit, as passed to the per-class splitClassFirst()/splitClassNext() hooks

Protected Member Functions

virtual void makeRandomSplit (const IDXTYPE n, const std::shared_ptr< INTERVALCONTAINER > list_train, const std::shared_ptr< INTERVALCONTAINER > list_test) override
Protected Member Functions inherited from FST::Data_Splitter_RandomRandom< INTERVALCONTAINER, IDXTYPE, BINTYPE >
virtual const char * splitter_name () const override
 class name, used in error messages
virtual bool prepareFirstSplit () override
 set up split-sequence state; false = no split can be made
virtual bool prepareNextSplit () override
 advance split-sequence state; false = no more splits
virtual void splitClassFirst (typename TCC::ClassIterator c, const unsigned int) override
 write first-split train/test intervals of class cidx (c is that class's entry in csplit)
virtual void splitClassNext (typename TCC::ClassIterator c, const unsigned int) override
 write next-split train/test intervals of class cidx (a single-split splitter never gets here, since its prepareNextSplit() returns false)
void fill_randomly (const IDXTYPE n, const BINTYPE id_empty, const BINTYPE id_fill, const IDXTYPE count, const IDXTYPE minidx, const IDXTYPE maxidx)
 Randomly relabels count of the still-id_empty slots of _data (within [minidx,maxidx]) to id_fill; draws from the per-instance engine when _randomize, else from the reproducible FST::fst_rand() stream.
void fill (const IDXTYPE n, const BINTYPE id_empty, const BINTYPE id_fill, const IDXTYPE minidx, const IDXTYPE maxidx)
 Relabels every still-id_empty slot of _data (within [minidx,maxidx]) to id_fill, unconditionally (no randomness).
void translate (const IDXTYPE n, const BINTYPE id_fill, const std::shared_ptr< INTERVALCONTAINER > lst)
 Converts the binary _data labeling (id_fill vs. everything else) over indices [0,n) into lst's list of consecutive Data_Interval runs.
Protected Member Functions inherited from FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >
void assert_csplit () const
 DEBUG-only: asserts csplit is non-empty and every class has n>0 and non-null train/test lists.
virtual void finishSplit ()
 post-loop state update shared by first/next split
Protected Member Functions inherited from FST::Clonable
void set_cloned (const bool cloned=true)
 marks/unmarks this instance as a clone; call from clone()/stateless_clone() overrides (Clonable_Impl does this automatically)
void set_sharing (const bool sharing=true)
 marks/unmarks this instance as sharing (see is_sharing())
void set_sharing_cloned (const bool cloned=true, const bool sharing=true)
 sets both flags at once; call from sharing_clone() overrides (Clonable_Impl does this automatically)

Additional Inherited Members

Protected Attributes inherited from FST::Data_Splitter_RandomRandom< INTERVALCONTAINER, IDXTYPE, BINTYPE >
IDXTYPE _n_max
 actual _data size (capacity; may exceed the current class size n)
std::unique_ptr< BINTYPE[]> _data
 pattern selection array: one BINTYPE label (id_empty/id_train/id_test) per sample index, reused/reallocated per class in makeRandomSplit()
const IDXTYPE perctrain
 percentage of each class's samples drawn for training
const IDXTYPE perctest
 percentage of each class's samples drawn for testing
const IDXTYPE splits
 number of splits this splitter yields (getNoOfSplits())
const bool _randomize
 true = seed a per-instance std::mt19937 engine (different splits every run); false = draw from the FST::fst_rand() stream, which makes the splits reproducible at a fixed seed
std::mt19937 _rng
 per-instance RNG engine; used only when _randomize==true (see prepareFirstSplit())
IDXTYPE current_split
 1-based index of the split currently being produced; 0 outside an active split sequence
Protected Attributes inherited from FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >
std::vector< PClassSplitter > csplit
 one TClassSplitter per data class, indexed by class index; grown on demand by assign()/set_n()

Detailed Description

template<class INTERVALCONTAINER, typename IDXTYPE, typename BINTYPE>
class FST::Data_Splitter_TrainRandom_TestFixed< INTERVALCONTAINER, IDXTYPE, BINTYPE >

Implements train/test data splitting: equal to Data_Splitter_RandomRandom except that the same test data is returned in each loop.

The train part is drawn at random from the leading part of each class, exactly as Data_Splitter_RandomRandom draws it, and varies from split to split. The test part is fixed: it is always the LAST perctest % of each class, in file order, and is therefore the same samples in every split. Use it when several splits should be compared against one common test set.

Warning
Because the test part is chosen by position rather than at random, it inherits whatever structure the sample order has: on data sorted by anything that correlates with a feature, the trailing samples are not a representative test set.

Member Typedef Documentation

◆ TCC

template<class INTERVALCONTAINER, typename IDXTYPE, typename BINTYPE>
typedef Data_Splitter<INTERVALCONTAINER,IDXTYPE> FST::Data_Splitter_TrainRandom_TestFixed< INTERVALCONTAINER, IDXTYPE, BINTYPE >::TCC
protected

alias for the Data_Splitter base

Member Function Documentation

◆ makeRandomSplit()

template<class INTERVALCONTAINER, typename IDXTYPE, typename BINTYPE>
void FST::Data_Splitter_TrainRandom_TestFixed< INTERVALCONTAINER, IDXTYPE, BINTYPE >::makeRandomSplit ( const IDXTYPE n,
const std::shared_ptr< INTERVALCONTAINER > list_train,
const std::shared_ptr< INTERVALCONTAINER > list_test )
overrideprotectedvirtual

Draws the same random perctrain % train subset as the base class, but always takes the fixed trailing perctest % interval of each class as test data (identical across splits).

Reimplemented from FST::Data_Splitter_RandomRandom< INTERVALCONTAINER, IDXTYPE, BINTYPE >.

◆ print()

template<class INTERVALCONTAINER, typename IDXTYPE, typename BINTYPE>
virtual std::ostream & FST::Data_Splitter_TrainRandom_TestFixed< INTERVALCONTAINER, IDXTYPE, BINTYPE >::print ( std::ostream & os) const
inlineoverridevirtual

writes a human-readable identification of the splitter and its configuration; base default writes nothing

Reimplemented from FST::Data_Splitter_RandomRandom< INTERVALCONTAINER, IDXTYPE, BINTYPE >.


The documentation for this class was generated from the following file:
Copyright © 2000–present ÚTIA, Institute of Information Theory and Automation of the Czech Academy of Sciences · Contacts · This site sets no cookies and uses no analytics.