Implements train/test data splitting: use randomly chosen x% of data samples for training and another y% of data for testing, without overlaps, separately in each class.
More...
|
|
| 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 |
| virtual std::ostream & | print (std::ostream &os) const override |
| | writes a human-readable identification of the splitter and its configuration; base default writes nothing
|
| 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)
|
|
| 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 |
| 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
|
|
| virtual void | makeRandomSplit (const IDXTYPE n, const std::shared_ptr< INTERVALCONTAINER > list_train, const std::shared_ptr< INTERVALCONTAINER > list_test) |
| | Generates one class's non-overlapping random train/test split of n samples into list_train / list_test (perctrain %/perctest % via fill_randomly()/fill()/translate()).
|
| 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.
|
|
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
|
|
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)
|
|
|
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
|
|
std::vector< PClassSplitter > | csplit |
| | one TClassSplitter per data class, indexed by class index; grown on demand by assign()/set_n()
|
template<class INTERVALCONTAINER, typename IDXTYPE, typename BINTYPE>
class FST::Data_Splitter_RandomRandom< INTERVALCONTAINER, IDXTYPE, BINTYPE >
Implements train/test data splitting: use randomly chosen x% of data samples for training and another y% of data for testing, without overlaps, separately in each class.
Yields the configured number of splits, each drawing a fresh random selection. The train part holds (class size * perctrain)/100 samples, rounded down. When the two percentages add up to 100 the test part is the whole complement of the train part (so it may hold one sample more than (class size * perctest)/100 would give); otherwise it holds (class size * perctest)/100 samples, rounded down, and the remaining samples are used by neither part.
Reproducibility. By default the draws come from the library PRNG (FST::fst_rand()), so a fixed seed reproduces the same splits on every platform and in every run.
- Warning
- Constructed with randomize==true, the splitter instead seeds its own engine from std::random_device: the splits then differ from run to run and results cannot be reproduced. Choose it only for experiments that deliberately want fresh randomness each time.
- Examples
- demo55.cpp.