1#ifndef FSTCANDIDATEEVALUATORSEQUENTIAL_H
2#define FSTCANDIDATEEVALUATORSEQUENTIAL_H
61template<
class RETURNTYPE,
typename DIMTYPE,
class SUBSET,
class CRITERION>
62class Candidate_Evaluator_Sequential :
public Candidate_Evaluator<RETURNTYPE,DIMTYPE,SUBSET,CRITERION> {
94 if(!
_crit->evaluate(val,sub)) {
_failed=
true;
return false;}
125 assert(bestsub->get_n()>0);
126 PSubset tmp_sub(
new SUBSET(bestsub->get_n()));
128 bool best_available=
false;
129 unsigned long long ordinal=0;
130 while(generator(*tmp_sub)) {
131 if(!crit->evaluate(val,tmp_sub))
return false;
132 if(tracker) tracker->add(val,tmp_sub);
133 if(!best_available || better(val,tmp_sub,result,bestsub)) {
135 bestsub->stateless_copy(*tmp_sub);
137 if(on_best) on_best(-1,ordinal,val,tmp_sub);
141 return best_available;
144 virtual std::ostream&
print(std::ostream& os)
const override {os <<
"Candidate_Evaluator_Sequential()";
return os;}
Abstract candidate-evaluation strategy: the seam through which one search algorithm body evaluates ca...
Implements sequential in-line evaluation of a criterion on a set of subset candidates.
Definition candidate_evaluator_sequential.hpp:62
virtual void initialize(const PCriterion &crit, const DIMTYPE max_candidates, ResultCallback on_result=ResultCallback()) override
starts a new batch; max_candidates must bound the number of add_candidate() calls to follow
Definition candidate_evaluator_sequential.hpp:79
DIMTYPE _bestfeature
the feature tag passed to add_candidate() for _bestsub
Definition candidate_evaluator_sequential.hpp:152
virtual unsigned int get_max_threads() const override
1 in the sequential implementation
Definition candidate_evaluator_sequential.hpp:76
PCriterion _crit
the criterion supplied to initialize(), evaluated in-line by add_candidate()
Definition candidate_evaluator_sequential.hpp:147
parent::BetterPredicate BetterPredicate
see Candidate_Evaluator::BetterPredicate
Definition candidate_evaluator_sequential.hpp:71
virtual bool is_threaded() const override
true for the threaded engine (any --threads value), false for the sequential one – distinguishes the ...
Definition candidate_evaluator_sequential.hpp:77
virtual bool evaluate_stream(Generator generator, const PCriterion &crit, const PResultTracker tracker, BetterPredicate better, BestCallback on_best, RETURNTYPE &result, const PSubset bestsub) override
Evaluates candidates produced by generator until it reports exhaustion, keeping the best one.
Definition candidate_evaluator_sequential.hpp:119
bool _failed
set when a criterion evaluate() call returned false; makes collect() and getBestResult() report failu...
Definition candidate_evaluator_sequential.hpp:154
parent::Generator Generator
see Candidate_Evaluator::Generator
Definition candidate_evaluator_sequential.hpp:68
DIMTYPE _evaluated
number of candidates evaluated in the current batch (collect() requires at least one)
Definition candidate_evaluator_sequential.hpp:153
parent::PSubset PSubset
shared pointer to a candidate feature subset
Definition candidate_evaluator_sequential.hpp:66
virtual std::ostream & print(std::ostream &os) const override
writes a human-readable identification of the engine; base default writes nothing
Definition candidate_evaluator_sequential.hpp:144
virtual bool collect() override
nothing is left pending in this engine (every candidate was evaluated inside add_candidate()),...
Definition candidate_evaluator_sequential.hpp:108
RETURNTYPE _bestval
criterion value of _bestsub
Definition candidate_evaluator_sequential.hpp:151
parent::ResultCallback ResultCallback
see Candidate_Evaluator::ResultCallback
Definition candidate_evaluator_sequential.hpp:69
virtual bool add_candidate(const PSubset &sub, const DIMTYPE feature=0) override
adds one candidate to the current batch; sub is copied, feature is an opaque tag handed back by the c...
Definition candidate_evaluator_sequential.hpp:89
bool _best_available
true once at least one candidate has been evaluated successfully in the current batch
Definition candidate_evaluator_sequential.hpp:150
PSubset _bestsub
the best candidate seen so far in the current batch (only the best is retained, not the whole batch)
Definition candidate_evaluator_sequential.hpp:149
virtual bool getBestResult(RETURNTYPE &result, PSubset &sub, DIMTYPE &feature) override
completes the batch first, then hands out its best candidate (sub is set to the engine's own subset o...
Definition candidate_evaluator_sequential.hpp:110
ResultCallback _on_result
the per-result callback supplied to initialize(), fired synchronously from add_candidate()
Definition candidate_evaluator_sequential.hpp:148
parent::BestCallback BestCallback
see Candidate_Evaluator::BestCallback
Definition candidate_evaluator_sequential.hpp:70
parent::PResultTracker PResultTracker
shared pointer to the result tracker fed during evaluate_stream()
Definition candidate_evaluator_sequential.hpp:67
parent::PCriterion PCriterion
shared pointer to the criterion this engine evaluates candidates against
Definition candidate_evaluator_sequential.hpp:65
Candidate_Evaluator< RETURNTYPE, DIMTYPE, SUBSET, CRITERION > parent
the abstract Candidate_Evaluator interface this class implements
Definition candidate_evaluator_sequential.hpp:64
Abstract candidate-evaluation strategy (sequential-inline vs. thread-pooled).
Definition candidate_evaluator.hpp:86
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
std::shared_ptr< Result_Tracker< RETURNTYPE, SUBSET > > PResultTracker
Definition candidate_evaluator.hpp:90
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
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
std::function< void(const int, const unsigned long long, const RETURNTYPE, const PSubset &)> BestCallback
Definition candidate_evaluator.hpp:97
std::shared_ptr< SUBSET > PSubset
shared pointer to a candidate feature subset
Definition candidate_evaluator.hpp:89
FST4 specific error passing class.
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