1#ifndef FSTSEARCHBRANCHANDBOUNDBASIC_H
2#define FSTSEARCHBRANCHANDBOUNDBASIC_H
101template<
class RETURNTYPE,
typename DIMTYPE,
class SUBSET,
class CRITERION>
117 virtual std::ostream&
print(std::ostream& os)
const override {
119 else os <<
"Basic Branch & Bound (BBB) [Search_Branch_And_Bound_Basic()]";
131template<
class RETURNTYPE,
typename DIMTYPE,
class SUBSET,
class CRITERION>
140 avail->
type=parent::UNKNOWN;
144template<
class RETURNTYPE,
typename DIMTYPE,
class SUBSET,
class CRITERION>
160 std::vector<PNode> submitted;
162 if(nod->
type!=parent::COMPUTED) submitted.push_back(nod);
163 if(submitted.empty())
return;
166 typename parent::EVALUATORENGINE::ResultCallback on_result=[&submitted,&done](
const RETURNTYPE value,
const PSubset&,
const DIMTYPE feat) {
167 PNode node=submitted[done++];
168 assert(node->
feature==feat); (void)feat;
170 node->
type=parent::COMPUTED;
173 for(
PNode snod : submitted)
175 assert(currentset->selected_raw(snod->feature));
176 currentset->deselect_raw(snod->feature);
178 currentset->select_raw(snod->feature);
184template<
class RETURNTYPE,
typename DIMTYPE,
class SUBSET,
class CRITERION>
190 if(currentnode.
type!=parent::COMPUTED) {
194 assert(currentset->selected_raw(currentnode.
feature));
195 currentset->deselect_raw(currentnode.
feature);
197 currentset->select_raw(currentnode.
feature);
198 currentnode.
type=parent::COMPUTED;
Implements Branch and Bound Basic method, i.e., with randomized node ordering.
Definition search_branch_and_bound_basic.hpp:102
parent::PSubset PSubset
shared pointer to a feature subset
Definition search_branch_and_bound_basic.hpp:106
parent::Node Node
search-tree node record (feature, value, type, valid), see Search_Branch_And_Bound
Definition search_branch_and_bound_basic.hpp:108
parent::PNode PNode
pointer to a search-tree Node, see Search_Branch_And_Bound
Definition search_branch_and_bound_basic.hpp:107
virtual void pre_evaluate_availables() override
BBB does not order the tree by any estimate of feature importance: every available feature gets a ran...
Definition search_branch_and_bound_basic.hpp:132
parent::NodeType NodeType
UNKNOWN/RANDOM/PREDICTED/COMPUTED node-value provenance, see Search_Branch_And_Bound.
Definition search_branch_and_bound_basic.hpp:109
Search_Branch_And_Bound_Basic(PEvaluatorEngine engine=PEvaluatorEngine())
engine forwarded to Search_Branch_And_Bound; defaults to sequential in-line evaluation if not supplie...
Definition search_branch_and_bound_basic.hpp:111
Search_Branch_And_Bound< RETURNTYPE, DIMTYPE, SUBSET, CRITERION > parent
base class alias
Definition search_branch_and_bound_basic.hpp:104
virtual void initialize(const DIMTYPE d, const DIMTYPE n, const PCriterion crit) override
BBB keeps no structures of its own beyond the base class's tree, so there is nothing to set up.
Definition search_branch_and_bound_basic.hpp:125
virtual std::ostream & print(std::ostream &os) const override
writes the method's name and, with a threaded engine, the number of worker threads
Definition search_branch_and_bound_basic.hpp:117
parent::PCriterion PCriterion
shared pointer to the criterion the search optimizes
Definition search_branch_and_bound_basic.hpp:105
virtual bool cut_possible() override
computes the current node's criterion value if it is not known yet and reports whether the node's val...
Definition search_branch_and_bound_basic.hpp:185
parent::PEvaluatorEngine PEvaluatorEngine
shared pointer to the injected evaluation-strategy engine
Definition search_branch_and_bound_basic.hpp:110
virtual void post_process_tree_level() override
the ordering values above are random, not criterion values, so every node chosen for the new level st...
Definition search_branch_and_bound_basic.hpp:145
PSubset & get_currentset()
mutable accessor for _currentset, for use by descendant B&B variants' hooks
Definition search_branch_and_bound.hpp:198
Node * PNode
pointer to a Node, as used by the getFirst.../getNext... accessors below
Definition search_branch_and_bound.hpp:142
bool getFirstNode(PNode &nod)
begins forward iteration (ascending by value, from _tree[k].begin()) over the current level's not-yet...
Definition search_branch_and_bound.hpp:190
PCriterion const & get_criterion() const
accessor for _criterion, for use by descendant B&B variants' hooks
Definition search_branch_and_bound.hpp:180
Search_Branch_And_Bound(PEvaluatorEngine engine=PEvaluatorEngine())
Constructs the search, optionally injecting a candidate-evaluation engine.
Definition search_branch_and_bound.hpp:121
DIMTYPE n
no. of all features
Definition search_branch_and_bound.hpp:176
Node & get_current_node()
the node at the current level k presently being visited (_tree[k].back()), i.e. about to be tested fo...
Definition search_branch_and_bound.hpp:200
PEvaluatorEngine const & get_engine() const
accessor for the injected evaluation strategy (sequential-inline or thread-pooled),...
Definition search_branch_and_bound.hpp:181
bool getFirstAvailable(PNode &avail)
begins iteration over _available in feature-index order, skipping withdrawn (invalid) entries,...
Definition search_branch_and_bound.hpp:193
bool getNextNode(PNode &nod)
advances the getFirstNode() iteration; returns false once the level's end is reached
Definition search_branch_and_bound.hpp:191
DIMTYPE d
no. of features to be selected
Definition search_branch_and_bound.hpp:177
std::shared_ptr< EVALUATORENGINE > PEvaluatorEngine
shared pointer to an EVALUATORENGINE, as accepted by the constructor and returned by get_engine()
Definition search_branch_and_bound.hpp:115
bool is_bound_valid() const
true once a valid bound has been established, see _boundvalid
Definition search_branch_and_bound.hpp:184
std::shared_ptr< SUBSET > PSubset
shared pointer to a feature subset
Definition search_branch_and_bound.hpp:113
bool getNextAvailable(PNode &avail)
advances the getFirstAvailable() iteration, again skipping invalid entries; returns false once exhaus...
Definition search_branch_and_bound.hpp:194
std::shared_ptr< CRITERION > PCriterion
shared pointer to the criterion under optimization
Definition search_branch_and_bound.hpp:112
NodeType
Marks how a Node's value was obtained: UNKNOWN = not yet assigned; RANDOM = reserved but currently un...
Definition search_branch_and_bound.hpp:134
DIMTYPE get_n() const
total number of features, see n
Definition search_branch_and_bound.hpp:187
RETURNTYPE get_bound_value() const
the current best (bound) criterion value; meaningful only once is_bound_valid()
Definition search_branch_and_bound.hpp:183
FST4 specific error passing class.
Definition error.hpp:61
FST4 specific error passing class.
FST4-owned pseudo-random number generator (UCRT-compatible LCG), replacing platform-specific std::ran...
The Feature Selection Toolbox 4 library: every library component – data access, criteria and classifi...
Definition data_accessor.hpp:80
int fst_rand()
Returns the next pseudo-random draw in 0..FST_RAND_MAX; use instead of std::rand().
Definition fst_rand.hpp:93
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
Defines interface for classes that enable collecting multiple results.
Implements Branch and Bound template method as basis for more advanced B&B implementations.
Structure representing search tree node.
Definition search_branch_and_bound.hpp:136
RETURNTYPE value
the node's criterion value: exact once type==COMPUTED, an ordering estimate while type==PREDICTED,...
Definition search_branch_and_bound.hpp:138
DIMTYPE feature
the feature index this node represents removing from its ancestor set (meaningless in the single root...
Definition search_branch_and_bound.hpp:137
NodeType type
how value was obtained, see NodeType
Definition search_branch_and_bound.hpp:139