1#ifndef FSTDATASPLITTER_H
2#define FSTDATASPLITTER_H
88template<
class INTERVALCONTAINER,
typename IDXTYPE>
91template<
class INTERVALCONTAINER,
typename IDXTYPE>
123template<
class INTERVALCONTAINER,
typename IDXTYPE>
124class Data_Splitter :
public Clonable {
126 friend std::ostream& operator<< <>(std::ostream& os,
const Data_Splitter<INTERVALCONTAINER,IDXTYPE>& ds);
129 Data_Splitter() {
csplit.clear();
notify(
"Data_Splitter constructor.");}
137 void set_n(
const unsigned int _clsidx,
const IDXTYPE _n);
138 IDXTYPE
get_n(
const unsigned int _clsidx)
const;
149 Data_Splitter*
clone()
const override {
throw fst_error(
"Data_Splitter::clone() not supported, use Data_Splitter::stateless_clone() instead.");}
150 Data_Splitter*
sharing_clone()
const override {
throw fst_error(
"Data_Splitter::sharing_clone() not supported, use Data_Splitter::stateless_clone() instead.");}
153 virtual std::ostream&
print(std::ostream& os)
const override {
return os;}
157 class TClassSplitter {
159 TClassSplitter() {
n=0;
train.reset();
test.reset();
notify(
"TClassSplitter empty constructor.");}
162 notify(
"TClassSplitter strong copy constructor begin.");
164 if(cs.
test)
test.reset(
new INTERVALCONTAINER(*cs.
test));
165 notify(
"TClassSplitter strong copy constructor end.");
188template<
class INTERVALCONTAINER,
typename IDXTYPE>
203template<
class INTERVALCONTAINER,
typename IDXTYPE>
218template<
class INTERVALCONTAINER,
typename IDXTYPE>
219Data_Splitter<INTERVALCONTAINER,IDXTYPE>::Data_Splitter(
const Data_Splitter& dsp)
221 notify(
"Data_Splitter strong copy constructor begin.");
223 for(
typename std::vector<PClassSplitter>::const_iterator c=dsp.
csplit.begin();c!=dsp.
csplit.end();c++)
225 notify(
"Data_Splitter strong copy constructor end.");
228template<
class INTERVALCONTAINER,
typename IDXTYPE>
235 csplit[_clsidx]->train=_train;
236 csplit[_clsidx]->test=_test;
238 throw fst_error(
"Data_Splitter::set_n() out-of-index? error.");
242template<
class INTERVALCONTAINER,
typename IDXTYPE>
250 throw fst_error(
"Data_Splitter::set_n() out-of-index? error.");
254template<
class INTERVALCONTAINER,
typename IDXTYPE>
257 assert(_clsidx<
csplit.size());
259 return csplit[_clsidx]->n;
261 throw fst_error(
"Data_Splitter::get_n() out-of-index? error.");
266template<
class INTERVALCONTAINER,
typename IDXTYPE>
267std::ostream&
operator<<(std::ostream& os,
const Data_Splitter<INTERVALCONTAINER,IDXTYPE>& ds) {
271template<
class INTERVALCONTAINER,
typename IDXTYPE>
Data splitting support structure; holds one set of intervals (train, test) per each (data)class.
Definition data_splitter.hpp:157
PIntervaller test
pointer to external list of intervals that will be overwritten from here
Definition data_splitter.hpp:170
TClassSplitter(const TClassSplitter &cs)
Deep-copies cs's train/test interval lists (own INTERVALCONTAINER instances, not shared).
Definition data_splitter.hpp:161
PIntervaller train
pointer to external list of intervals that will be overwritten from here
Definition data_splitter.hpp:169
IDXTYPE n
n=total no. of patterns
Definition data_splitter.hpp:168
Abstract class, defines interface for data splitting implementations (for use in data accessors).
Definition data_splitter.hpp:124
virtual bool prepareNextSplit()=0
advance split-sequence state; false = no more splits
virtual bool prepareFirstSplit()
set up split-sequence state; false = no split can be made
Definition data_splitter.hpp:181
std::vector< PClassSplitter > csplit
one TClassSplitter per data class, indexed by class index; grown on demand by assign()/set_n()
Definition data_splitter.hpp:173
Data_Splitter * sharing_clone() const override
Definition data_splitter.hpp:150
bool makeNextSplit()
Produces the next split: prepareNextSplit(), then splitClassNext() per class, then finishSplit().
Definition data_splitter.hpp:204
std::shared_ptr< INTERVALCONTAINER > PIntervaller
shared pointer to one class's list of train/test data intervals
Definition data_splitter.hpp:128
void set_n(const unsigned int _clsidx, const IDXTYPE _n)
Sets class _clsidx's pattern count, which getNoOfSplits() and the concrete prepare*/splitClass* hook...
Definition data_splitter.hpp:243
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)
IDXTYPE get_n(const unsigned int _clsidx) const
the pattern count previously set for class _clsidx via set_n()
Definition data_splitter.hpp:255
std::shared_ptr< TClassSplitter > PClassSplitter
shared pointer to one class's TClassSplitter
Definition data_splitter.hpp:172
virtual const char * splitter_name() const =0
class name, used in error messages
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 ow...
Definition data_splitter.hpp:229
void assert_csplit() const
DEBUG-only: asserts csplit is non-empty and every class has n>0 and non-null train/test lists.
Definition data_splitter.hpp:272
Data_Splitter * stateless_clone() const override=0
virtual void finishSplit()
post-loop state update shared by first/next split
Definition data_splitter.hpp:185
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,...
Definition data_splitter.hpp:184
virtual IDXTYPE getNoOfSplits() const =0
Data_Splitter * clone() const override
Definition data_splitter.hpp:149
std::vector< PClassSplitter >::const_iterator ClassIterator
iterator over csplit, as passed to the per-class splitClassFirst()/splitClassNext() hooks
Definition data_splitter.hpp:174
bool makeFirstSplit()
Produces the first split: prepareFirstSplit(), then splitClassFirst() per class, then finishSplit().
Definition data_splitter.hpp:189
virtual std::ostream & print(std::ostream &os) const override
writes a human-readable identification of the splitter and its configuration; base default writes not...
Definition data_splitter.hpp:153
FST4 specific error passing class.
Definition error.hpp:61
Defines interface for classes that may need to get cloned.
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
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