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

Abstract class, defines interface for data splitting implementations (for use in data accessors). More...

#include <data_splitter.hpp>

Inheritance diagram for FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >:
FST::Clonable FST::Clonable_Impl< Data_Splitter_5050, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP > FST::Clonable_Impl< Data_Splitter_CV, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP > FST::Clonable_Impl< Data_Splitter_Holdout, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP > FST::Clonable_Impl< Data_Splitter_Leave1Out, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP > FST::Clonable_Impl< Data_Splitter_RandomRandom, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP > FST::Clonable_Impl< Data_Splitter_Resub, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP > FST::Clonable_Impl< Data_Splitter_5050< INTERVALCONTAINER, IDXTYPE >, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP > FST::Clonable_Impl< Data_Splitter_CV< INTERVALCONTAINER, IDXTYPE >, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP > FST::Clonable_Impl< Data_Splitter_Holdout< INTERVALCONTAINER, IDXTYPE >, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP > FST::Clonable_Impl< Data_Splitter_Leave1Out< INTERVALCONTAINER, IDXTYPE >, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP > FST::Clonable_Impl< Data_Splitter_RandomRandom< INTERVALCONTAINER, IDXTYPE, BINTYPE >, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP > FST::Clonable_Impl< Data_Splitter_Resub< INTERVALCONTAINER, IDXTYPE >, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP >

Classes

class  TClassSplitter
 Data splitting support structure; holds one set of intervals (train, test) per each (data)class. More...

Public Types

typedef std::shared_ptr< INTERVALCONTAINER > PIntervaller
 shared pointer to one class's list of train/test data intervals

Public Member Functions

 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()
virtual IDXTYPE getNoOfSplits () const =0
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
Data_Splitter * stateless_clone () const override=0
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
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 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

void assert_csplit () const
 DEBUG-only: asserts csplit is non-empty and every class has n>0 and non-null train/test lists.
virtual const char * splitter_name () const =0
 class name, used in error messages
virtual bool prepareFirstSplit ()
 set up split-sequence state; false = no split can be made
virtual bool prepareNextSplit ()=0
 advance split-sequence state; false = no more splits
virtual void splitClassFirst (ClassIterator c, const unsigned int cidx)=0
 write first-split train/test intervals of class cidx (c is that class's entry in csplit)
virtual void splitClassNext (ClassIterator c, const unsigned int cidx)
 write next-split train/test intervals of class cidx (a single-split splitter never gets here, since its prepareNextSplit() returns false)
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)

Protected Attributes

std::vector< PClassSplitter > csplit
 one TClassSplitter per data class, indexed by class index; grown on demand by assign()/set_n()

Friends

std::ostream & operator<< (std::ostream &os, const Data_Splitter< INTERVALCONTAINER, IDXTYPE > &ds)
 Streams a splitter's print() to os.

Detailed Description

template<class INTERVALCONTAINER, typename IDXTYPE>
class FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >

Abstract class, defines interface for data splitting implementations (for use in data accessors).

A splitter enumerates a sequence of train/test partitions. It does not touch data: it works purely with sample INDEXES, and writes each partition as two lists of index intervals, per class.

Driving a splitter. The owner first calls assign() and set_n() once per class, then iterates for(bool b=makeFirstSplit(); b; b=makeNextSplit()). Each successful call overwrites the train and test interval lists registered through assign(); the lists are only valid until the next call. getNoOfSplits() says how many iterations to expect and requires set_n() to have been called.

What an implementation must guarantee. Every split, for every class:

  • indexes are 0-based and LOCAL TO THE CLASS – index 0 is that class's first sample and the largest valid index is get_n(class)-1. A splitter never sees a global sample index;
  • the train and test lists must not overlap, neither with each other nor internally;
  • the intervals within each list must be sorted by ascending startidx. Nested splitting translates a deeper level's indexes through Data_Intervaller::reduce(), which walks both lists once in ascending order and silently produces wrong intervals for unsorted input;
  • an interval with count==0 should not be emitted; the consumers treat empty intervals as a degenerate case and skip them;
  • leaving the train part empty makes the split unusable for any criterion that trains on it. A splitter that can reach such a configuration should end the sequence instead.

Implementing one. The template methods makeFirstSplit()/makeNextSplit() own the shared scaffolding – the state assertions, the per-class loop and the error reporting – so a concrete splitter implements only the prepare*, splitClass* and finishSplit hooks, i.e. its actual splitting logic. The call order is: prepareFirstSplit(), then splitClassFirst() once per class in class order, then finishSplit(); and for every later split prepareNextSplit(), then splitClassNext() once per class in class order, then finishSplit(). A prepare hook returning false ends the sequence, and neither splitClass nor finishSplit is called after it.

Member Function Documentation

◆ clone()

template<class INTERVALCONTAINER, typename IDXTYPE>
Data_Splitter * FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >::clone ( ) const
inlineoverridevirtual

create 1:1 independent clone of the current object. The caller owns the returned object. Families that cannot support a given clone kind implement it to throw fst_error; Clonable_Impl's CLONE_INHERIT slot defers to such a body.

Implements FST::Clonable.

◆ finishSplit()

template<class INTERVALCONTAINER, typename IDXTYPE>
virtual void FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >::finishSplit ( )
inlineprotectedvirtual

post-loop state update shared by first/next split

Reimplemented in FST::Data_Splitter_CV< INTERVALCONTAINER, IDXTYPE >, and FST::Data_Splitter_Leave1Out< INTERVALCONTAINER, IDXTYPE >.

◆ getNoOfSplits()

template<class INTERVALCONTAINER, typename IDXTYPE>
virtual IDXTYPE FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >::getNoOfSplits ( ) const
pure virtual

◆ makeFirstSplit()

template<class INTERVALCONTAINER, typename IDXTYPE>
bool FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >::makeFirstSplit ( )

Produces the first split: prepareFirstSplit(), then splitClassFirst() per class, then finishSplit().

Returns
false if no split can be made at all; any exception a hook throws is rethrown as an fst_error naming the splitter and this method – the original exception's own message is not preserved.

◆ makeNextSplit()

template<class INTERVALCONTAINER, typename IDXTYPE>
bool FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >::makeNextSplit ( )

Produces the next split: prepareNextSplit(), then splitClassNext() per class, then finishSplit().

Returns
false once the split sequence is exhausted; exceptions are reported as in makeFirstSplit().

◆ prepareFirstSplit()

template<class INTERVALCONTAINER, typename IDXTYPE>
virtual bool FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >::prepareFirstSplit ( )
inlineprotectedvirtual

◆ prepareNextSplit()

◆ print()

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

◆ sharing_clone()

template<class INTERVALCONTAINER, typename IDXTYPE>
Data_Splitter * FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >::sharing_clone ( ) const
inlineoverridevirtual

create equivalent clone of the current object, permitting read-only access to structures in the source object (allows referencing instead of copying of large memory structures). may be faster and save space but requires more caution with respect to concurrency Use example: Data_Accessor memory data representation cloning

Implements FST::Clonable.

◆ splitClassFirst()

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

◆ splitClassNext()

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

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

Reimplemented in FST::Data_Splitter_CV< INTERVALCONTAINER, IDXTYPE >, FST::Data_Splitter_Leave1Out< INTERVALCONTAINER, IDXTYPE >, and FST::Data_Splitter_RandomRandom< INTERVALCONTAINER, IDXTYPE, BINTYPE >.

◆ splitter_name()

◆ stateless_clone()

template<class INTERVALCONTAINER, typename IDXTYPE>
Data_Splitter * FST::Data_Splitter< INTERVALCONTAINER, IDXTYPE >::stateless_clone ( ) const
overridepure virtual

create clone of the current object, ignoring internal temporary structures to save speed. Does not replicate exact object state. The clone must be used carefully in a way that ensures internal structure re-initialization Use example: Data_Splitter cloning or Classifier_LIBSVM cloning due to inability to clone external structures defined in LibSVM

Implements FST::Clonable.

Implemented in FST::Clonable_Impl< Data_Splitter_5050, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP >, FST::Clonable_Impl< Data_Splitter_5050< INTERVALCONTAINER, IDXTYPE >, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP >, FST::Clonable_Impl< Data_Splitter_CV, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP >, FST::Clonable_Impl< Data_Splitter_CV< INTERVALCONTAINER, IDXTYPE >, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP >, FST::Clonable_Impl< Data_Splitter_Holdout, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP >, FST::Clonable_Impl< Data_Splitter_Holdout< INTERVALCONTAINER, IDXTYPE >, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP >, FST::Clonable_Impl< Data_Splitter_Leave1Out, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP >, FST::Clonable_Impl< Data_Splitter_Leave1Out< INTERVALCONTAINER, IDXTYPE >, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP >, FST::Clonable_Impl< Data_Splitter_RandomRandom, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP >, FST::Clonable_Impl< Data_Splitter_RandomRandom< INTERVALCONTAINER, IDXTYPE, BINTYPE >, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP >, FST::Clonable_Impl< Data_Splitter_Resub, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP >, FST::Clonable_Impl< Data_Splitter_Resub< INTERVALCONTAINER, IDXTYPE >, Data_Splitter< INTERVALCONTAINER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP >, and FST::Clonable_Impl< Data_Splitter_TrainRandom_TestFixed< INTERVALCONTAINER, IDXTYPE, BINTYPE >, Data_Splitter_RandomRandom< INTERVALCONTAINER, IDXTYPE, BINTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP >.


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.