Feature Selection Toolbox FST4
UTIA · Czech Academy of Sciences
Loading...
Searching...
No Matches
candidate_evaluator.hpp
Go to the documentation of this file.
1#ifndef FSTCANDIDATEEVALUATOR_H
2#define FSTCANDIDATEEVALUATOR_H
3 /*
22=========================================================================
23Copyright and license:
24 * FST4 software (with the exception of any bundled or externally linked
25 third-party components) is Copyright (C) 2000-present Institute of
26 Information Theory and Automation of the Czech Academy of Sciences (UTIA).
27 * FST4 is free software: you can redistribute it and/or modify it under
28 the terms of the GNU Affero General Public License as published by the
29 Free Software Foundation, version 3. The full text of the license is in
30 the file LICENSE in the distribution root and at
31 https://www.gnu.org/licenses/agpl-3.0.html.
32 * FST4 is distributed in the hope that it will be useful, but WITHOUT ANY
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or
34 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
35 License for more details.
36 * Closed-source use without the AGPL's copyleft obligations requires a
37 commercial license from UTIA; in case of interest write to
38 utia@utia.cas.cz. LICENSING.md in the distribution root explains both
39 options, the contributor license agreement that every contribution
40 requires, and the contacts (technical questions and pull requests:
41 somol@utia.cas.cz, with "FST" in the subject line).
42========================================================================== */
43
44#include <memory>
45#include <functional>
46#include <iostream>
47#include "error.hpp"
48#include "global.hpp"
49#include "result_tracker.hpp"
50
51namespace FST {
52
85template<class RETURNTYPE, typename DIMTYPE, class SUBSET, class CRITERION>
87public:
88 typedef std::shared_ptr<CRITERION> PCriterion;
89 typedef std::shared_ptr<SUBSET> PSubset;
90 typedef std::shared_ptr<Result_Tracker<RETURNTYPE,SUBSET> > PResultTracker;
92 typedef std::function<bool(SUBSET&)> Generator;
94 typedef std::function<void(const RETURNTYPE, const PSubset&, const DIMTYPE)> ResultCallback;
97 typedef std::function<void(const int, const unsigned long long, const RETURNTYPE, const PSubset&)> BestCallback;
99 typedef std::function<bool(const RETURNTYPE, const PSubset&, const RETURNTYPE, const PSubset&)> BetterPredicate;
100
101 virtual ~Candidate_Evaluator() {}
102
103 virtual unsigned int get_max_threads() const =0;
104 virtual bool is_threaded() const =0;
105
106 // batch mode
107 // NOTE: crit is expected to be already initialize()d before use here
108 virtual void initialize(const PCriterion &crit, const DIMTYPE max_candidates, ResultCallback on_result=ResultCallback()) =0;
109 virtual bool add_candidate(const PSubset &sub, const DIMTYPE feature=0) =0;
110 virtual bool collect() =0;
111 virtual bool getBestResult(RETURNTYPE &result, PSubset &sub, DIMTYPE &feature) =0;
112
113 // streaming mode
114 // NOTE: crit is expected to be already initialize()d before use here
124 virtual bool evaluate_stream(Generator generator, const PCriterion &crit, const PResultTracker tracker, BetterPredicate better, BestCallback on_best, RETURNTYPE &result, const PSubset bestsub) =0;
125
126 virtual std::ostream& print(std::ostream& os) const {return os;}
127
141 virtual void invalidate_clones() {}
142};
143
145template<class RETURNTYPE, typename DIMTYPE, class SUBSET, class CRITERION>
146inline std::ostream& operator<<(std::ostream& os, const Candidate_Evaluator<RETURNTYPE,DIMTYPE,SUBSET,CRITERION>& ce) {
147 return ce.print(os);
148}
149
150} // namespace
151#endif // FSTCANDIDATEEVALUATOR_H ///:~
Abstract candidate-evaluation strategy (sequential-inline vs. thread-pooled).
Definition candidate_evaluator.hpp:86
virtual bool collect()=0
completes the batch (threaded: waits for the workers, fires the pending per-result callbacks in add-o...
std::function< void(const RETURNTYPE, const PSubset &, const DIMTYPE)> ResultCallback
fired once per evaluated batch candidate: (criterion value, candidate, feature tag as passed to add_c...
Definition candidate_evaluator.hpp:94
virtual unsigned int get_max_threads() const =0
1 in the sequential implementation
std::shared_ptr< Result_Tracker< RETURNTYPE, SUBSET > > PResultTracker
Definition candidate_evaluator.hpp:90
virtual std::ostream & print(std::ostream &os) const
writes a human-readable identification of the engine; base default writes nothing
Definition candidate_evaluator.hpp:126
std::function< bool(SUBSET &)> Generator
fills sub with the next candidate, returns false when no candidate remains (in the threaded implement...
Definition candidate_evaluator.hpp:92
std::shared_ptr< CRITERION > PCriterion
shared pointer to the criterion this engine evaluates candidates against
Definition candidate_evaluator.hpp:88
virtual void invalidate_clones()
Drops any cached per-worker criterion clones, so that the next batch or stream re-clones from the cri...
Definition candidate_evaluator.hpp:141
std::function< bool(const RETURNTYPE, const PSubset &, const RETURNTYPE, const PSubset &)> BetterPredicate
returns true if (value,subset) is better than (best value,best subset) - encodes per-search tie-break...
Definition candidate_evaluator.hpp:99
virtual bool evaluate_stream(Generator generator, const PCriterion &crit, const PResultTracker tracker, BetterPredicate better, BestCallback on_best, RETURNTYPE &result, const PSubset bestsub)=0
Evaluates candidates produced by generator until it reports exhaustion, keeping the best one.
virtual bool add_candidate(const PSubset &sub, const DIMTYPE feature=0)=0
adds one candidate to the current batch; sub is copied, feature is an opaque tag handed back by the c...
std::function< void(const int, const unsigned long long, const RETURNTYPE, const PSubset &)> BestCallback
Definition candidate_evaluator.hpp:97
virtual bool getBestResult(RETURNTYPE &result, PSubset &sub, DIMTYPE &feature)=0
completes the batch first, then hands out its best candidate (sub is set to the engine's own subset o...
std::shared_ptr< SUBSET > PSubset
shared pointer to a candidate feature subset
Definition candidate_evaluator.hpp:89
virtual void initialize(const PCriterion &crit, const DIMTYPE max_candidates, ResultCallback on_result=ResultCallback())=0
starts a new batch; max_candidates must bound the number of add_candidate() calls to follow
virtual bool is_threaded() const =0
true for the threaded engine (any --threads value), false for the sequential one – distinguishes the ...
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
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.