Feature Selection Toolbox FST4
UTIA · Czech Academy of Sciences
Loading...
Searching...
No Matches
data_accessor_splitting_memARFF.hpp
Go to the documentation of this file.
1#ifndef FSTDATAACCESSORSPLITTINGMEMARFF_H
2#define FSTDATAACCESSORSPLITTINGMEMARFF_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 <sstream>
52#include <vector>
53
54#include "error.hpp"
55#include "global.hpp"
57#include "data_file_ARFF.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
88template<typename DATATYPE, typename IDXTYPE, class INTERVALCONTAINER>
89class Data_Accessor_Splitting_MemARFF : public Clonable_Impl<Data_Accessor_Splitting_MemARFF<DATATYPE,IDXTYPE,INTERVALCONTAINER>,Data_Accessor_Splitting_Mem<DATATYPE,IDXTYPE,INTERVALCONTAINER>,CLONE_INHERIT,CLONE_WEAK_SHARING,CLONE_INHERIT>
90{
91 // NOTE: the calling convention is the same for the inner and the outer CV loop -- both call just
92 // get*Split, get*Block, get*Pattern -- and which of them a call refers to is selected beforehand
93 // with the inherited setSplittingDepth()
94 public:
101 typedef std::shared_ptr<Data_Scaler<DATATYPE> > PScaler;
102 typedef typename DASM::PSplitters PSplitters;
104 Data_Accessor_Splitting_MemARFF(const std::string _filename, const PSplitters _dsp, const PScaler _dsc) : parent_impl(_filename, _dsp, _dsc) {notify("Data_Accessor_Splitting_MemARFF constructor.");}
105 virtual ~Data_Accessor_Splitting_MemARFF(){notify("Data_Accessor_Splitting_MemARFF destructor.");}
106
107 virtual std::ostream& print(std::ostream& os) const override;
108 protected:
109 friend parent_impl;
114 protected:
115 std::unique_ptr<Data_File_ARFF> ARFFFile;
116
117 unsigned int clsCount;
118 unsigned int featureCount;
119 std::shared_ptr<IDXTYPE> clsSize;
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 {return clsCount; }
126 virtual unsigned int file_getNoOfFeatures() const override {return featureCount; }
127 virtual IDXTYPE file_getClassSize(unsigned int cls) const override {return clsSize.get()[cls]; }
128};
129
130template<typename DATATYPE, typename IDXTYPE, class INTERVALCONTAINER>
132{
133 if(Clonable::is_sharing_clone()) throw fst_error("Data_Accessor_Splitting_MemARFF()::initial_file_prepare() called from shared_clone instance.");
134 ARFFFile.reset(new Data_File_ARFF(this->filename));
135 if(!ARFFFile->prepareFile()) // the reader has already printed the offending line/reason
136 throw fst_error("ARFF file '"+this->filename+"' could not be loaded (see the reader's message above for the offending definition or data row)");
137 ARFFFile->sortRecordsByClass();
138
139 clsCount = ARFFFile->getNoOfClasses();
140 featureCount = ARFFFile->getNoOfFeatures();
141 clsSize.reset(new IDXTYPE[clsCount], std::default_delete<IDXTYPE[]>());
142 for (unsigned int i=0;i<clsCount; i++) clsSize.get()[i] = ARFFFile->getClassSize(i);
143}
144
145template<typename DATATYPE, typename IDXTYPE, class INTERVALCONTAINER>
147{
148 if(Clonable::is_sharing_clone()) throw fst_error("Data_Accessor_Splitting_MemARFF()::initial_data_read() called from shared_clone instance.");
149 {std::ostringstream sos; sos << "Reading data to memory..."; syncout::print(std::cout,sos);}
150 IDXTYPE idx=0;
151 for(unsigned int p=0;p<ARFFFile->getTotalSize();p++)
152 {
153 for(unsigned int f=0;f<ARFFFile->getNoOfFeatures();f++) {
154 this->data.get()[idx++]=(DATATYPE) ARFFFile->getFeatureValue(p,f);
155 }
156 }
157 ARFFFile.reset();
158 {std::ostringstream sos; sos << "done."<<std::endl; syncout::print(std::cout,sos);}
159}
160
161
162
163template<typename DATATYPE, typename IDXTYPE, class INTERVALCONTAINER>
165{
166 DASM::print(os);
167 os << std::endl << "Data_Accessor_Splitting_MemARFF()";
168 return os;
169}
170
171} // namespace
172#endif // FSTDATAACCESSORSPLITTINGMEMARFF_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, read once from a ARFF file.
Definition data_accessor_splitting_memARFF.hpp:90
Data_Accessor_Splitting_MemARFF(const Data_Accessor_Splitting_MemARFF &damt, int x)
Weak (referencing) copy-constructor used by sharing_clone(); transfers the cached header counters cls...
Definition data_accessor_splitting_memARFF.hpp:113
DASM::PSplitters PSplitters
Definition data_accessor_splitting_memARFF.hpp:102
Data_Accessor_Splitting_MemARFF(const std::string _filename, const PSplitters _dsp, const PScaler _dsc)
Constructs the accessor for the ARFF file _filename, the splitter stack _dsp and the scaler _dsc; act...
Definition data_accessor_splitting_memARFF.hpp:104
virtual void initial_data_read() override
copies the reader's values into the base class's data array, then releases the reader;
Definition data_accessor_splitting_memARFF.hpp:146
std::shared_ptr< IDXTYPE > clsSize
Definition data_accessor_splitting_memARFF.hpp:119
virtual unsigned int file_getNoOfFeatures() const override
featureCount, as required by Data_Accessor_Splitting_Mem
Definition data_accessor_splitting_memARFF.hpp:126
Data_Accessor_Splitting_Mem< DATATYPE, IDXTYPE, INTERVALLER > DASM
Definition data_accessor_splitting_memARFF.hpp:95
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_memARFF.hpp:164
unsigned int clsCount
Definition data_accessor_splitting_memARFF.hpp:117
virtual void initial_file_prepare() override
opens ARFFFile, reads and class-sorts it, and caches clsCount/featureCount/clsSize; throws fst_error ...
Definition data_accessor_splitting_memARFF.hpp:131
std::unique_ptr< Data_File_ARFF > ARFFFile
Definition data_accessor_splitting_memARFF.hpp:115
std::shared_ptr< Data_Scaler< DATATYPE > > PScaler
Definition data_accessor_splitting_memARFF.hpp:101
unsigned int featureCount
Definition data_accessor_splitting_memARFF.hpp:118
virtual IDXTYPE file_getClassSize(unsigned int cls) const override
clsSize[cls], as required by Data_Accessor_Splitting_Mem
Definition data_accessor_splitting_memARFF.hpp:127
Clonable_Impl< Data_Accessor_Splitting_MemARFF, DASM, CLONE_INHERIT, CLONE_WEAK_SHARING, CLONE_INHERIT > parent_impl
Definition data_accessor_splitting_memARFF.hpp:100
virtual unsigned int file_getNoOfClasses() const override
clsCount, as required by Data_Accessor_Splitting_Mem
Definition data_accessor_splitting_memARFF.hpp:125
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
ARFF data format filter.
Definition data_file_ARFF.hpp:135
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 ARFF (Weka) 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.