#include <Optimizer.h>
Inheritance diagram for PLearn::Optimizer:
Public Member Functions | |
Optimizer (int n_updates=1, const string &file_name="", int every_iterations=1) | |
Optimizer (VarArray the_params, Var the_cost, int n_updates=1, const string &file_name="", int every_iterations=1) | |
Optimizer (VarArray the_params, Var the_cost, VarArray the_update_for_measure, int n_updates=1, const string &file_name="", int every_iterations=1) | |
virtual void | init () |
virtual void | build () |
Should call simply inherited::build(), then this class's build_(). | |
virtual void | reset () |
virtual void | setToOptimize (VarArray the_params, Var the_cost) |
virtual void | setVarArrayOption (const string &optionname, VarArray value) |
virtual void | setVarOption (const string &optionname, Var value) |
virtual void | setVMatOption (const string &optionname, VMat value) |
PLEARN_DECLARE_ABSTRACT_OBJECT (Optimizer) | |
virtual void | makeDeepCopyFromShallowCopy (map< const void *, void * > &copies) |
void | addMeasurer (Measurer &measurer) |
virtual bool | measure (int t, const Vec &costs) |
virtual real | optimize ()=0 |
sub-classes should define this, which is the main method | |
virtual bool | optimizeN (VecStatsCollector &stats_coll)=0 |
sub-classes should define this, which is the new main method | |
void | verifyGradient (real minval, real maxval, real step) |
verify gradient with uniform random initialization of parameters using step for the finite difference approximation of the gradient | |
void | verifyGradient (real step) |
verify gradient at the current value of the parameters using step for the finite difference approximation of the gradient | |
virtual void | oldwrite (ostream &out) const |
virtual void | oldread (istream &in) |
DEPRECATED For backward compatibility with old saved object. | |
virtual | ~Optimizer () |
void | computeRepartition (Vec v, int n, real mini, real maxi, Vec res, int &noutliers) |
Compute the repartition of v by splitting the interval [mini,maxi] into n intervals. | |
real | collectGradientStats (Vec gradient) |
Collect various statistics on the gradient. | |
Static Public Member Functions | |
void | computeGradient (Optimizer *opt, const Vec &gradient) |
Given an optimizer, compute the gradient of the cost function and store it in the "gradient" Vec. | |
void | computeOppositeGradient (Optimizer *opt, const Vec &gradient) |
Given an optimizer, compute the opposite of the gradient of the cost function and store it in the "gradient" Vec. | |
Public Attributes | |
VarArray | params |
Var | cost |
VarArray | proppath |
int | nupdates |
int | nstages |
number of steps to perform when calling optimizeN | |
int | stage |
current number of steps performed | |
bool | early_stop |
int | early_stop_i |
VarArray | update_for_measure |
PStream | vlog |
int | every |
if = 0 don't print or measure anything | |
Static Protected Member Functions | |
void | declareOptions (OptionList &ol) |
redefine this in subclasses: call declareOption(...) for each option, and then call inherited::declareOptions(options) ( see the declareOption function further down) | |
Protected Attributes | |
Array< Measurer * > | measurers |
string | filename |
call measure <every> <nupdates> iterations saving the results in the <filename>. | |
Private Types | |
typedef Object | inherited |
Private Member Functions | |
void | build_ () |
Private Attributes | |
Vec | temp_grad |
used to store temp stuff for gradient stats |
|
Reimplemented from PLearn::Object. Reimplemented in PLearn::AdaptGradientOptimizer, PLearn::ConjGradientOptimizer, and PLearn::GradientOptimizer. Definition at line 68 of file Optimizer.h. |
|
Definition at line 54 of file Optimizer.cc. |
|
Definition at line 59 of file Optimizer.cc. |
|
Definition at line 65 of file Optimizer.cc. |
|
Definition at line 227 of file Optimizer.cc. |
|
Definition at line 200 of file Optimizer.cc. References PLearn::TVec< Measurer * >::appendIfNotThereAlready(), and measurers. |
|
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::Object. Reimplemented in PLearn::AdaptGradientOptimizer, PLearn::ConjGradientOptimizer, and PLearn::GradientOptimizer. Definition at line 73 of file Optimizer.cc. References build_(). Referenced by init(), and makeDeepCopyFromShallowCopy(). |
|
This method should be redefined in subclasses and do the actual building of the object according to previously set option fields. Constructors can just set option fields, and then call build_. This method is NOT virtual, and will typically be called only from three places: a constructor, the public virtual build() method, and possibly the public virtual read method (which calls its parent's read). build_() can assume that it's parent's build_ has already been called. Reimplemented from PLearn::Object. Reimplemented in PLearn::AdaptGradientOptimizer, PLearn::ConjGradientOptimizer, and PLearn::GradientOptimizer. Definition at line 79 of file Optimizer.cc. References cost, early_stop, early_stop_i, PLearn::VarArray::fprop(), PLearn::TVec< Var >::length(), PLearn::VarArray::nelems(), params, PLearn::propagationPath(), PLearn::propagationPathToParentsOfPath(), proppath, PLearn::TVec< T >::resize(), temp_grad, and update_for_measure. Referenced by build(). |
|
Collect various statistics on the gradient.
|
|
Given an optimizer, compute the gradient of the cost function and store it in the "gradient" Vec.
Definition at line 259 of file Optimizer.cc. References PLearn::VarArray::clearGradient(), PLearn::VarArray::copyGradientTo(), cost, PLearn::VarArray::fbprop(), params, and proppath. |
|
Given an optimizer, compute the opposite of the gradient of the cost function and store it in the "gradient" Vec.
Definition at line 277 of file Optimizer.cc. References PLearn::VarArray::clearGradient(), PLearn::VarArray::copyGradientTo(), cost, PLearn::VarArray::fbprop(), params, and proppath. |
|
Compute the repartition of v by splitting the interval [mini,maxi] into n intervals. The result is stored into res. Definition at line 233 of file Optimizer.cc. References PLearn::TVec< T >::clear(), k, and PLearn::TVec< T >::length(). |
|
redefine this in subclasses: call declareOption(...) for each option, and then call inherited::declareOptions(options) ( see the declareOption function further down) ex: static void declareOptions(OptionList& ol) { declareOption(ol, "inputsize", &MyObject::inputsize_, OptionBase::buildoption, "the size of the input\n it must be provided"); declareOption(ol, "weights", &MyObject::weights, OptionBase::learntoption, "the learnt model weights"); inherited::declareOptions(ol); } Reimplemented from PLearn::Object. Reimplemented in PLearn::AdaptGradientOptimizer, PLearn::ConjGradientOptimizer, and PLearn::GradientOptimizer. Definition at line 106 of file Optimizer.cc. References PLearn::declareOption(), and PLearn::OptionList. |
|
Definition at line 114 of file Optimizer.h. References build(). |
|
Definition at line 179 of file Optimizer.cc. References build(), cost, PLearn::deepCopyField(), measurers, params, PLWARNING, PLearn::TVec< Measurer * >::size(), temp_grad, update_for_measure, and PLearn::varDeepCopyField(). |
|
Definition at line 205 of file Optimizer.cc. References measurers, and PLearn::TVec< Measurer * >::size(). |
|
DEPRECATED For backward compatibility with old saved object.
Reimplemented from PLearn::Object. Definition at line 131 of file Optimizer.cc. References every, nupdates, PLERROR, PLearn::readField(), PLearn::readFooter(), and PLearn::readHeader(). |
|
Definition at line 123 of file Optimizer.cc. References every, nupdates, PLearn::writeField(), PLearn::writeFooter(), and PLearn::writeHeader(). |
|
sub-classes should define this, which is the main method
Implemented in PLearn::AdaptGradientOptimizer, PLearn::ConjGradientOptimizer, PLearn::GradientOptimizer, and PLearn::ScaledGradientOptimizer. |
|
sub-classes should define this, which is the new main method
Implemented in PLearn::AdaptGradientOptimizer, PLearn::ConjGradientOptimizer, and PLearn::GradientOptimizer. |
|
|
|
Reimplemented in PLearn::ConjGradientOptimizer. Definition at line 101 of file Optimizer.cc. References stage. |
|
Definition at line 141 of file Optimizer.cc. References cost, PLearn::VarArray::fprop(), params, PLearn::propagationPath(), PLearn::propagationPathToParentsOfPath(), and proppath. Referenced by setVarArrayOption(), and setVarOption(). |
|
Definition at line 152 of file Optimizer.cc. References cost, PLERROR, setToOptimize(), and update_for_measure. |
|
Definition at line 159 of file Optimizer.cc. References params, PLERROR, and setToOptimize(). |
|
Definition at line 165 of file Optimizer.cc. References PLERROR. |
|
verify gradient at the current value of the parameters using step for the finite difference approximation of the gradient
Definition at line 219 of file Optimizer.cc. References cost, PLearn::VarArray::nelems(), and params. |
|
verify gradient with uniform random initialization of parameters using step for the finite difference approximation of the gradient
Definition at line 213 of file Optimizer.cc. |
|
|
Definition at line 78 of file Optimizer.h. Referenced by build_(), and PLearn::ConjGradientOptimizer::fletcherSearchMain(). |
|
Definition at line 79 of file Optimizer.h. Referenced by build_(). |
|
if = 0 don't print or measure anything
Definition at line 101 of file Optimizer.h. Referenced by oldread(), and oldwrite(). |
|
call measure <every> <nupdates> iterations saving the results in the <filename>.
Definition at line 98 of file Optimizer.h. |
|
Definition at line 94 of file Optimizer.h. Referenced by addMeasurer(), makeDeepCopyFromShallowCopy(), and measure(). |
|
number of steps to perform when calling optimizeN
Definition at line 75 of file Optimizer.h. |
|
Definition at line 74 of file Optimizer.h. Referenced by oldread(), and oldwrite(). |
|
|
Definition at line 73 of file Optimizer.h. Referenced by build_(), PLearn::ConjGradientOptimizer::computeCostAndDerivative(), PLearn::ConjGradientOptimizer::computeCostValue(), computeGradient(), computeOppositeGradient(), and setToOptimize(). |
|
current number of steps performed
Definition at line 76 of file Optimizer.h. Referenced by reset(). |
|
used to store temp stuff for gradient stats
Definition at line 89 of file Optimizer.h. Referenced by build_(), and makeDeepCopyFromShallowCopy(). |
|
Definition at line 81 of file Optimizer.h. Referenced by build_(), makeDeepCopyFromShallowCopy(), and setVarArrayOption(). |
|
Definition at line 85 of file Optimizer.h. |