PLearn 0.1
|
The first sentence should be a BRIEF DESCRIPTION of what the class does. More...
#include <MatrixModule.h>
Public Member Functions | |
MatrixModule (const string &the_name="", bool call_build_=false) | |
Default constructor. | |
void | setData (const Mat &the_data) |
Make this module see the provided 'the_data' matrix. | |
Mat & | getData () |
Return the current matrix viewed by this module. | |
virtual void | fprop (const Vec &input, Vec &output) const |
given the input, compute the output (possibly resize it appropriately) | |
virtual void | forget () |
Reset the parameters to the state they would be BEFORE starting training. | |
virtual void | fprop (const TVec< Mat * > &ports_value) |
If provided, the matrix value is used to fill 'data'. | |
virtual void | bpropAccUpdate (const TVec< Mat * > &ports_value, const TVec< Mat * > &ports_gradient) |
If provided, the gradient is used to update 'data' (and fill 'data_gradient'). | |
virtual const TVec< string > & | getPorts () |
Overridden. | |
virtual const TMat< int > & | getPortSizes () |
Overridden. | |
void | setGradientTo (real g) |
Set the gradient w.r.t. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual MatrixModule * | 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 | |
Mat | data |
Mat | data_gradient |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
Private Types | |
typedef OnlineLearningModule | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
The first sentence should be a BRIEF DESCRIPTION of what the class does.
Place the rest of the class programmer documentation here. Doxygen supports Javadoc-style comments. See http://www.doxygen.org/manual.html
Definition at line 57 of file MatrixModule.h.
typedef OnlineLearningModule PLearn::MatrixModule::inherited [private] |
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 59 of file MatrixModule.h.
PLearn::MatrixModule::MatrixModule | ( | const string & | the_name = "" , |
bool | call_build_ = false |
||
) |
Default constructor.
If 'the_name' is empty, and 'call_build_' is true, then the name is set to the name of this class (otherwise it is kept to an empty string, and it will be properly initialized at build time).
Definition at line 56 of file MatrixModule.cc.
References build_().
: inherited(the_name.empty() && call_build_ ? classname() : the_name, call_build_) { if (call_build_) build_(); }
string PLearn::MatrixModule::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 51 of file MatrixModule.cc.
OptionList & PLearn::MatrixModule::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 51 of file MatrixModule.cc.
RemoteMethodMap & PLearn::MatrixModule::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 51 of file MatrixModule.cc.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 51 of file MatrixModule.cc.
Object * PLearn::MatrixModule::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 51 of file MatrixModule.cc.
StaticInitializer MatrixModule::_static_initializer_ & PLearn::MatrixModule::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 51 of file MatrixModule.cc.
void PLearn::MatrixModule::bpropAccUpdate | ( | const TVec< Mat * > & | ports_value, |
const TVec< Mat * > & | ports_gradient | ||
) | [virtual] |
If provided, the gradient is used to update 'data' (and fill 'data_gradient').
If required, it is filled with 'gradient'.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 107 of file MatrixModule.cc.
References data, data_gradient, grad, PLearn::TMat< T >::isEmpty(), PLearn::TMat< T >::length(), PLearn::TVec< T >::length(), PLASSERT, PLERROR, PLearn::TMat< T >::resize(), PLearn::TVec< T >::resize(), and PLearn::TMat< T >::width().
{ PLASSERT( ports_gradient.length() == 1 ); Mat* grad = ports_gradient[0]; if (!grad) return; if (grad->isEmpty()) { // Accumulate 'data_gradient' into gradient (if there actually is a // gradient). grad->resize(data.length(), data.width()); if (!data_gradient.isEmpty()) { PLASSERT( data.length() == data_gradient.length() && data.width() == data_gradient.width() ); *grad += data_gradient; } } else { data_gradient.resize(grad->length(), grad->width()); data_gradient << *grad; PLERROR("In MatrixModule::bpropAccUpdate - Update of the underlying " "data matrix is not yet implemented"); } }
void PLearn::MatrixModule::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 98 of file MatrixModule.cc.
References PLearn::OnlineLearningModule::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::MatrixModule::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 92 of file MatrixModule.cc.
Referenced by build(), and MatrixModule().
{}
string PLearn::MatrixModule::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 51 of file MatrixModule.cc.
void PLearn::MatrixModule::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 67 of file MatrixModule.cc.
References PLearn::OptionBase::buildoption, data, data_gradient, PLearn::declareOption(), and PLearn::OnlineLearningModule::declareOptions().
{ // ### Declare all of this object's options here. // ### For the "flags" of each option, you should typically specify // ### one of OptionBase::buildoption, OptionBase::learntoption or // ### OptionBase::tuningoption. If you don't provide one of these three, // ### this option will be ignored when loading values from a script. // ### You can also combine flags, for example with OptionBase::nosave: // ### (OptionBase::buildoption | OptionBase::nosave) declareOption(ol, "data", &MatrixModule::data, OptionBase::buildoption, "The matrix seen by this module."); declareOption(ol, "data_gradient", &MatrixModule::data_gradient, OptionBase::buildoption, "The gradient w.r.t. 'data'. If not provided, is assumed to be 0."); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::MatrixModule::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 197 of file MatrixModule.h.
:
//##### Protected Member Functions ######################################
MatrixModule * PLearn::MatrixModule::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 51 of file MatrixModule.cc.
void PLearn::MatrixModule::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 212 of file MatrixModule.cc.
{
// Nothing to forget.
}
If provided, the matrix value is used to fill 'data'.
If required, it is filled with 'data'.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 151 of file MatrixModule.cc.
References data, PLearn::TMat< T >::length(), PLearn::TVec< T >::length(), PLASSERT, PLearn::TMat< T >::resize(), PLearn::TVec< T >::resize(), and PLearn::TMat< T >::width().
{ PLASSERT( ports_value.length() == 1 ); Mat* mat = ports_value[0]; if (!mat) return; if (mat->isEmpty()) { // We want to query the value of the matrix. mat->resize(data.length(), data.width()); *mat << data; } else { // We want to store the value of the matrix. data.resize(mat->length(), mat->width()); data << *mat; } }
given the input, compute the output (possibly resize it appropriately)
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 146 of file MatrixModule.cc.
References PLERROR.
{ PLERROR("In MatrixModule::fprop - Not implemented"); }
Mat & PLearn::MatrixModule::getData | ( | ) |
Return the current matrix viewed by this module.
Definition at line 250 of file MatrixModule.cc.
References data.
{ return this->data; }
OptionList & PLearn::MatrixModule::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 51 of file MatrixModule.cc.
OptionMap & PLearn::MatrixModule::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 51 of file MatrixModule.cc.
const TVec< string > & PLearn::MatrixModule::getPorts | ( | ) | [virtual] |
Overridden.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 220 of file MatrixModule.cc.
References PLearn::TVec< T >::append(), and PLearn::TVec< T >::isEmpty().
{ static TVec<string> ports; if (ports.isEmpty()) ports.append("data"); return ports; }
Overridden.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 231 of file MatrixModule.cc.
References data, PLearn::TMat< T >::length(), PLearn::OnlineLearningModule::port_sizes, PLearn::TMat< T >::resize(), and PLearn::TMat< T >::width().
{ port_sizes.resize(1, 2); port_sizes(0, 0) = data.length(); port_sizes(0, 1) = data.width(); return port_sizes; }
RemoteMethodMap & PLearn::MatrixModule::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 51 of file MatrixModule.cc.
void PLearn::MatrixModule::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 135 of file MatrixModule.cc.
References data, data_gradient, PLearn::deepCopyField(), and PLearn::OnlineLearningModule::makeDeepCopyFromShallowCopy().
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(data, copies); deepCopyField(data_gradient, copies); }
void PLearn::MatrixModule::setData | ( | const Mat & | the_data | ) |
Make this module see the provided 'the_data' matrix.
Note that no copy is made, so 'the_data' should not be modified afterwards.
Definition at line 285 of file MatrixModule.cc.
References data.
{ this->data = the_data; }
void PLearn::MatrixModule::setGradientTo | ( | real | g | ) |
Set the gradient w.r.t.
'data' to the provided constant value 'g'. The result is that 'data_gradient' is resized to the same size as 'data' and filled with 'g'.
Definition at line 267 of file MatrixModule.cc.
References data, data_gradient, PLearn::TMat< T >::fill(), PLearn::TMat< T >::length(), PLearn::TMat< T >::resize(), and PLearn::TMat< T >::width().
{ data_gradient.resize(data.length(), data.width()); data_gradient.fill(g); }
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 197 of file MatrixModule.h.
Definition at line 64 of file MatrixModule.h.
Referenced by bpropAccUpdate(), declareOptions(), fprop(), getData(), getPortSizes(), makeDeepCopyFromShallowCopy(), setData(), and setGradientTo().
Definition at line 65 of file MatrixModule.h.
Referenced by bpropAccUpdate(), declareOptions(), makeDeepCopyFromShallowCopy(), and setGradientTo().