Feature Selection Toolbox FST4
UTIA · Czech Academy of Sciences
Loading...
Searching...
No Matches
data_splitter_5050.hpp
Go to the documentation of this file.
1#ifndef FSTDATASPLITTER5050_H
2#define FSTDATASPLITTER5050_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 <iostream>
51#include <cstdlib>
52#include <ctime>
53#include <vector>
54#include "error.hpp"
55#include "global.hpp"
56#include "data_splitter.hpp"
57
58/*============== Template parameter type naming conventions ==============
59--------- Numeric types: -------------------------------------------------
60DATATYPE - data sample values - usually real numbers (but may be integers
61 in text processing etc.)
62REALTYPE - must be real numbers - for representing intermediate results of
63 calculations like mean, covariance etc.
64IDXTYPE - index values for enumeration of data samples - (nonnegative) integers,
65 extent depends on numbers of samples in data
66DIMTYPE - index values for enumeration of features (dimensions), or classes (not
67 class sizes) - (nonnegative) integers, usually lower extent than IDXTYPE,
68 but be aware of expressions like _classes*_features*_features !
69 in linearized representations of feature matrices for all classes
70BINTYPE - feature selection marker type - represents ca. <10 different feature
71 states (selected, deselected, sel./desel. temporarily 1st nested loop, 2nd...)
72RETURNTYPE - criterion value: real value, but may be extended in future to support
73 multiple values
74--------- Class types: ---------------------------------------------------
75SUBSET - class of class type Subset
76CLASSIFIER - class implementing interface defined in abstract class Classifier
77EVALUATOR - class implementing interface defined in abstract class Sequential_Step
78DISTANCE - class implementing interface defined in abstract class Distance
79DATAACCESSOR - class implementing interface defined in abstract class Data_Accessor
80INTERVALCONTAINER - class of class type Data_Intervaller
81CONTAINER - STL container of class type Data_Interval
82========================================================================== */
83
84namespace FST {
85
86// FIFTY-FIFTY
87
98template<class INTERVALCONTAINER, typename IDXTYPE>
99class Data_Splitter_5050 : public Clonable_Impl<Data_Splitter_5050<INTERVALCONTAINER,IDXTYPE>,Data_Splitter<INTERVALCONTAINER,IDXTYPE>,CLONE_INHERIT,CLONE_INHERIT,CLONE_DEEP> {
100public:
102 Data_Splitter_5050() : parent_impl() {notify("Data_Splitter_5050 constructor.");}
103 Data_Splitter_5050(const Data_Splitter_5050& dsp) : parent_impl(dsp) {notify("Data_Splitter_5050 copy constructor.");}
104 virtual ~Data_Splitter_5050() {notify("Data_Splitter_5050 destructor.");}
105 virtual IDXTYPE getNoOfSplits() const override {return 1;}
106
107 virtual std::ostream& print(std::ostream& os) const override {os << "Data_Splitter_5050()"; return os;}
108protected:
110 // Template-method hooks: makeFirstSplit()/makeNextSplit() skeletons live in Data_Splitter
111 virtual const char* splitter_name() const override {return "Data_Splitter_5050";}
112 virtual bool prepareNextSplit() override {return false;} // single-split splitter
113 virtual void splitClassFirst(typename TCC::ClassIterator c, const unsigned int) override {
114 const IDXTYPE trsiz=(*c)->n/2;
115 const IDXTYPE tesiz=(*c)->n-trsiz;
116 Data_Interval<IDXTYPE> tri={0,trsiz},tei={trsiz,tesiz};
117 (*c)->train->clear(); (*c)->train->push_back(tri);
118 (*c)->test->clear(); (*c)->test->push_back(tei);
119 }
120};
121
122
123} // namespace
124#endif // FSTDATASPLITTER5050_H ///:~
CRTP mixin implementing the Clonable protocol for a concrete class.
Definition clonable.hpp:184
Implements train/test data splitting: first 50% of original data for training, second 50% for testing...
Definition data_splitter_5050.hpp:99
virtual const char * splitter_name() const override
class name, used in error messages
Definition data_splitter_5050.hpp:111
Clonable_Impl< Data_Splitter_5050, Data_Splitter< INTERVALLER, IDXTYPE >, CLONE_INHERIT, CLONE_INHERIT, CLONE_DEEP > parent_impl
Definition data_splitter_5050.hpp:101
Data_Splitter< INTERVALLER, IDXTYPE > TCC
Definition data_splitter_5050.hpp:109
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_5050.hpp:113
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_5050.hpp:107
virtual IDXTYPE getNoOfSplits() const override
Definition data_splitter_5050.hpp:105
Data_Splitter_5050(const Data_Splitter_5050 &dsp)
copies configuration (this splitter is parameterless, so there is nothing else to copy)
Definition data_splitter_5050.hpp:103
virtual bool prepareNextSplit() override
advance split-sequence state; false = no more splits
Definition data_splitter_5050.hpp:112
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.