Feature Selection Toolbox FST4
UTIA · Czech Academy of Sciences
Loading...
Searching...
No Matches
data_accessor_splitting_memTRN.hpp
Go to the documentation of this file.
1#ifndef FSTDATAACCESSORSPLITTINGMEMTRN_H
2#define FSTDATAACCESSORSPLITTINGMEMTRN_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 <sstream>
53#include <vector>
54
55#include "error.hpp"
56#include "global.hpp"
58#include "data_file_TRN.hpp"
59
60/*============== Template parameter type naming conventions ==============
61--------- Numeric types: -------------------------------------------------
62DATATYPE - data sample values - usually real numbers (but may be integers
63 in text processing etc.)
64REALTYPE - must be real numbers - for representing intermediate results of
65 calculations like mean, covariance etc.
66IDXTYPE - index values for enumeration of data samples - (nonnegative) integers,
67 extent depends on numbers of samples in data
68DIMTYPE - index values for enumeration of features (dimensions), or classes (not
69 class sizes) - (nonnegative) integers, usually lower extent than IDXTYPE,
70 but be aware of expressions like _classes*_features*_features !
71 in linearized representations of feature matrices for all classes
72BINTYPE - feature selection marker type - represents ca. <10 different feature
73 states (selected, deselected, sel./desel. temporarily 1st nested loop, 2nd...)
74RETURNTYPE - criterion value: real value, but may be extended in future to support
75 multiple values
76--------- Class types: ---------------------------------------------------
77SUBSET - class of class type Subset
78CLASSIFIER - class implementing interface defined in abstract class Classifier
79EVALUATOR - class implementing interface defined in abstract class Sequential_Step
80DISTANCE - class implementing interface defined in abstract class Distance
81DATAACCESSOR - class implementing interface defined in abstract class Data_Accessor
82INTERVALCONTAINER - class of class type Data_Intervaller
83CONTAINER - STL container of class type Data_Interval
84========================================================================== */
85
86namespace FST {
87
89template<typename DATATYPE, typename IDXTYPE, class INTERVALCONTAINER>
90class Data_Accessor_Splitting_MemTRN : public Clonable_Impl<Data_Accessor_Splitting_MemTRN<DATATYPE,IDXTYPE,INTERVALCONTAINER>,Data_Accessor_Splitting_Mem<DATATYPE,IDXTYPE,INTERVALCONTAINER>,CLONE_INHERIT,CLONE_WEAK_SHARING,CLONE_INHERIT>
91{
92 // NOTE: the calling convention is the same for the inner and the outer CV loop -- both call just
93 // get*Split, get*Block, get*Pattern -- and which of them a call refers to is selected beforehand
94 // with the inherited setSplittingDepth()
95 public:
102 typedef std::shared_ptr<Data_Scaler<DATATYPE> > PScaler;
103 typedef typename DASM::PSplitters PSplitters;
105 Data_Accessor_Splitting_MemTRN(const std::string _filename, const PSplitters _dsp, const PScaler _dsc) : parent_impl(_filename, _dsp, _dsc) {notify("Data_Accessor_Splitting_MemTRN constructor.");}
106 virtual ~Data_Accessor_Splitting_MemTRN(){notify("Data_Accessor_Splitting_MemTRN destructor.");}
107
108 virtual std::ostream& print(std::ostream& os) const override;
109 protected:
110 friend parent_impl;
115 protected:
119 std::shared_ptr<Data_File_TRN<DATATYPE,IDXTYPE> > trnFile;
120
121 virtual void initial_data_read() override ;
122 virtual void initial_file_prepare() override;
123
124 public:
125 virtual unsigned int file_getNoOfClasses() const override {assert(trnFile); return trnFile->getNoOfClasses(); }
126 virtual unsigned int file_getNoOfFeatures() const override {assert(trnFile); return trnFile->getNoOfFeatures(); }
127 virtual IDXTYPE file_getClassSize(unsigned int cls) const override {assert(trnFile); return trnFile->getClassSize(cls); }
128};
129
130template<typename DATATYPE, typename IDXTYPE, class INTERVALCONTAINER>
132{
133 if(Clonable::is_sharing_clone()) throw fst_error("Data_Accessor_Splitting_MemTRN()::initial_file_prepare() called from shared_clone instance.");
135 trnFile->open(this->filename);
136}
137
138template<typename DATATYPE, typename IDXTYPE, class INTERVALCONTAINER>
140{
141 if(Clonable::is_sharing_clone()) throw fst_error("Data_Accessor_Splitting_MemTRN()::initial_data_read() called from shared_clone instance.");
142 {std::ostringstream sos; sos << "Reading data to memory..."; syncout::print(std::cout,sos);}
143 IDXTYPE idx=0;
144 for(unsigned int c=0;c<trnFile->getNoOfClasses();c++)
145 {
146 for(IDXTYPE p=0;p<trnFile->getClassSize(c);p++) {
147 for(unsigned int f=0;f<trnFile->getNoOfFeatures();f++) {
148 this->data.get()[idx++]=trnFile->read_val();
149 }
150 }
151 }
152 trnFile->close();
153 {std::ostringstream sos; sos << "done."<<std::endl; syncout::print(std::cout,sos);}
154}
155
156
157
158template<typename DATATYPE, typename IDXTYPE, class INTERVALCONTAINER>
160{
161 DASM::print(os);
162 os << std::endl << "Data_Accessor_Splitting_MemTRN()";
163 return os;
164}
165
166} // namespace
167#endif // FSTDATAACCESSORSPLITTINGMEMTRN_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
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_splitting_mem.hpp:412
std::shared_ptr< DATATYPE > data
Definition data_accessor_splitting_mem.hpp:199
std::string filename
Definition data_accessor_splitting_mem.hpp:196
Implements data access to data cached entirely in memory, read once from a TRN file.
Definition data_accessor_splitting_memTRN.hpp:91
virtual void initial_data_read() override
reads the whole file into the base class's data array, then closes the file;
Definition data_accessor_splitting_memTRN.hpp:139
Data_Accessor_Splitting_MemTRN(const std::string _filename, const PSplitters _dsp, const PScaler _dsc)
Constructs the accessor for TRN file _filename, splitter stack _dsp and scaler _dsc; the file is open...
Definition data_accessor_splitting_memTRN.hpp:105
DASM::PSplitters PSplitters
Definition data_accessor_splitting_memTRN.hpp:103
virtual void initial_file_prepare() override
opens trnFile on this->filename;
Definition data_accessor_splitting_memTRN.hpp:131
Data_Accessor_Splitting_MemTRN(const Data_Accessor_Splitting_MemTRN &damt, int x)
Definition data_accessor_splitting_memTRN.hpp:114
virtual IDXTYPE file_getClassSize(unsigned int cls) const override
forwards to the open TRN file
Definition data_accessor_splitting_memTRN.hpp:127
std::shared_ptr< Data_Scaler< DATATYPE > > PScaler
Definition data_accessor_splitting_memTRN.hpp:102
virtual unsigned int file_getNoOfFeatures() const override
forwards to the open TRN file
Definition data_accessor_splitting_memTRN.hpp:126
std::shared_ptr< Data_File_TRN< DATATYPE, IDXTYPE > > trnFile
Definition data_accessor_splitting_memTRN.hpp:119
Data_Accessor_Splitting_Mem< DATATYPE, IDXTYPE, INTERVALLER > DASM
Definition data_accessor_splitting_memTRN.hpp:96
virtual unsigned int file_getNoOfClasses() const override
forwards to the open TRN file
Definition data_accessor_splitting_memTRN.hpp:125
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_splitting_memTRN.hpp:159
Clonable_Impl< Data_Accessor_Splitting_MemTRN, DASM, CLONE_INHERIT, CLONE_WEAK_SHARING, CLONE_INHERIT > parent_impl
Definition data_accessor_splitting_memTRN.hpp:101
TRN data format filter.
Definition data_file_TRN.hpp:136
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 ...
Enables data accessor objects to read TRN type of data files.
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.