Feature Selection Toolbox FST4
UTIA · Czech Academy of Sciences
Loading...
Searching...
No Matches
data_splitter_holdout.hpp
Go to the documentation of this file.
1#ifndef FSTDATASPLITTERHOLDOUT_H
2#define FSTDATASPLITTERHOLDOUT_H
3 /*
27=========================================================================
28Copyright and license:
29 * FST4 software (with the exception of any bundled or externally linked
30 third-party components) is Copyright (C) 2000-present Institute of
31 Information Theory and Automation of the Czech Academy of Sciences (UTIA).
32 * FST4 is free software: you can redistribute it and/or modify it under
33 the terms of the GNU Affero General Public License as published by the
34 Free Software Foundation, version 3. The full text of the license is in
35 the file LICENSE in the distribution root and at
36 https://www.gnu.org/licenses/agpl-3.0.html.
37 * FST4 is distributed in the hope that it will be useful, but WITHOUT ANY
38 WARRANTY; without even the implied warranty of MERCHANTABILITY or
39 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
40 License for more details.
41 * Closed-source use without the AGPL's copyleft obligations requires a
42 commercial license from UTIA; in case of interest write to
43 utia@utia.cas.cz. LICENSING.md in the distribution root explains both
44 options, the contributor license agreement that every contribution
45 requires, and the contacts (technical questions and pull requests:
46 somol@utia.cas.cz, with "FST" in the subject line).
47========================================================================== */
48
49#include <memory>
50#include <cassert>
51#include <iostream>
52#include <cstdlib>
53#include <ctime>
54#include <vector>
55#include "error.hpp"
56#include "global.hpp"
57#include "data_splitter.hpp"
58
59/*============== Template parameter type naming conventions ==============
60--------- Numeric types: -------------------------------------------------
61DATATYPE - data sample values - usually real numbers (but may be integers
62 in text processing etc.)
63REALTYPE - must be real numbers - for representing intermediate results of
64 calculations like mean, covariance etc.
65IDXTYPE - index values for enumeration of data samples - (nonnegative) integers,
66 extent depends on numbers of samples in data
67DIMTYPE - index values for enumeration of features (dimensions), or classes (not
68 class sizes) - (nonnegative) integers, usually lower extent than IDXTYPE,
69 but be aware of expressions like _classes*_features*_features !
70 in linearized representations of feature matrices for all classes
71BINTYPE - feature selection marker type - represents ca. <10 different feature
72 states (selected, deselected, sel./desel. temporarily 1st nested loop, 2nd...)
73RETURNTYPE - criterion value: real value, but may be extended in future to support
74 multiple values
75--------- Class types: ---------------------------------------------------
76SUBSET - class of class type Subset
77CLASSIFIER - class implementing interface defined in abstract class Classifier
78EVALUATOR - class implementing interface defined in abstract class Sequential_Step
79DISTANCE - class implementing interface defined in abstract class Distance
80DATAACCESSOR - class implementing interface defined in abstract class Data_Accessor
81INTERVALCONTAINER - class of class type Data_Intervaller
82CONTAINER - STL container of class type Data_Interval
83========================================================================== */
84
85namespace FST {
86
87// HOLD-OUT
88
99template<class INTERVALCONTAINER, typename IDXTYPE>
100class Data_Splitter_Holdout : public Clonable_Impl<Data_Splitter_Holdout<INTERVALCONTAINER,IDXTYPE>,Data_Splitter<INTERVALCONTAINER,IDXTYPE>,CLONE_INHERIT,CLONE_INHERIT,CLONE_DEEP> {
101public:
103 Data_Splitter_Holdout(const IDXTYPE _perctrain) : parent_impl() , perctrain(_perctrain) {assert(perctrain<=100); notify("Data_Splitter_Holdout constructor.");}
104 Data_Splitter_Holdout(const Data_Splitter_Holdout& dsp) : parent_impl(dsp) , perctrain(dsp.perctrain) {notify("Data_Splitter_Holdout copy constructor.");}
105 virtual ~Data_Splitter_Holdout() {notify("Data_Splitter_Holdout destructor.");}
106 virtual IDXTYPE getNoOfSplits() const override {return 1;}
107
108 virtual std::ostream& print(std::ostream& os) const override {os << "Data_Splitter_Holdout()"; return os;}
109protected:
111 // Template-method hooks: makeFirstSplit()/makeNextSplit() skeletons live in Data_Splitter
112 virtual const char* splitter_name() const override {return "Data_Splitter_Holdout";}
113 virtual bool prepareNextSplit() override {return false;} // single-split splitter
114 virtual void splitClassFirst(typename TCC::ClassIterator c, const unsigned int) override {
115 const IDXTYPE trsiz=((*c)->n * perctrain)/100;
116 const IDXTYPE tesiz=(*c)->n-trsiz;
117 Data_Interval<IDXTYPE> tri={0,trsiz},tei={trsiz,tesiz};
118 (*c)->train->clear(); (*c)->train->push_back(tri);
119 (*c)->test->clear(); (*c)->test->push_back(tei);
120 }
121private:
122 const IDXTYPE perctrain;
123};
124
125
126} // namespace
127#endif // FSTDATASPLITTERHOLDOUT_H ///:~
CRTP mixin implementing the Clonable protocol for a concrete class.
Definition clonable.hpp:184
Implements train/test data splitting: use initial x% of original data for training,...
Definition data_splitter_holdout.hpp:100
virtual bool prepareNextSplit() override
advance split-sequence state; false = no more splits
Definition data_splitter_holdout.hpp:113
virtual IDXTYPE getNoOfSplits() const override
Definition data_splitter_holdout.hpp:106
Data_Splitter< INTERVALLER, IDXTYPE > TCC
Definition data_splitter_holdout.hpp:110
Clonable_Impl< Data_Splitter_Holdout, Data_Splitter< INTERVALLER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP > parent_impl
Definition data_splitter_holdout.hpp:102
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_holdout.hpp:108
Data_Splitter_Holdout(const IDXTYPE _perctrain)
the initial _perctrain % of each class trains, the rest tests (single split)
Definition data_splitter_holdout.hpp:103
Data_Splitter_Holdout(const Data_Splitter_Holdout &dsp)
copies configuration
Definition data_splitter_holdout.hpp:104
virtual const char * splitter_name() const override
class name, used in error messages
Definition data_splitter_holdout.hpp:112
const IDXTYPE perctrain
Definition data_splitter_holdout.hpp:122
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)
Definition data_splitter_holdout.hpp:114
Abstract class, defines interface for data splitting implementations (for use in data accessors).
Definition data_splitter.hpp:124
std::vector< PClassSplitter >::const_iterator ClassIterator
iterator over csplit, as passed to the per-class splitClassFirst()/splitClassNext() hooks
Definition data_splitter.hpp:174
Defines interface for data splitting implementations (for use in data accessors).
FST4 specific error passing class.
Global definitions.
The Feature Selection Toolbox 4 library: every library component – data access, criteria and classifi...
Definition data_accessor.hpp:80
@ CLONE_DEEP
new Derived(*this), then set_cloned()
Definition clonable.hpp:149
@ CLONE_INHERIT
do not add behavior; defer to the Base class body (typically a family-level throwing default)
Definition clonable.hpp:147
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
Support structure to hold data interval (referring into data held by data accessor).
Definition data_intervaller.hpp:88
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.