PLearn 0.1
|
This oracle implements a stepwise forward variable selection procedure. More...
#include <StepwiseSelectionOracle.h>
Public Member Functions | |
StepwiseSelectionOracle () | |
virtual void | build () |
Post-constructor. | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual StepwiseSelectionOracle * | deepCopy (CopiesMap &copies) const |
virtual TVec< string > | getOptionNames () const |
Returns the set of names of options this generator generates. | |
virtual TVec< string > | generateNextTrial (const TVec< string > &older_trial, real obtained_objective) |
Given the objective value returned for a previous trial, generate a new trial. | |
virtual void | forget () |
Reset the generator's internal state (as having no info about previous trials). | |
Static Public Member Functions | |
static string | _classname_ () |
Declares name and deepCopy methods. | |
static OptionList & | _getOptionList_ () |
static RemoteMethodMap & | _getRemoteMethodMap_ () |
static Object * | _new_instance_for_typemap_ () |
static bool | _isa_ (const Object *o) |
static void | _static_initialize_ () |
static const PPath & | declaringFile () |
Public Attributes | |
string | option_name |
Name of option that should contain the returned list of selected inputs (default = 'selected_inputs') | |
int | maxvars |
Maximum number of variables that should be permitted in the search. | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
void | generateNewSearchset () |
Generate a new searchset from base_selected_variables and combination_performance. | |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares this class' options. | |
Protected Attributes | |
TVec< int > | base_selected_variables |
This remembers the current BASE set of selected indexes, EXCLUDING the variable we are currently iterating upon. | |
set< string > | current_indexes_searchset |
This list contains the remaining combinations to generate for the current variable. | |
priority_queue< pair< real, string > > | combination_performance |
This remembers the performance of each combination tried in the current search set. | |
bool | last_combination |
To know that we have gone through all combinations. | |
Private Types | |
typedef OptionsOracle | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
This oracle implements a stepwise forward variable selection procedure.
It supports the interface provided by SelectInputsLearner, wherein the variables to selected are specified by a vector of normalized 'selected_inputs' ranging from 0 to n-1, where n is the maximum number of variables. (The object SelectInputsLearner is then responsible for mapping back those normalized inputs to the real inputs of the learner).
You simply specify to this oracle the maximum number of inputs that should be allowed.
The current implementation is the simplest: it adds variables one at a time. Look-ahead is not currently supported.
Definition at line 68 of file StepwiseSelectionOracle.h.
typedef OptionsOracle PLearn::StepwiseSelectionOracle::inherited [private] |
Reimplemented from PLearn::OptionsOracle.
Definition at line 70 of file StepwiseSelectionOracle.h.
PLearn::StepwiseSelectionOracle::StepwiseSelectionOracle | ( | ) |
Definition at line 49 of file StepwiseSelectionOracle.cc.
: option_name("selected_inputs"), maxvars(-1), last_combination(false) { }
string PLearn::StepwiseSelectionOracle::_classname_ | ( | ) | [static] |
Declares name and deepCopy methods.
Reimplemented from PLearn::OptionsOracle.
Definition at line 70 of file StepwiseSelectionOracle.cc.
OptionList & PLearn::StepwiseSelectionOracle::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::OptionsOracle.
Definition at line 70 of file StepwiseSelectionOracle.cc.
RemoteMethodMap & PLearn::StepwiseSelectionOracle::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::OptionsOracle.
Definition at line 70 of file StepwiseSelectionOracle.cc.
Reimplemented from PLearn::OptionsOracle.
Definition at line 70 of file StepwiseSelectionOracle.cc.
Object * PLearn::StepwiseSelectionOracle::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 70 of file StepwiseSelectionOracle.cc.
StaticInitializer StepwiseSelectionOracle::_static_initializer_ & PLearn::StepwiseSelectionOracle::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::OptionsOracle.
Definition at line 70 of file StepwiseSelectionOracle.cc.
void PLearn::StepwiseSelectionOracle::build | ( | ) | [virtual] |
Post-constructor.
The normal implementation should call simply inherited::build(), then this class's build_(). This method should be callable again at later times, after modifying some option fields to change the "architecture" of the object.
Reimplemented from PLearn::OptionsOracle.
Definition at line 147 of file StepwiseSelectionOracle.cc.
References PLearn::OptionsOracle::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::StepwiseSelectionOracle::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::OptionsOracle.
Definition at line 141 of file StepwiseSelectionOracle.cc.
References forget().
Referenced by build().
{ forget(); }
string PLearn::StepwiseSelectionOracle::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 70 of file StepwiseSelectionOracle.cc.
void PLearn::StepwiseSelectionOracle::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::OptionsOracle.
Definition at line 72 of file StepwiseSelectionOracle.cc.
References PLearn::OptionBase::buildoption, combination_performance, current_indexes_searchset, PLearn::declareOption(), PLearn::OptionsOracle::declareOptions(), PLearn::OptionBase::learntoption, maxvars, and option_name.
{ declareOption(ol, "option_name", &StepwiseSelectionOracle::option_name, OptionBase::buildoption, "Name of option that should contain the returned list of selected\n" "inputs (default = 'selected_inputs')"); declareOption(ol, "maxvars", &StepwiseSelectionOracle::maxvars, OptionBase::buildoption, "Maximum number of variables that should be permitted in the search"); declareOption(ol, "current_indexes_searchset", &StepwiseSelectionOracle:: current_indexes_searchset, OptionBase::learntoption, "Contains the remaining combinations to generate for the" " current variable."); declareOption(ol, "combination_performance", &StepwiseSelectionOracle:: combination_performance, OptionBase::learntoption, "This remembers the performance of each combination tried in the" " current search set."); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::StepwiseSelectionOracle::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::OptionsOracle.
Definition at line 113 of file StepwiseSelectionOracle.h.
:
StepwiseSelectionOracle * PLearn::StepwiseSelectionOracle::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::OptionsOracle.
Definition at line 70 of file StepwiseSelectionOracle.cc.
void PLearn::StepwiseSelectionOracle::forget | ( | ) | [virtual] |
Reset the generator's internal state (as having no info about previous trials).
Implements PLearn::OptionsOracle.
Definition at line 133 of file StepwiseSelectionOracle.cc.
References base_selected_variables, combination_performance, current_indexes_searchset, last_combination, and PLearn::TVec< T >::resize().
Referenced by build_().
{ base_selected_variables.resize(0); current_indexes_searchset.clear(); combination_performance = priority_queue< pair<real,string> >(); last_combination=false; }
void PLearn::StepwiseSelectionOracle::generateNewSearchset | ( | ) | [protected] |
Generate a new searchset from base_selected_variables and combination_performance.
Definition at line 159 of file StepwiseSelectionOracle.cc.
References base_selected_variables, PLearn::TVec< T >::begin(), combination_performance, current_indexes_searchset, PLearn::TVec< T >::end(), i, last_combination, maxvars, n, PLearn::openString(), PLASSERT, PLearn::PStream::plearn_ascii, PLearn::TVec< T >::size(), and PLearn::TVec< T >::subVec().
Referenced by generateNextTrial().
{ if (last_combination) return; // First find the best-performing combination in combination_performance // and convert the option string into a vector of ints to obtain the new // base_selected_variables if (combination_performance.size() > 0) { const pair<real,string>& min_objective = combination_performance.top(); const string& option = min_objective.second; PStream option_stream = openString(option,PStream::plearn_ascii); option_stream >> base_selected_variables; } else { // There should have been nothing computed before... PLASSERT( base_selected_variables.size() == 0); } // Second, find the remaining variables (not in base_selected_variables) TVec<int> range(0,maxvars-1,1); set<int> remaining_vars(range.begin(), range.end()); for(int i=0, n=base_selected_variables.size() ; i<n ; ++i) remaining_vars.erase(base_selected_variables[i]); // Third, make up a new current_indexes_searchset if we have not yet // reached maxvars current_indexes_searchset.clear(); combination_performance = priority_queue< pair<real,string> >(); int newsize = base_selected_variables.size() + 1; if (newsize > maxvars) { last_combination = true; return; } TVec<int> new_combination(newsize); new_combination.subVec(0, newsize-1) << base_selected_variables; for (set<int>::iterator it = remaining_vars.begin() ; it != remaining_vars.end() ; ++it) { new_combination[newsize-1] = *it; ostringstream newoption; PStream newoption_stream(&newoption, false /* don't own */); newoption_stream << new_combination; current_indexes_searchset.insert(newoption.str()); } }
TVec< string > PLearn::StepwiseSelectionOracle::generateNextTrial | ( | const TVec< string > & | older_trial, |
real | obtained_objective | ||
) | [virtual] |
Given the objective value returned for a previous trial, generate a new trial.
Implements PLearn::OptionsOracle.
Definition at line 104 of file StepwiseSelectionOracle.cc.
References combination_performance, current_indexes_searchset, generateNewSearchset(), last_combination, PLASSERT, and PLearn::TVec< T >::size().
{ if (last_combination) return TVec<string>(); else { if (older_trial.size() > 0) { PLASSERT(older_trial.size() == 1); // insert negative of objective since priority_queue computes // the maximum of its inserted elements combination_performance.push(make_pair(- obtained_objective, older_trial[0])); } if (current_indexes_searchset.empty()) generateNewSearchset(); if (last_combination) return TVec<string>(); PLASSERT(current_indexes_searchset.begin() != current_indexes_searchset.end()); string optionval = *current_indexes_searchset.begin(); current_indexes_searchset.erase(current_indexes_searchset.begin()); return TVec<string>(1,optionval); } }
OptionList & PLearn::StepwiseSelectionOracle::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 70 of file StepwiseSelectionOracle.cc.
OptionMap & PLearn::StepwiseSelectionOracle::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 70 of file StepwiseSelectionOracle.cc.
TVec< string > PLearn::StepwiseSelectionOracle::getOptionNames | ( | ) | const [virtual] |
Returns the set of names of options this generator generates.
Implements PLearn::OptionsOracle.
Definition at line 99 of file StepwiseSelectionOracle.cc.
References option_name.
{ return TVec<string>(1,option_name); }
RemoteMethodMap & PLearn::StepwiseSelectionOracle::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 70 of file StepwiseSelectionOracle.cc.
void PLearn::StepwiseSelectionOracle::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::OptionsOracle.
Definition at line 153 of file StepwiseSelectionOracle.cc.
References base_selected_variables, PLearn::deepCopyField(), and PLearn::OptionsOracle::makeDeepCopyFromShallowCopy().
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(base_selected_variables, copies); }
Reimplemented from PLearn::OptionsOracle.
Definition at line 113 of file StepwiseSelectionOracle.h.
This remembers the current BASE set of selected indexes, EXCLUDING the variable we are currently iterating upon.
Definition at line 85 of file StepwiseSelectionOracle.h.
Referenced by forget(), generateNewSearchset(), and makeDeepCopyFromShallowCopy().
priority_queue< pair<real,string> > PLearn::StepwiseSelectionOracle::combination_performance [protected] |
This remembers the performance of each combination tried in the current search set.
Definition at line 95 of file StepwiseSelectionOracle.h.
Referenced by declareOptions(), forget(), generateNewSearchset(), and generateNextTrial().
set<string> PLearn::StepwiseSelectionOracle::current_indexes_searchset [protected] |
This list contains the remaining combinations to generate for the current variable.
It consists of a set of strings of FULLY-FORMED options, starting with the current base_selected_variables and ending with each allowable index for the current variable
Definition at line 91 of file StepwiseSelectionOracle.h.
Referenced by declareOptions(), forget(), generateNewSearchset(), and generateNextTrial().
To know that we have gone through all combinations.
Definition at line 98 of file StepwiseSelectionOracle.h.
Referenced by forget(), generateNewSearchset(), and generateNextTrial().
Maximum number of variables that should be permitted in the search.
Definition at line 80 of file StepwiseSelectionOracle.h.
Referenced by declareOptions(), and generateNewSearchset().
Name of option that should contain the returned list of selected inputs (default = 'selected_inputs')
Definition at line 77 of file StepwiseSelectionOracle.h.
Referenced by declareOptions(), and getOptionNames().