PLearn 0.1
|
#include <EarlyStoppingOracle.h>
Public Types | |
typedef OptionsOracle | inherited |
Public Member Functions | |
EarlyStoppingOracle () | |
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) |
virtual void | forget () |
SUBCLASS WRITING: Should reset the generator's internal state (as having no info about previous trials). | |
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 EarlyStoppingOracle * | deepCopy (CopiesMap &copies) const |
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 |
the name of the option to change | |
TVec< string > | values |
a list of values to try in sequence | |
Vec | range |
a numerical range of the form [ start, end ] or [ start, end, step ] | |
real | min_value |
early-stopping parameters | |
real | max_value |
maximum error beyond which we stop | |
real | max_degradation |
maximum allowed degradation in error from last best value | |
real | relative_max_degradation |
real | min_improvement |
required minimum improvement from last step | |
real | relative_min_improvement |
int | max_degraded_steps |
max. nb of steps beyond best found | |
int | min_n_steps |
min. nb of steps before early stopping | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares this class' options. | |
Protected Attributes | |
TVec< string > | option_values |
if the values option was specified, then this points to it if the range option was specified, this is an extensive list of the values implied by the range (this field is built by the build_ method). | |
int | nreturned |
number of trials returned so far (This is also the index of the next trial to be returned from options_values) | |
real | previous_objective |
real | best_objective |
int | best_step |
bool | met_early_stopping |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Definition at line 51 of file EarlyStoppingOracle.h.
Reimplemented from PLearn::OptionsOracle.
Definition at line 76 of file EarlyStoppingOracle.h.
PLearn::EarlyStoppingOracle::EarlyStoppingOracle | ( | ) |
Definition at line 51 of file EarlyStoppingOracle.cc.
: nreturned(0), previous_objective(REAL_MAX), best_objective(REAL_MAX), best_step(-1), met_early_stopping(false), min_value(-REAL_MAX), max_value(REAL_MAX), max_degradation(REAL_MAX), relative_max_degradation(-1), min_improvement(-REAL_MAX), relative_min_improvement(-1), max_degraded_steps(100), min_n_steps(0) { // build_(); }
string PLearn::EarlyStoppingOracle::_classname_ | ( | ) | [static] |
Declares name and deepCopy methods.
Reimplemented from PLearn::OptionsOracle.
Definition at line 69 of file EarlyStoppingOracle.cc.
OptionList & PLearn::EarlyStoppingOracle::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::OptionsOracle.
Definition at line 69 of file EarlyStoppingOracle.cc.
RemoteMethodMap & PLearn::EarlyStoppingOracle::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::OptionsOracle.
Definition at line 69 of file EarlyStoppingOracle.cc.
Reimplemented from PLearn::OptionsOracle.
Definition at line 69 of file EarlyStoppingOracle.cc.
Object * PLearn::EarlyStoppingOracle::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 69 of file EarlyStoppingOracle.cc.
StaticInitializer EarlyStoppingOracle::_static_initializer_ & PLearn::EarlyStoppingOracle::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::OptionsOracle.
Definition at line 69 of file EarlyStoppingOracle.cc.
void PLearn::EarlyStoppingOracle::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 157 of file EarlyStoppingOracle.cc.
References PLearn::OptionsOracle::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::EarlyStoppingOracle::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::OptionsOracle.
Definition at line 130 of file EarlyStoppingOracle.cc.
References PLearn::TVec< T >::append(), PLearn::fast_exact_is_equal(), PLearn::is_equal(), PLearn::TVec< T >::length(), option_values, PLERROR, PLWARNING, range, PLearn::TVec< T >::resize(), PLearn::tostring(), values, and x.
Referenced by build().
{ if(values.length()>0) option_values = values; else if(range.length()>=2) { option_values.resize(0); real step = 1; if(range.length()==3){ step = range[2]; if(step<0 || is_equal(step,0)) PLERROR("IN EarlyStoppingOracle::build_() - the" " step(=%f) should be greater the 0!",step); } for(real x = range[0]; x<range[1]; x+=step) option_values.append(tostring(x)); if(fast_exact_is_equal(range[0], range[1])) PLWARNING("In EarlyStoppingOracle::build_ - no range selected. " "Maybe you forgot that the end part of the range is not " "included!"); } if(option_values.length()==0) PLWARNING("In EarlyStoppingOracle::build_ - no range selected."); }
string PLearn::EarlyStoppingOracle::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 69 of file EarlyStoppingOracle.cc.
void PLearn::EarlyStoppingOracle::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::OptionsOracle.
Definition at line 71 of file EarlyStoppingOracle.cc.
References best_objective, best_step, PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::OptionsOracle::declareOptions(), PLearn::OptionBase::learntoption, max_degradation, max_degraded_steps, max_value, met_early_stopping, min_improvement, min_n_steps, min_value, nreturned, option, range, relative_max_degradation, relative_min_improvement, and values.
{ declareOption(ol, "option", &EarlyStoppingOracle::option, OptionBase::buildoption, "the name of the option to change"); declareOption(ol, "values", &EarlyStoppingOracle::values, OptionBase::buildoption, "a list of values to try in sequence "); declareOption(ol, "range", &EarlyStoppingOracle::range, OptionBase::buildoption, "a numerical range of the form [ start, end ] or [ start, end, step ]\n" "WARNING: end is not included!"); declareOption(ol, "min_value", &EarlyStoppingOracle::min_value, OptionBase::buildoption, "minimum allowed error beyond which we stop\n"); declareOption(ol, "max_value", &EarlyStoppingOracle::max_value, OptionBase::buildoption, "maximum allowed error beyond which we stop\n"); declareOption(ol, "max_degradation", &EarlyStoppingOracle::max_degradation, OptionBase::buildoption, "maximum allowed degradation from last best objective value\n"); declareOption(ol, "relative_max_degradation", &EarlyStoppingOracle::relative_max_degradation, OptionBase::buildoption, "maximum allowed degradation from last best objective, relative to abs(best_objective)\n" "ex: 0.10 will allow a degradation of 10% the magnitude of best_objective\n" "Will be ignored if negative}n"); declareOption(ol, "min_improvement", &EarlyStoppingOracle::min_improvement, OptionBase::buildoption, "minimum required improvement from previous objective value\n"); declareOption(ol, "relative_min_improvement", &EarlyStoppingOracle::relative_min_improvement, OptionBase::buildoption, "minimum required improvement from previous objective value, relative to it.\n" "ex: 0.01 means we need an improvement of 0.01*abs(previous_objective) i.e. 1%\n" "Will be ignored if negative\n"); declareOption(ol, "max_degraded_steps", &EarlyStoppingOracle::max_degraded_steps, OptionBase::buildoption, " ax. nb of steps beyond best found\n"); declareOption(ol, "min_n_steps", &EarlyStoppingOracle::min_n_steps, OptionBase::buildoption, "minimum required number of steps before allowing early stopping\n"); //learnt option declareOption(ol, "nreturned", &EarlyStoppingOracle::nreturned, OptionBase::learntoption, "The number of returned option\n"); declareOption(ol, "best_objective", &EarlyStoppingOracle::best_objective, OptionBase::learntoption, "The best objective see up to date\n"); declareOption(ol, "best_step", &EarlyStoppingOracle::best_step, OptionBase::learntoption, "The step where we have see the best objective\n"); declareOption(ol, "met_early_stopping", &EarlyStoppingOracle::met_early_stopping, OptionBase::learntoption, "True if we met the early stopping criterion\n"); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::EarlyStoppingOracle::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::OptionsOracle.
Definition at line 135 of file EarlyStoppingOracle.h.
EarlyStoppingOracle * PLearn::EarlyStoppingOracle::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::OptionsOracle.
Definition at line 69 of file EarlyStoppingOracle.cc.
void PLearn::EarlyStoppingOracle::forget | ( | ) | [virtual] |
SUBCLASS WRITING: Should reset the generator's internal state (as having no info about previous trials).
Implements PLearn::OptionsOracle.
Definition at line 258 of file EarlyStoppingOracle.cc.
References best_objective, best_step, met_early_stopping, nreturned, and previous_objective.
{ nreturned = 0; previous_objective = FLT_MAX; best_objective = FLT_MAX; best_step = -1; met_early_stopping = false; }
TVec< string > PLearn::EarlyStoppingOracle::generateNextTrial | ( | const TVec< string > & | older_trial, |
real | obtained_objective | ||
) | [virtual] |
SUBCLASS WRITING: This notifies the oracle, of the result obtained for a previous trial it suggested. The oracle is expected to return the next suggestion, or an empty vector if stopping conditions were met, or it run out of suggestions. An empty vector may be passed for older_trial if there is no result to report.
Implements PLearn::OptionsOracle.
Definition at line 166 of file EarlyStoppingOracle.cc.
References PLearn::abs(), best_objective, best_step, PLearn::endl(), PLearn::TVec< T >::length(), max_degradation, max_degraded_steps, max_value, met_early_stopping, min_improvement, min_n_steps, min_value, nreturned, option_values, previous_objective, relative_max_degradation, and relative_min_improvement.
{ if(met_early_stopping) return TVec<string>(); if(older_trial.length()>0) { real current_objective = obtained_objective; int current_step = nreturned; if(current_objective<best_objective && current_step >= min_n_steps) { best_objective = current_objective; best_step = current_step; } real improvement = previous_objective-current_objective; real degradation = current_objective-best_objective; int n_degraded_steps = current_step-best_step; // Check if early-stopping condition was met if (( (current_objective < min_value) || (current_objective > max_value) || (n_degraded_steps >= max_degraded_steps) || (degradation > max_degradation) || (relative_max_degradation>=0 && degradation > relative_max_degradation * abs(best_objective)) || (improvement < min_improvement) || (relative_min_improvement>=0 && improvement < relative_min_improvement * abs(previous_objective)) ) && current_step >= min_n_steps){ met_early_stopping = true; //print debug info if(current_objective < min_value){ DBG_MODULE_LOG <<"stopping the learner as: current_objective " <<current_objective <<" < min_value "<<min_value <<endl; } if(current_objective > max_value){ DBG_MODULE_LOG <<"stopping the learner as: current_objective ("<<current_objective <<") < max_value ("<<max_value<<")"<<endl; } if(n_degraded_steps >= max_degraded_steps){ DBG_MODULE_LOG <<"stopping the learner as:n_degraded_steps("<< n_degraded_steps<<") >= max_degraded_steps("<< max_degraded_steps<<") " <<endl; } if(degradation > max_degradation){ DBG_MODULE_LOG <<"stopping the learner as: degradation("<<degradation <<") > max_degradation("<<max_degradation<<")" <<endl; } if(relative_max_degradation>=0 && degradation > relative_max_degradation * abs(best_objective)){ DBG_MODULE_LOG <<"stopping the learner as: relative_max_degradation>=0 " <<"&& degradation("<<degradation <<") > relative_max_degradation("<<relative_max_degradation <<") * abs(best_objective)("<<best_objective<<")" <<endl; } if(improvement < min_improvement){ DBG_MODULE_LOG <<"stopping the learner as: improvement("<<improvement<<") < min_improvement(" <<min_improvement<<")" <<endl; } if(relative_min_improvement>=0 && improvement < relative_min_improvement * abs(previous_objective)){ DBG_MODULE_LOG <<"stopping the learner as: relative_min_improvement("<<relative_min_improvement<<")>=0 " <<endl <<"&& improvement("<<improvement<<") < relative_min_improvement("<<relative_min_improvement<<") * abs(previous_objective"<<previous_objective<<")" <<endl; } } previous_objective = current_objective; } if(met_early_stopping || nreturned >= option_values.length()) return TVec<string>(); else return TVec<string>(1, option_values[nreturned++]); }
OptionList & PLearn::EarlyStoppingOracle::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 69 of file EarlyStoppingOracle.cc.
OptionMap & PLearn::EarlyStoppingOracle::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 69 of file EarlyStoppingOracle.cc.
TVec< string > PLearn::EarlyStoppingOracle::getOptionNames | ( | ) | const [virtual] |
returns the set of names of options this generator generates
Implements PLearn::OptionsOracle.
Definition at line 163 of file EarlyStoppingOracle.cc.
References option.
{ return TVec<string>(1,option); }
RemoteMethodMap & PLearn::EarlyStoppingOracle::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 69 of file EarlyStoppingOracle.cc.
void PLearn::EarlyStoppingOracle::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::OptionsOracle.
Definition at line 268 of file EarlyStoppingOracle.cc.
References PLearn::deepCopyField(), PLearn::OptionsOracle::makeDeepCopyFromShallowCopy(), option_values, range, and values.
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(option_values, copies); deepCopyField(values, copies); deepCopyField(range, copies); }
Reimplemented from PLearn::OptionsOracle.
Definition at line 135 of file EarlyStoppingOracle.h.
real PLearn::EarlyStoppingOracle::best_objective [protected] |
Definition at line 69 of file EarlyStoppingOracle.h.
Referenced by declareOptions(), forget(), and generateNextTrial().
int PLearn::EarlyStoppingOracle::best_step [protected] |
Definition at line 70 of file EarlyStoppingOracle.h.
Referenced by declareOptions(), forget(), and generateNextTrial().
maximum allowed degradation in error from last best value
Definition at line 89 of file EarlyStoppingOracle.h.
Referenced by declareOptions(), and generateNextTrial().
max. nb of steps beyond best found
Definition at line 93 of file EarlyStoppingOracle.h.
Referenced by declareOptions(), and generateNextTrial().
maximum error beyond which we stop
Definition at line 88 of file EarlyStoppingOracle.h.
Referenced by declareOptions(), and generateNextTrial().
bool PLearn::EarlyStoppingOracle::met_early_stopping [protected] |
Definition at line 72 of file EarlyStoppingOracle.h.
Referenced by declareOptions(), forget(), and generateNextTrial().
required minimum improvement from last step
Definition at line 91 of file EarlyStoppingOracle.h.
Referenced by declareOptions(), and generateNextTrial().
min. nb of steps before early stopping
Definition at line 94 of file EarlyStoppingOracle.h.
Referenced by declareOptions(), and generateNextTrial().
early-stopping parameters
minimum error beyond which we stop
Definition at line 87 of file EarlyStoppingOracle.h.
Referenced by declareOptions(), and generateNextTrial().
int PLearn::EarlyStoppingOracle::nreturned [protected] |
number of trials returned so far (This is also the index of the next trial to be returned from options_values)
Definition at line 65 of file EarlyStoppingOracle.h.
Referenced by declareOptions(), forget(), and generateNextTrial().
the name of the option to change
Definition at line 82 of file EarlyStoppingOracle.h.
Referenced by declareOptions(), and getOptionNames().
TVec<string> PLearn::EarlyStoppingOracle::option_values [protected] |
if the values option was specified, then this points to it if the range option was specified, this is an extensive list of the values implied by the range (this field is built by the build_ method).
Definition at line 61 of file EarlyStoppingOracle.h.
Referenced by build_(), generateNextTrial(), and makeDeepCopyFromShallowCopy().
real PLearn::EarlyStoppingOracle::previous_objective [protected] |
Definition at line 68 of file EarlyStoppingOracle.h.
Referenced by forget(), and generateNextTrial().
a numerical range of the form [ start, end ] or [ start, end, step ]
Definition at line 84 of file EarlyStoppingOracle.h.
Referenced by build_(), declareOptions(), and makeDeepCopyFromShallowCopy().
Definition at line 90 of file EarlyStoppingOracle.h.
Referenced by declareOptions(), and generateNextTrial().
Definition at line 92 of file EarlyStoppingOracle.h.
Referenced by declareOptions(), and generateNextTrial().
a list of values to try in sequence
Definition at line 83 of file EarlyStoppingOracle.h.
Referenced by build_(), declareOptions(), and makeDeepCopyFromShallowCopy().