PLearn 0.1
|
#include <SubMatTransposeVariable.h>
Public Member Functions | |
SubMatTransposeVariable () | |
Default constructor for persistence. | |
SubMatTransposeVariable (Variable *v, int i, int j, int the_length, int the_width) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual SubMatTransposeVariable * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Post-constructor. | |
virtual void | recomputeSize (int &l, int &w) const |
Recomputes the length l and width w that this variable should have, according to its parent variables. | |
virtual void | fprop () |
Nothing to do by default. | |
virtual void | bprop () |
Nothing to do by default. | |
virtual void | symbolicBprop () |
compute a piece of new Var graph that represents the symbolic derivative of this Var | |
virtual void | rfprop () |
Static Public Member Functions | |
static string | _classname_ () |
SubMatTransposeVariable. | |
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 () |
static void | declareOptions (OptionList &ol) |
Declare options (data fields) for the class. | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Protected Attributes | |
int | startk |
int | length_ |
int | width_ |
int | i_ |
int | j_ |
Private Types | |
typedef UnaryVariable | inherited |
Private Member Functions | |
void | build_ () |
Object-specific post-constructor. |
Definition at line 52 of file SubMatTransposeVariable.h.
typedef UnaryVariable PLearn::SubMatTransposeVariable::inherited [private] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 57 of file SubMatTransposeVariable.h.
PLearn::SubMatTransposeVariable::SubMatTransposeVariable | ( | ) | [inline] |
string PLearn::SubMatTransposeVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubMatTransposeVariable.cc.
OptionList & PLearn::SubMatTransposeVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubMatTransposeVariable.cc.
RemoteMethodMap & PLearn::SubMatTransposeVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubMatTransposeVariable.cc.
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubMatTransposeVariable.cc.
Object * PLearn::SubMatTransposeVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubMatTransposeVariable.cc.
StaticInitializer SubMatTransposeVariable::_static_initializer_ & PLearn::SubMatTransposeVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubMatTransposeVariable.cc.
void PLearn::SubMatTransposeVariable::bprop | ( | ) | [virtual] |
Nothing to do by default.
Reimplemented from PLearn::UnaryVariable.
Definition at line 119 of file SubMatTransposeVariable.cc.
References PLearn::Variable::gradientdata, i, PLearn::UnaryVariable::input, j, PLearn::Var::length(), PLearn::Variable::length(), PLearn::Variable::nelems(), startk, PLearn::Variable::width(), and PLearn::Var::width().
{ if(input->length()==1 || input->width()==1) // optimized version for this special case... { real* inputdata = input->gradientdata+startk; for(int k=0; k<nelems(); k++) inputdata[k] += gradientdata[k]; } else // general case { real* inputrowdata = input->gradientdata+startk; int thiskcolstart = 0; // element index of start of column in this var for(int i=0; i<width(); i++) // the width() of this var is the length() of the submat { int thisk = thiskcolstart++; for(int j=0; j<length(); j++, thisk+=width()) // the length() of this var is the width() of the submat inputrowdata[j] += gradientdata[thisk]; inputrowdata += input->width(); } } }
void PLearn::SubMatTransposeVariable::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::UnaryVariable.
Definition at line 66 of file SubMatTransposeVariable.cc.
References PLearn::UnaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::SubMatTransposeVariable::build_ | ( | ) | [private] |
Object-specific post-constructor.
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 its parent's build_()
has already been called.
Reimplemented from PLearn::UnaryVariable.
Definition at line 72 of file SubMatTransposeVariable.cc.
References i_, PLearn::UnaryVariable::input, j_, PLearn::Var::length(), PLERROR, startk, and PLearn::Var::width().
Referenced by build(), and SubMatTransposeVariable().
{ if (input) { // input is v from constructor if (i_ < 0 || i_ + length_ > input->length() || j_ < 0 || j_ + width_ > input->width()) PLERROR("In SubMatTransposeVariable: requested sub-matrix is out of matrix bounds"); startk = i_ * input->length() + j_; } }
string PLearn::SubMatTransposeVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubMatTransposeVariable.cc.
void PLearn::SubMatTransposeVariable::declareOptions | ( | OptionList & | ol | ) | [static] |
Declare options (data fields) for the class.
Redefine this in subclasses: call declareOption
(...) for each option, and then call inherited::declareOptions(options)
. Please call the inherited
method AT THE END to get the options listed in a consistent order (from most recently defined to least recently defined).
static void MyDerivedClass::declareOptions(OptionList& ol) { declareOption(ol, "inputsize", &MyObject::inputsize_, OptionBase::buildoption, "The size of the input; it must be provided"); declareOption(ol, "weights", &MyObject::weights, OptionBase::learntoption, "The learned model weights"); inherited::declareOptions(ol); }
ol | List of options that is progressively being constructed for the current class. |
Reimplemented from PLearn::UnaryVariable.
Definition at line 83 of file SubMatTransposeVariable.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::UnaryVariable::declareOptions(), i_, j_, length_, startk, and width_.
{ declareOption(ol, "length_", &SubMatTransposeVariable::length_, OptionBase::buildoption, ""); declareOption(ol, "width_", &SubMatTransposeVariable::width_, OptionBase::buildoption, ""); declareOption(ol, "startk", &SubMatTransposeVariable::startk, OptionBase::buildoption, ""); declareOption(ol, "i_", &SubMatTransposeVariable::i_, OptionBase::buildoption, ""); declareOption(ol, "j_", &SubMatTransposeVariable::j_, OptionBase::buildoption, ""); inherited::declareOptions(ol); }
static const PPath& PLearn::SubMatTransposeVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 71 of file SubMatTransposeVariable.h.
:
SubMatTransposeVariable * PLearn::SubMatTransposeVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubMatTransposeVariable.cc.
void PLearn::SubMatTransposeVariable::fprop | ( | ) | [virtual] |
Nothing to do by default.
Reimplemented from PLearn::UnaryVariable.
Definition at line 96 of file SubMatTransposeVariable.cc.
References i, PLearn::UnaryVariable::input, j, PLearn::Var::length(), PLearn::Variable::length(), PLearn::Variable::nelems(), startk, PLearn::Variable::valuedata, PLearn::Variable::width(), and PLearn::Var::width().
{ if(input->length()==1 || input->width()==1) // optimized version for this special case... { real* inputdata = input->valuedata+startk; for(int k=0; k<nelems(); k++) valuedata[k] = inputdata[k]; } else // general case { real* inputrowdata = input->valuedata+startk; int thiskcolstart = 0; // element index of start of column in this var for(int i=0; i<width(); i++) // the width() of this var is the length() of the submat { int thisk = thiskcolstart++; for(int j=0; j<length(); j++, thisk+=width()) // the length() of this var is the width() of the submat valuedata[thisk] = inputrowdata[j]; inputrowdata += input->width(); } } }
OptionList & PLearn::SubMatTransposeVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubMatTransposeVariable.cc.
OptionMap & PLearn::SubMatTransposeVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubMatTransposeVariable.cc.
RemoteMethodMap & PLearn::SubMatTransposeVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file SubMatTransposeVariable.cc.
Recomputes the length l and width w that this variable should have, according to its parent variables.
This is used for ex. by sizeprop() The default version stupidly returns the current dimensions, so make sure to overload it in subclasses if this is not appropriate.
Reimplemented from PLearn::Variable.
Definition at line 93 of file SubMatTransposeVariable.cc.
void PLearn::SubMatTransposeVariable::rfprop | ( | ) | [virtual] |
Reimplemented from PLearn::Variable.
Definition at line 154 of file SubMatTransposeVariable.cc.
References i, PLearn::UnaryVariable::input, j, PLearn::Var::length(), PLearn::TVec< T >::length(), PLearn::Variable::length(), PLearn::Variable::nelems(), PLearn::UnaryVariable::resizeRValue(), PLearn::Variable::rValue, PLearn::Variable::rvaluedata, startk, PLearn::Variable::width(), and PLearn::Var::width().
{ if (rValue.length()==0) resizeRValue(); if(input->length()==1 || input->width()==1) // optimized version for this special case... { real* inputdata = input->rvaluedata+startk; for(int k=0; k<nelems(); k++) rvaluedata[k] = inputdata[k]; } else // general case { real* inputrowdata = input->rvaluedata+startk; int thiskcolstart = 0; // element index of start of column in this var for(int i=0; i<width(); i++) // the width() of this var is the length() of the submat { int thisk = thiskcolstart++; for(int j=0; j<length(); j++, thisk+=width()) // the length() of this var is the width() of the submat rvaluedata[thisk] = inputrowdata[j]; inputrowdata += input->width(); } } }
void PLearn::SubMatTransposeVariable::symbolicBprop | ( | ) | [virtual] |
compute a piece of new Var graph that represents the symbolic derivative of this Var
Reimplemented from PLearn::Variable.
Definition at line 142 of file SubMatTransposeVariable.cc.
References PLearn::extend(), PLearn::Variable::g, i, PLearn::UnaryVariable::input, j, PLearn::Variable::length(), PLearn::Var::length(), startk, PLearn::transpose(), PLearn::Variable::width(), and PLearn::Var::width().
{ int i = startk/input->width(); int j = startk%input->width(); int topextent = i; int bottomextent = input->length()-(i+width()); // the width() of this var is the length() of the submat int leftextent = j; int rightextent = input->width()-(j+length()); // the length() of this var is the width() of the submat input->accg(extend(transpose(g),topextent,bottomextent,leftextent,rightextent)); }
Reimplemented from PLearn::UnaryVariable.
Definition at line 71 of file SubMatTransposeVariable.h.
int PLearn::SubMatTransposeVariable::i_ [protected] |
Definition at line 63 of file SubMatTransposeVariable.h.
Referenced by build_(), and declareOptions().
int PLearn::SubMatTransposeVariable::j_ [protected] |
Definition at line 63 of file SubMatTransposeVariable.h.
Referenced by build_(), and declareOptions().
int PLearn::SubMatTransposeVariable::length_ [protected] |
Definition at line 62 of file SubMatTransposeVariable.h.
Referenced by declareOptions(), and recomputeSize().
int PLearn::SubMatTransposeVariable::startk [protected] |
Definition at line 61 of file SubMatTransposeVariable.h.
Referenced by bprop(), build_(), declareOptions(), fprop(), rfprop(), and symbolicBprop().
int PLearn::SubMatTransposeVariable::width_ [protected] |
Definition at line 62 of file SubMatTransposeVariable.h.
Referenced by declareOptions(), and recomputeSize().