Feature Selection Toolbox FST4
UTIA · Czech Academy of Sciences
Loading...
Searching...
No Matches
result_tracker.hpp
Go to the documentation of this file.
1#ifndef FSTRESULTTRACKER_H
2#define FSTRESULTTRACKER_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 <cstddef>
51#include "error.hpp"
52#include "global.hpp"
53#include "clonable.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
90template<class RETURNTYPE, class SUBSET>
91class Result_Tracker : public Clonable { // abstract class
92public:
93 typedef std::shared_ptr<SUBSET> PSubset;
94 Result_Tracker(): _detail(NORMAL) {notify("Result_Tracker constructor.");}
95 Result_Tracker(const Result_Tracker& rt): _detail(rt._detail) {notify("Result_Tracker copy-constructor.");}
96 virtual ~Result_Tracker() {}
97
99 typedef struct {
100 RETURNTYPE value;
102 } ResultRec;
104
105 virtual bool add(const RETURNTYPE value, const PSubset sub)=0;
106 virtual void clear() =0;
107 virtual std::size_t size() const =0;
108 virtual bool get_first(PResultRec &r) =0;
109 virtual bool get_next(PResultRec &r) =0;
110 virtual void join(Result_Tracker &src);
111
112 Result_Tracker* clone() const override {throw fst_error("Result_Tracker::clone() not supported, use Result_Tracker::stateless_clone() instead.");}
113 Result_Tracker* sharing_clone() const override {throw fst_error("Result_Tracker::sharing_clone() not supported, use Result_Tracker::stateless_clone() instead.");}
114 Result_Tracker* stateless_clone() const override =0;
115
116 void set_output_detail(OutputDetail detail) {_detail=detail;}
118 bool output_normal() const {return _detail==NORMAL || _detail==DETAILED;}
119 bool output_detailed() const {return _detail==DETAILED;}
120protected:
122};
123
124template<class RETURNTYPE, class SUBSET>
126{
127 PResultRec prr;
128 bool found=src.get_first(prr);
129 while(found) {
130 add(prr->value,prr->sub);
131 found=src.get_next(prr);
132 }
133}
134
135} // namespace
136#endif // FSTRESULTTRACKER_H ///:~
Abstract class, defines interface for classes that enable collecting multiple results.
Definition result_tracker.hpp:91
virtual void join(Result_Tracker &src)
adds the contents of src to this tracker, one add() per record, so this tracker's own inclusion rules...
Definition result_tracker.hpp:125
OutputDetail _detail
the output detail level set via set_output_detail(); read by output_normal()/output_detailed()
Definition result_tracker.hpp:121
Result_Tracker * clone() const override
Definition result_tracker.hpp:112
virtual void clear()=0
discards all recorded results
virtual bool add(const RETURNTYPE value, const PSubset sub)=0
records one (value, subset) result; returns false if the tracker declines to keep it (concrete tracke...
std::shared_ptr< SUBSET > PSubset
shared pointer to a tracked feature subset
Definition result_tracker.hpp:93
bool output_detailed() const
true only at the DETAILED output level
Definition result_tracker.hpp:119
bool output_normal() const
true unless output detail is SILENT
Definition result_tracker.hpp:118
virtual std::size_t size() const =0
number of results currently held (std::size_t rather than 'long': on LLP64 platforms 'long' is 32 bit...
Result_Tracker * sharing_clone() const override
Definition result_tracker.hpp:113
Result_Tracker(const Result_Tracker &rt)
copies the output-detail setting only – concrete trackers copy their own collected results separately
Definition result_tracker.hpp:95
ResultRec * PResultRec
raw pointer to a ResultRec, as used by get_first()/get_next() iteration
Definition result_tracker.hpp:103
Result_Tracker * stateless_clone() const override=0
virtual bool get_next(PResultRec &r)=0
hands out the next held result; false once the iteration is exhausted. A tracker has a single shared ...
void set_output_detail(OutputDetail detail)
sets the amount of information that is logged to output stream throughout the course of search
Definition result_tracker.hpp:116
virtual bool get_first(PResultRec &r)=0
starts an iteration over the held results, best first; false if the tracker holds nothing....
OutputDetail get_output_detail() const
the currently configured output detail level
Definition result_tracker.hpp:117
FST4 specific error passing class.
Definition error.hpp:61
Defines interface for classes that may need to get cloned.
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
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
Structure to hold [subset,criterion value] temporary solutions in the course of search.
Definition result_tracker.hpp:99
RETURNTYPE value
the criterion value of the recorded subset
Definition result_tracker.hpp:100
PSubset sub
the recorded subset itself
Definition result_tracker.hpp:101
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.