1#ifndef FSTSEARCHSEQDOS_H
2#define FSTSEARCHSEQDOS_H
96template<
class RETURNTYPE,
typename DIMTYPE,
class SUBSET,
class CRITERION,
class EVALUATOR>
109 virtual bool search(
const DIMTYPE target_d, RETURNTYPE &result,
const PSubset sub,
const PCriterion crit, std::ostream& os=std::cout)
override;
114 virtual std::ostream&
print(std::ostream& os)
const override;
143template<
class RETURNTYPE,
typename DIMTYPE,
class SUBSET,
class CRITERION,
class EVALUATOR>
149 os <<
", delta=" <<
_delta;
150 os <<
" [Search_DOS()";
157template<
class RETURNTYPE,
typename DIMTYPE,
class SUBSET,
class CRITERION,
class EVALUATOR>
165 assert(sub->get_n()>0);
174 sos <<
"---------------------------------------" << std::endl;
175 sos <<
"Starting " << *
this << std::endl;
176 sos <<
"with Criterion: " << *crit << std::endl;
177 sos <<
"with initial subset: " << *sub << std::endl;
178 sos <<
"Subset size to be optimized." << std::endl << std::endl << std::flush;
182 DIMTYPE _n=sub->get_n();
192 sub->set_forward_mode(
true);
193 if(sub->get_d()==0) {
194 if(!
parent::Step(
true, result, sub, crit, os))
return false;
200 if(!crit->evaluate(result,sub))
return false;
206 DIMTYPE _d=sub->get_d();
209 bool pivot_top_avail=
false;
210 bool pivot_bottom_avail=
false;
221 while(_cur_delta<=
_delta) {
222 label:
switch(swing) {
224 assert(_d==sub->get_d());
226 pivotsub->stateless_copy(*sub); pivotval=result;
227 pivot_top_avail=pivot_bottom_avail=
false;
232 assert(_d==sub->get_d());
235 assert(_d==sub->get_d());
236 assert(_d <= _d_piv);
237 assert(sub->get_d()!=0);
241 assert(_d==sub->get_d());
244 _d=sub->get_d(); swinged=
true;
245 if(result>pivotval || (result==pivotval && _d<_d_piv)) {swing=RESTART;
goto label;}
248 assert(_d==sub->get_d());
250 pivot_bottom_avail=
true;
255 pivot_bottom_avail=
false;
258 assert(_d==sub->get_d());
261 assert(_d==sub->get_d());
264 assert(_d==sub->get_d());
268 if(result>pivotval || (result==pivotval && _d<_d_piv)) {swing=RESTART;
goto label;}
273 swing=UP; swinged=
false;
274 assert(_d==sub->get_d());
277 assert(_d==sub->get_d());
278 assert(_d >= _d_piv);
279 if(pivot_top_avail) {assert(
pivot_top->get_d()!=0); sub->stateless_copy(*
pivot_top); _d=sub->get_d();}
282 assert(_d==sub->get_d());
285 _d=sub->get_d(); swinged=
true;
286 if(result>pivotval || (result==pivotval && _d<_d_piv)) {swing=RESTART;
goto label;}
289 assert(_d==sub->get_d());
291 pivot_top_avail=
true;
296 pivot_top_avail=
false;
300 assert(_d==sub->get_d());
303 assert(_d==sub->get_d());
306 assert(_d==sub->get_d());
310 if(result>pivotval || (result==pivotval && _d<_d_piv)) {swing=RESTART;
goto label;}
315 swing=DOWN; swinged=
false;
317 assert(_d==sub->get_d());
327 sos <<
"......................................." << std::endl;
328 sos <<
"Search_DOS() search finished. " << swatch << std::endl;
329 sos <<
"Search result: "<< std::endl << *sub << std::endl <<
"Criterion value: " << result << std::endl << std::endl << std::flush;
Implements Dynamic_Oscillating_Search.
Definition search_seq_dos.hpp:97
void set_delta(const DIMTYPE delta)
oscillating cycle depth
Definition search_seq_dos.hpp:111
DIMTYPE get_delta() const
the currently configured oscillating cycle depth (see set_delta())
Definition search_seq_dos.hpp:112
Search_Sequential< RETURNTYPE, DIMTYPE, SUBSET, CRITERION, EVALUATOR > parent
base class alias
Definition search_seq_dos.hpp:99
parent::parent grandparent
the shared Search base (output detail, result tracker)
Definition search_seq_dos.hpp:100
DIMTYPE _delta
current oscillating cycle depth (max swing extent); see set_delta()
Definition search_seq_dos.hpp:136
Search_DOS(const PEvaluator evaluator)
evaluator must be non-null; initial_subset_enabled() is turned ON by construction (empty initial subs...
Definition search_seq_dos.hpp:104
std::shared_ptr< CRITERION > PCriterion
shared pointer to the criterion the search optimizes
Definition search_seq_dos.hpp:102
std::unique_ptr< SUBSET > pivot_top
the subset the last UP swing ended on; when the cycle depth grows, the next UP swing resumes from her...
Definition search_seq_dos.hpp:139
std::unique_ptr< SUBSET > pivot_bottom
the subset the last DOWN swing ended on, used the same way to resume a deeper DOWN swing without repe...
Definition search_seq_dos.hpp:140
std::shared_ptr< SUBSET > PSubset
shared pointer to a feature subset
Definition search_seq_dos.hpp:103
std::shared_ptr< EVALUATOR > PEvaluator
shared pointer to the sequential-step evaluator
Definition search_seq_dos.hpp:101
virtual bool search(const DIMTYPE target_d, RETURNTYPE &result, const PSubset sub, const PCriterion crit, std::ostream &os=std::cout) override
returns found subset + criterion value
Definition search_seq_dos.hpp:158
std::unique_ptr< SUBSET > pivotsub
the current pivot: the best-known subset (highest criterion value, smallest cardinality among equals)...
Definition search_seq_dos.hpp:138
virtual std::ostream & print(std::ostream &os) const override
writes a human-readable identification of the search and its configuration; base default writes nothi...
Definition search_seq_dos.hpp:144
SwingPhase
Oscillating-cycle phase for the DOS swing state machine driving search()'s inline switch.
Definition search_seq_dos.hpp:129
Search< RETURNTYPE, DIMTYPE, SUBSET, CRITERION > parent
base class alias
Definition search_seq.hpp:107
Search_Sequential(const PEvaluator evaluator)
evaluator must be non-null
Definition search_seq.hpp:111
bool Step(const bool forward, RETURNTYPE &result, const PSubset sub, const PCriterion crit, std::ostream &os=std::cout)
Performs one sequential step: adds (forward) or removes (!forward) the best g-tuple of features,...
Definition search_seq.hpp:146
PEvaluator _evaluator
the sequential-step evaluator injected at construction; drives Step()'s candidate generation and best...
Definition search_seq.hpp:139
void enable_initial_subset()
makes search() start from the caller-supplied contents of its sub argument instead of the concrete me...
Definition search_seq.hpp:134
bool initial_subset_enabled() const
true if enable_initial_subset() was called (and not since disabled by disable_initial_subset())
Definition search_seq.hpp:136
DIMTYPE get_generalization_level() const
the currently configured generalization level (see set_generalization_level())
Definition search_seq.hpp:131
bool output_normal() const
true unless output detail is SILENT
Definition search.hpp:159
void report(std::ostream &os, const msgbuf &m) const
delivers one pre-formatted progress message: to the observer if attached, otherwise as syncout text t...
Definition search.hpp:170
bool result_tracker_active() const
true if a result tracker was assigned via enable_result_tracking() and not since disabled
Definition search.hpp:155
OutputDetail get_output_detail() const
the currently configured output detail level
Definition search.hpp:158
PResultTracker _tracker
the assigned result tracker, or null (see enable_result_tracking()/result_tracker_active())
Definition search.hpp:179
void report_solution(std::ostream &os, const RETURNTYPE value, const SUBSET &sub, const msgbuf &m) const
like report(), for sites announcing a new (sub-)solution; fires on_solution instead
Definition search.hpp:175
bool output_detailed() const
true only at the DETAILED output level
Definition search.hpp:160
Simple stopwatch to measure run time of search algorithms.
Definition stopwatch.hpp:92
FST4 specific error passing class.
Definition error.hpp:61
Message accumulator for Search::report() - collects one progress message exactly as an std::ostringst...
Definition search.hpp:87
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
Defines interface for sequential search method implementations.
Simple tool to measure run time.