PLearn 0.1
|
#include <ForwardModule.h>
Public Member Functions | |
ForwardModule (const string &the_name="", bool call_build_=false) | |
Constructor. | |
void | fprop (const TVec< Mat * > &ports_value) |
Perform a fprop step. | |
virtual void | bpropAccUpdate (const TVec< Mat * > &ports_value, const TVec< Mat * > &ports_gradient) |
Perform a back propagation step (also updating parameters according to the provided gradient). | |
virtual void | forget () |
Reset the parameters to the state they would be BEFORE starting training. | |
virtual void | finalize () |
Perform some processing after training, or after a series of fprop/bpropUpdate calls to prepare the model for truly out-of-sample operation. | |
virtual bool | bpropDoesNothing () |
In case bpropUpdate does not do anything, make it known. | |
virtual void | setLearningRate (real dynamic_learning_rate) |
If this class has a learning rate (or something close to it), set it. | |
virtual const TVec< string > & | getPorts () |
Return the list of ports in the module. | |
virtual const TMat< int > & | getPortSizes () |
Return the size of all ports, in the form of a two-column matrix, where each row represents a port, and the two numbers on a row are respectively its length and its width (with -1 representing an undefined or variable value). | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual ForwardModule * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Post-constructor. | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
Static Public Member Functions | |
static string | _classname_ () |
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 | |
TVec< PP< OnlineLearningModule > > | modules |
string | forward_to |
bool | forget_all |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
Protected Attributes | |
int | current |
Index of the module currently being used in the 'modules' list. | |
Private Types | |
typedef OnlineLearningModule | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Definition at line 47 of file ForwardModule.h.
typedef OnlineLearningModule PLearn::ForwardModule::inherited [private] |
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 49 of file ForwardModule.h.
PLearn::ForwardModule::ForwardModule | ( | const string & | the_name = "" , |
bool | call_build_ = false |
||
) |
Constructor.
Definition at line 56 of file ForwardModule.cc.
References build_().
: inherited(the_name.empty() && call_build_ ? classname() : the_name, call_build_), forget_all(true), current(-1) { if (call_build_) build_(); }
string PLearn::ForwardModule::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 51 of file ForwardModule.cc.
OptionList & PLearn::ForwardModule::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 51 of file ForwardModule.cc.
RemoteMethodMap & PLearn::ForwardModule::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 51 of file ForwardModule.cc.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 51 of file ForwardModule.cc.
Object * PLearn::ForwardModule::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 51 of file ForwardModule.cc.
StaticInitializer ForwardModule::_static_initializer_ & PLearn::ForwardModule::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 51 of file ForwardModule.cc.
void PLearn::ForwardModule::bpropAccUpdate | ( | const TVec< Mat * > & | ports_value, |
const TVec< Mat * > & | ports_gradient | ||
) | [virtual] |
Perform a back propagation step (also updating parameters according to the provided gradient).
The matrices in 'ports_value' must be the same as the ones given in a previous call to 'fprop' (and thus they should in particular contain the result of the fprop computation). However, they are not necessarily the same as the ones given in the LAST call to 'fprop': if there is a need to store an internal module state, this should be done using a specific port to store this state. Each Mat* pointer in the 'ports_gradient' vector can be one of:
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 165 of file ForwardModule.cc.
bool PLearn::ForwardModule::bpropDoesNothing | ( | ) | [virtual] |
In case bpropUpdate does not do anything, make it known.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 194 of file ForwardModule.cc.
void PLearn::ForwardModule::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::OnlineLearningModule.
Definition at line 137 of file ForwardModule.cc.
References PLearn::OnlineLearningModule::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::ForwardModule::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 105 of file ForwardModule.cc.
References current, forward_to, i, PLearn::TVec< T >::length(), modules, PLearn::OnlineLearningModule::name, PLCHECK, and PLearn::OnlineLearningModule::random_gen.
Referenced by build(), and ForwardModule().
{ current = -1; if (forward_to.empty()) current = 0; else { for (int i = 0; i < modules.length(); i++) { if (modules[i]->name == forward_to) { current = i; break; } } } PLCHECK( current >= 0 ); // Forward random number generator to all underlying modules. Note that we // need to forward it to all modules because we call forget(). if (random_gen) { for (int i = 0; i < modules.length(); i++) { PP<OnlineLearningModule> mod = modules[i]; if (!mod->random_gen) { mod->random_gen = random_gen; mod->build(); mod->forget(); } } } }
string PLearn::ForwardModule::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 51 of file ForwardModule.cc.
void PLearn::ForwardModule::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 69 of file ForwardModule.cc.
References PLearn::OptionBase::buildoption, current, PLearn::declareOption(), PLearn::OnlineLearningModule::declareOptions(), forget_all, forward_to, modules, and PLearn::OptionBase::nosave.
{ // 'build' options. declareOption(ol, "modules", &ForwardModule::modules, OptionBase::buildoption, "The list of modules that can be used to forward calls."); declareOption(ol, "forward_to", &ForwardModule::forward_to, OptionBase::buildoption, "Name of the module currently being used. If empty, the first module\n" "in 'modules' will be used."); declareOption(ol, "forget_all", &ForwardModule::forget_all, OptionBase::buildoption, "If set to 1, then the forget() method will call forget() on all\n" "modules. Otherwise, only the current module pointed by 'forward_to'\n" "will be forgotten."); // 'nosave' options. // 'current' is an option only so it can be modified in server mode for // instance, in order to bypass a call to build (yes, this is a hack!). declareOption(ol, "current", &ForwardModule::current, OptionBase::nosave, "Index in 'modules' of the module given by 'forward_to'."); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::ForwardModule::declaringFile | ( | ) | [inline, static] |
ForwardModule * PLearn::ForwardModule::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 51 of file ForwardModule.cc.
void PLearn::ForwardModule::finalize | ( | ) | [virtual] |
Perform some processing after training, or after a series of fprop/bpropUpdate calls to prepare the model for truly out-of-sample operation.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 186 of file ForwardModule.cc.
void PLearn::ForwardModule::forget | ( | ) | [virtual] |
Reset the parameters to the state they would be BEFORE starting training.
Note that this method is necessarily called from build().
Implements PLearn::OnlineLearningModule.
Definition at line 174 of file ForwardModule.cc.
References current, forget_all, i, PLearn::TVec< T >::length(), and modules.
{ if (forget_all) { for (int i = 0; i < modules.length(); i++) modules[i]->forget(); } else modules[current]->forget(); }
Perform a fprop step.
Each Mat* pointer in the 'ports_value' vector can be one of:
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 157 of file ForwardModule.cc.
OptionList & PLearn::ForwardModule::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 51 of file ForwardModule.cc.
OptionMap & PLearn::ForwardModule::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 51 of file ForwardModule.cc.
const TVec< string > & PLearn::ForwardModule::getPorts | ( | ) | [virtual] |
Return the list of ports in the module.
The default implementation returns a pair ("input", "output") to handle the most common case.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 210 of file ForwardModule.cc.
Return the size of all ports, in the form of a two-column matrix, where each row represents a port, and the two numbers on a row are respectively its length and its width (with -1 representing an undefined or variable value).
The default value fills this matrix with:
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 217 of file ForwardModule.cc.
RemoteMethodMap & PLearn::ForwardModule::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 51 of file ForwardModule.cc.
void PLearn::ForwardModule::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 147 of file ForwardModule.cc.
References PLearn::deepCopyField(), PLearn::OnlineLearningModule::makeDeepCopyFromShallowCopy(), and modules.
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(modules, copies); }
void PLearn::ForwardModule::setLearningRate | ( | real | dynamic_learning_rate | ) | [virtual] |
If this class has a learning rate (or something close to it), set it.
If not, you can redefine this method to get rid of the warning.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 202 of file ForwardModule.cc.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 146 of file ForwardModule.h.
int PLearn::ForwardModule::current [protected] |
Index of the module currently being used in the 'modules' list.
Definition at line 158 of file ForwardModule.h.
Referenced by bpropAccUpdate(), bpropDoesNothing(), build_(), declareOptions(), finalize(), forget(), fprop(), getPorts(), getPortSizes(), and setLearningRate().
Definition at line 57 of file ForwardModule.h.
Referenced by declareOptions(), and forget().
Definition at line 56 of file ForwardModule.h.
Referenced by build_(), and declareOptions().
Definition at line 55 of file ForwardModule.h.
Referenced by bpropAccUpdate(), bpropDoesNothing(), build_(), declareOptions(), finalize(), forget(), fprop(), getPorts(), getPortSizes(), makeDeepCopyFromShallowCopy(), and setLearningRate().