Feature Selection Toolbox FST4
UTIA · Czech Academy of Sciences
Loading...
Searching...
No Matches
seq_step.hpp
Go to the documentation of this file.
1#ifndef FSTSEARCHSEQSTEP_H
2#define FSTSEARCHSEQSTEP_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 "error.hpp"
52#include "global.hpp"
53#include "result_tracker.hpp"
54
55/*============== Template parameter type naming conventions ==============
56--------- Numeric types: -------------------------------------------------
57DATATYPE - data sample values - usually real numbers (but may be integers
58 in text processing etc.)
59REALTYPE - must be real numbers - for representing intermediate results of
60 calculations like mean, covariance etc.
61IDXTYPE - index values for enumeration of data samples - (nonnegative) integers,
62 extent depends on numbers of samples in data
63DIMTYPE - index values for enumeration of features (dimensions), or classes (not
64 class sizes) - (nonnegative) integers, usually lower extent than IDXTYPE,
65 but be aware of expressions like _classes*_features*_features !
66 in linearized representations of feature matrices for all classes
67BINTYPE - feature selection marker type - represents ca. <10 different feature
68 states (selected, deselected, sel./desel. temporarily 1st nested loop, 2nd...)
69RETURNTYPE - criterion value: real value, but may be extended in future to support
70 multiple values
71--------- Class types: ---------------------------------------------------
72SUBSET - class of class type Subset
73CLASSIFIER - class implementing interface defined in abstract class Classifier
74EVALUATOR - class implementing interface defined in abstract class Sequential_Step
75DISTANCE - class implementing interface defined in abstract class Distance
76DATAACCESSOR - class implementing interface defined in abstract class Data_Accessor
77INTERVALCONTAINER - class of class type Data_Intervaller
78CONTAINER - STL container of class type Data_Interval
79========================================================================== */
80
81namespace FST {
82
83template<class RETURNTYPE, typename DIMTYPE, class SUBSET, class CRITERION>
84class Sequential_Step;
85
87template<class RETURNTYPE, typename DIMTYPE, class SUBSET, class CRITERION>
88std::ostream& operator<<(std::ostream& os, const Sequential_Step<RETURNTYPE,DIMTYPE,SUBSET,CRITERION>& ss);
89
96template<class RETURNTYPE, typename DIMTYPE, class SUBSET, class CRITERION>
97class Sequential_Step { // abstract class
99 friend std::ostream& operator<< <>(std::ostream& os, const Sequential_Step<RETURNTYPE,DIMTYPE,SUBSET,CRITERION>& ss);
100public:
101 typedef std::shared_ptr<CRITERION> PCriterion;
102 typedef std::shared_ptr<SUBSET> PSubset;
103 typedef std::shared_ptr<Result_Tracker<RETURNTYPE,SUBSET> > PResultTracker;
104 Sequential_Step():_detail(NORMAL) {}
105 virtual ~Sequential_Step() {}
106
107 // NOTE: crit is expected to be already initialize()d before use here
127 virtual bool evaluate_candidates(RETURNTYPE &result, const PSubset sub, const PCriterion crit, const DIMTYPE _generalization_level, std::ostream& os) =0;
128
129 virtual std::ostream& print(std::ostream& os) const {return os;}
130public:
133 bool result_tracker_active() const {return _tracker.get()!=0;}
134
135 void set_output_detail(OutputDetail detail) {_detail=detail;}
137 bool output_normal() const {return _detail==NORMAL || _detail==DETAILED;}
138 bool output_detailed() const {return _detail==DETAILED;}
139protected:
142};
143
145template<class RETURNTYPE, typename DIMTYPE, class SUBSET, class CRITERION>
146std::ostream& operator<<(std::ostream& os, const Sequential_Step<RETURNTYPE,DIMTYPE,SUBSET,CRITERION>& ss) {
147 return ss.print(os);
148}
149
150} // namespace
151#endif // FSTSEARCHSEQSTEP_H ///:~
Abstract class, defines interface for implementations of one selection step in sequential search type...
Definition seq_step.hpp:97
virtual std::ostream & print(std::ostream &os) const
writes a human-readable identification of the step and its configuration; base default writes nothing
Definition seq_step.hpp:129
std::shared_ptr< SUBSET > PSubset
shared pointer to a feature subset
Definition seq_step.hpp:102
OutputDetail _detail
the output detail level set via set_output_detail(); read by output_normal()/output_detailed()
Definition seq_step.hpp:141
bool output_normal() const
true unless output detail is SILENT
Definition seq_step.hpp:137
std::shared_ptr< Result_Tracker< RETURNTYPE, SUBSET > > PResultTracker
shared pointer to the result tracker enabled via enable_result_tracking()
Definition seq_step.hpp:103
void disable_result_tracking()
detaches any result tracker (result_tracker_active() then returns false)
Definition seq_step.hpp:132
PResultTracker _tracker
the assigned result tracker, or null (see enable_result_tracking()/result_tracker_active())
Definition seq_step.hpp:140
std::shared_ptr< CRITERION > PCriterion
shared pointer to the criterion this step evaluates candidates against
Definition seq_step.hpp:101
bool output_detailed() const
true only at the DETAILED output level
Definition seq_step.hpp:138
bool result_tracker_active() const
true if a result tracker was assigned via enable_result_tracking() and not since disabled
Definition seq_step.hpp:133
virtual bool evaluate_candidates(RETURNTYPE &result, const PSubset sub, const PCriterion crit, const DIMTYPE _generalization_level, std::ostream &os)=0
Performs one selection step: evaluates the candidate subsets reachable from sub and leaves the best o...
void set_output_detail(OutputDetail detail)
sets the amount of information that is logged to output stream throughout the course of search
Definition seq_step.hpp:135
void enable_result_tracking(PResultTracker tracker)
assigns a result tracker to this step, i.e., enables logging of all evaluated candidate subsets for f...
Definition seq_step.hpp:131
OutputDetail get_output_detail() const
the currently configured output detail level
Definition seq_step.hpp:136
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
OutputDetail
search algorithms' output extent
Definition global.hpp:67
@ NORMAL
informs about new found solutions and time elapsed etc.
Definition global.hpp:69
@ DETAILED
includes much detail including variable contents etc. (may render output unreadably cluttered)
Definition global.hpp:70
std::ostream & operator<<(std::ostream &os, const Data_Intervaller< CONTAINER, IDXTYPE > &ia)
Streams every contained interval as "si:<startidx>, c:<count>" lines to os.
Definition data_intervaller.hpp:152
Defines interface for classes that enable collecting multiple results.
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.