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

Implements train/test data splitting: by means of k-fold cross-validation. More...

#include <data_splitter_cv.hpp>

Inheritance diagram for FST::Data_Splitter_CV< INTERVALCONTAINER, IDXTYPE >:
FST::Clonable_Impl< Data_Splitter_CV< INTERVALCONTAINER, IDXTYPE >, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP > FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE > FST::Clonable

Public Types

typedef Clonable_Impl< Data_Splitter_CV, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, 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< 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_CV (const IDXTYPE _kfold)
 _kfold-fold cross-validation (_kfold must be > 1)
 Data_Splitter_CV (const Data_Splitter_CV &dsp)
 copies configuration only; a split sequence in progress is not reproduced (prepareFirstSplit() sets the fold state up afresh), consistent with the other splitters
virtual IDXTYPE getNoOfSplits () const override
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_CV< INTERVALCONTAINER, IDXTYPE >, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP >
Data_Splitter< INTERVALCONTAINER, IDXTYPE > * clone () const override
 dispatches to the DEEP_KIND mechanism (default CLONE_DEEP: Derived's copy-constructor)
Data_Splitter< INTERVALCONTAINER, IDXTYPE > * sharing_clone () const override
 dispatches to the SHARING_KIND mechanism (default CLONE_INHERIT: defers to Base, which throws by family convention)
Data_Splitter< INTERVALCONTAINER, IDXTYPE > * 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< 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
 alias for the Data_Splitter base, used by the per-class hooks
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 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 cidx) 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 cidx) override
 write next-split train/test intervals of class cidx (a single-split splitter never gets here, since its prepareNextSplit() returns false)
virtual void finishSplit () override
 post-loop state update shared by first/next split
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.
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)

Private Attributes

const IDXTYPE kfold
 number of folds (splits)
IDXTYPE tmpod
 remaining folds still to be produced in the current split sequence (counts down from kfold, decremented by finishSplit())
std::vector< IDXTYPE > tmpn
 per-class remaining sample count not yet used as a test fold
std::vector< IDXTYPE > tmpstartidx
 per-class offset where the next test fold begins

Additional Inherited Members

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>
class FST::Data_Splitter_CV< INTERVALCONTAINER, IDXTYPE >

Implements train/test data splitting: by means of k-fold cross-validation.

Yields k splits. In each, one fold of every class is the test part and the remaining folds are the train part; the folds are contiguous blocks of each class, taken in file order.

Fold sizes are NOT exactly equal when the class size is not a multiple of k. Each fold takes (samples not yet used as a test fold)/(folds still to come), rounded down, so the earlier folds are the smaller ones and the last fold absorbs the remainder – with 10 samples and k=3 the folds are 3, 3 and 4. The per-class test parts therefore differ slightly in size between splits.

Warning
A class with fewer samples than k produces empty test folds, silently: the fold size rounds down to 0 for as long as the remaining count is below the remaining fold count. Choose k no larger than the smallest class size.
The folds are taken by position, not at random. On data sorted by anything that correlates with a feature, the folds are systematically different from one another.
Examples
demo52t.cpp, and demo55.cpp.

Member Function Documentation

◆ finishSplit()

template<class INTERVALCONTAINER, typename IDXTYPE>
virtual void FST::Data_Splitter_CV< INTERVALCONTAINER, IDXTYPE >::finishSplit ( )
inlineoverrideprotectedvirtual

post-loop state update shared by first/next split

Reimplemented from FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >.

◆ getNoOfSplits()

template<class INTERVALCONTAINER, typename IDXTYPE>
virtual IDXTYPE FST::Data_Splitter_CV< INTERVALCONTAINER, IDXTYPE >::getNoOfSplits ( ) const
inlineoverridevirtual

number of splits this splitter yields (requires class sizes to have been set via set_n())

Implements FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >.

◆ prepareFirstSplit()

template<class INTERVALCONTAINER, typename IDXTYPE>
virtual bool FST::Data_Splitter_CV< INTERVALCONTAINER, IDXTYPE >::prepareFirstSplit ( )
inlineoverrideprotectedvirtual

set up split-sequence state; false = no split can be made

Reimplemented from FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >.

◆ prepareNextSplit()

template<class INTERVALCONTAINER, typename IDXTYPE>
virtual bool FST::Data_Splitter_CV< INTERVALCONTAINER, IDXTYPE >::prepareNextSplit ( )
inlineoverrideprotectedvirtual

advance split-sequence state; false = no more splits

Implements FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >.

◆ print()

template<class INTERVALCONTAINER, typename IDXTYPE>
virtual std::ostream & FST::Data_Splitter_CV< INTERVALCONTAINER, IDXTYPE >::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< INTERVALCONTAINER, IDXTYPE >.

◆ splitClassFirst()

template<class INTERVALCONTAINER, typename IDXTYPE>
virtual void FST::Data_Splitter_CV< INTERVALCONTAINER, IDXTYPE >::splitClassFirst ( typename TCC::ClassIterator c,
const unsigned int cidx )
inlineoverrideprotectedvirtual

write first-split train/test intervals of class cidx (c is that class's entry in csplit)

Implements FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >.

◆ splitClassNext()

template<class INTERVALCONTAINER, typename IDXTYPE>
virtual void FST::Data_Splitter_CV< INTERVALCONTAINER, IDXTYPE >::splitClassNext ( typename TCC::ClassIterator c,
const unsigned int cidx )
inlineoverrideprotectedvirtual

write next-split train/test intervals of class cidx (a single-split splitter never gets here, since its prepareNextSplit() returns false)

Reimplemented from FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >.

◆ splitter_name()

template<class INTERVALCONTAINER, typename IDXTYPE>
virtual const char * FST::Data_Splitter_CV< INTERVALCONTAINER, IDXTYPE >::splitter_name ( ) const
inlineoverrideprotectedvirtual

class name, used in error messages

Implements FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >.


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.