Feature Selection Toolbox FST4
UTIA · Czech Academy of Sciences
Loading...
Searching...
No Matches
data_accessor_universe.hpp
Go to the documentation of this file.
1#ifndef FSTDATAACCESSORUNIVERSE_H
2#define FSTDATAACCESSORUNIVERSE_H
3 /*
28=========================================================================
29Copyright and license:
30 * FST4 software (with the exception of any bundled or externally linked
31 third-party components) is Copyright (C) 2000-present Institute of
32 Information Theory and Automation of the Czech Academy of Sciences (UTIA).
33 * FST4 is free software: you can redistribute it and/or modify it under
34 the terms of the GNU Affero General Public License as published by the
35 Free Software Foundation, version 3. The full text of the license is in
36 the file LICENSE in the distribution root and at
37 https://www.gnu.org/licenses/agpl-3.0.html.
38 * FST4 is distributed in the hope that it will be useful, but WITHOUT ANY
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or
40 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
41 License for more details.
42 * Closed-source use without the AGPL's copyleft obligations requires a
43 commercial license from UTIA; in case of interest write to
44 utia@utia.cas.cz. LICENSING.md in the distribution root explains both
45 options, the contributor license agreement that every contribution
46 requires, and the contacts (technical questions and pull requests:
47 somol@utia.cas.cz, with "FST" in the subject line).
48========================================================================== */
49
50#include <sstream>
51#include "error.hpp"
52#include "global.hpp"
54
55namespace FST {
56
81template<typename DATATYPE, typename IDXTYPE, class INTERVALCONTAINER>
82class Data_Accessor_Universe : public Clonable_Impl<Data_Accessor_Universe<DATATYPE,IDXTYPE,INTERVALCONTAINER>,Data_Accessor_Splitting_Mem<DATATYPE,IDXTYPE,INTERVALCONTAINER>,CLONE_INHERIT,CLONE_WEAK_SHARING,CLONE_INHERIT>
83{
84 public:
86 typedef typename DASM::DAS DAS;
89 typedef std::shared_ptr<Data_Scaler<DATATYPE> > PScaler;
90 typedef typename DASM::PSplitters PSplitters;
92 Data_Accessor_Universe(const unsigned int n_features, const PSplitters _dsp, const PScaler _dsc) : parent_impl("",_dsp,_dsc), _n(n_features) {notify("Data_Accessor_Universe constructor.");}
93 virtual ~Data_Accessor_Universe(){notify("Data_Accessor_Universe destructor.");}
94
98 virtual void initialize() override
99 {
100 if(Clonable::is_sharing_clone()) throw fst_error("Data_Accessor_Universe::initialize() called from shared_clone instance.");
101 if(_n==0) throw fst_error("Data_Accessor_Universe: the feature universe must have at least 1 feature.");
102 {std::ostringstream sos; sos << "Feature universe: " << _n << " features, no data (--features)" << std::endl; syncout::print(std::cout,sos);}
103 DAS::initialize(_n, typename DAS::CLASSSIZES()); // features=N, zero classes; no buffer, no scaling, no splitter set_n
104 }
105
106 // The three overrides below implement a trivial split protocol: exactly one (empty) split per
107 // enumeration round. There is nothing to split, but callers iterate splits unconditionally. The
108 // base machinery is bypassed on purpose: it would run the configured splitter over zero classes,
109 // tripping its (correct) debug assertions in Debug builds.
110 virtual bool getFirstSplit() override {DAS::enum_split[DAS::getSplittingDepth()]=1; return true;}
111 virtual bool getNextSplit() override {DAS::enum_split[DAS::getSplittingDepth()]=0; return false;}
112 virtual unsigned int getNoOfSplits() const override {return 1;}
113
114 virtual std::ostream& print(std::ostream& os) const override {os << "Data_Accessor_Universe(features=" << _n << ", data-free)"; return os;}
115 protected:
116 friend parent_impl;
119 Data_Accessor_Universe(const Data_Accessor_Universe &dau, int x) : parent_impl(dau, x), _n(dau._n) {};
120 protected:
121 unsigned int _n;
122
123 // the file hooks exist to satisfy the DASM pure-virtual contract; initialize() is
124 // overridden above so the read hooks never run, and the shape hooks report the
125 // honest degenerate values should diagnostics ever query them
126 virtual void initial_data_read() override {}
127 virtual void initial_file_prepare() override {}
128 virtual unsigned int file_getNoOfClasses() const override {return 0;}
129 virtual unsigned int file_getNoOfFeatures() const override {return _n;}
130 virtual IDXTYPE file_getClassSize(unsigned int) const override {return 0;}
131};
132
133} // namespace
134#endif // FSTDATAACCESSORUNIVERSE_H ///:~
CRTP mixin implementing the Clonable protocol for a concrete class.
Definition clonable.hpp:184
bool is_sharing_clone() const
true if this instance is BOTH a clone and sharing – i.e. specifically a sharing_clone() result,...
Definition clonable.hpp:127
Implements data access to data cached entirely in memory, concrete file type support is delegated to ...
Definition data_accessor_splitting_mem.hpp:102
DAS::PSplitters PSplitters
Definition data_accessor_splitting_mem.hpp:110
Data_Accessor_Splitting< DATATYPE, IDXTYPE, INTERVALLER > DAS
Definition data_accessor_splitting_mem.hpp:107
std::vector< unsigned int > CLASSSIZES
per-class pattern counts, indexed by class index; the format initialize() takes
Definition data_accessor_splitting.hpp:203
unsigned int getSplittingDepth() const
the nested splitting level last set via setSplittingDepth()
Definition data_accessor_splitting.hpp:172
std::vector< IDXTYPE > enum_split
current split.. 0~none
Definition data_accessor_splitting.hpp:242
void initialize(const unsigned int _features, const CLASSSIZES &_classes)
Definition data_accessor_splitting.hpp:503
Data-free accessor over an abstract feature universe of N features (the fst4 CLI's --features N entry...
Definition data_accessor_universe.hpp:83
DASM::DAS DAS
Definition data_accessor_universe.hpp:86
std::shared_ptr< Data_Scaler< DATATYPE > > PScaler
Definition data_accessor_universe.hpp:89
virtual IDXTYPE file_getClassSize(unsigned int) const override
the degenerate shape: no class has any samples
Definition data_accessor_universe.hpp:130
virtual void initial_file_prepare() override
no-op: there is no file to open
Definition data_accessor_universe.hpp:127
virtual unsigned int file_getNoOfFeatures() const override
the universe size _n
Definition data_accessor_universe.hpp:129
Data_Accessor_Universe(const unsigned int n_features, const PSplitters _dsp, const PScaler _dsc)
Constructs the accessor over an abstract universe of n_features features; _dsp and _dsc are accepted ...
Definition data_accessor_universe.hpp:92
Clonable_Impl< Data_Accessor_Universe, DASM, CLONE_INHERIT, CLONE_WEAK_SHARING, CLONE_INHERIT > parent_impl
Definition data_accessor_universe.hpp:88
virtual unsigned int file_getNoOfClasses() const override
the degenerate shape: 0 classes (no data)
Definition data_accessor_universe.hpp:128
unsigned int _n
Definition data_accessor_universe.hpp:121
virtual unsigned int getNoOfSplits() const override
always 1
Definition data_accessor_universe.hpp:112
virtual std::ostream & print(std::ostream &os) const override
writes the splitter stack's print() output (or "Data_Accessor_Splitting()" if the stack is empty) to ...
Definition data_accessor_universe.hpp:114
DASM::PSplitters PSplitters
Definition data_accessor_universe.hpp:90
virtual void initial_data_read() override
no-op: there is no data to read (the overridden initialize() never calls it)
Definition data_accessor_universe.hpp:126
virtual void initialize() override
no file to read: announces the universe and sets up the degenerate shape (N features,...
Definition data_accessor_universe.hpp:98
virtual bool getNextSplit() override
always false: the single split is the only one
Definition data_accessor_universe.hpp:111
Data_Accessor_Universe(const Data_Accessor_Universe &dau, int x)
Definition data_accessor_universe.hpp:119
Data_Accessor_Splitting_Mem< DATATYPE, IDXTYPE, INTERVALLER > DASM
Definition data_accessor_universe.hpp:85
virtual bool getFirstSplit() override
enters the single split; always true
Definition data_accessor_universe.hpp:110
FST4 specific error passing class.
Definition error.hpp:61
static void print(std::ostream &os, std::ostringstream &sos)
Writes sos's buffered content to os, serializing concurrent writers under FST_THREADED via a shared m...
Definition global.hpp:86
Implements data access to data cached entirely in memory, concrete file type support is delegated to ...
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
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
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.