PLearn 0.1
|
Takes a submatrix of an input variable. More...
#include <SubMatVariable.h>
Public Member Functions | |
SubMatVariable () | |
Default constructor for persistence. | |
SubMatVariable (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 SubMatVariable * | 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 | bbprop () |
compute an approximation to diag(d^2/dinput^2) given diag(d^2/doutput^2), with diag(d^2/dinput^2) ~=~ (doutput/dinput)' diag(d^2/doutput^2) (doutput/dinput) In particular: if 'C' depends on 'y' and 'y' depends on x ... | |
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_ () |
SubMatVariable. | |
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 |
Should not be set directly: this is equal to the starting element in the INPUT MATRIX corresponding to the settings of i_ and j_. | |
int | length_ |
New length (number of rows) of the SubVMatrix variable. | |
int | width_ |
New width (number of columns) of the SubVMatrix variable. | |
int | i_ |
Starting ROW in the input variable. | |
int | j_ |
Starting COLUMN in the input variable. | |
Private Types | |
typedef UnaryVariable | inherited |
Private Member Functions | |
void | build_ () |
Object-specific post-constructor. |
Takes a submatrix of an input variable.
This Variable performs creates a view of a subset of an input variable. The starting row and column in the input variable must be specified, as well as the new number of rows and columns.
Variables of this kind can also be created from C++ through the subMat function.
Definition at line 61 of file SubMatVariable.h.
typedef UnaryVariable PLearn::SubMatVariable::inherited [private] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 63 of file SubMatVariable.h.
PLearn::SubMatVariable::SubMatVariable | ( | ) | [inline] |
string PLearn::SubMatVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 61 of file SubMatVariable.cc.
OptionList & PLearn::SubMatVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 61 of file SubMatVariable.cc.
RemoteMethodMap & PLearn::SubMatVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 61 of file SubMatVariable.cc.
Reimplemented from PLearn::UnaryVariable.
Definition at line 61 of file SubMatVariable.cc.
Object * PLearn::SubMatVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 61 of file SubMatVariable.cc.
StaticInitializer SubMatVariable::_static_initializer_ & PLearn::SubMatVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 61 of file SubMatVariable.cc.
void PLearn::SubMatVariable::bbprop | ( | ) | [virtual] |
compute an approximation to diag(d^2/dinput^2) given diag(d^2/doutput^2), with diag(d^2/dinput^2) ~=~ (doutput/dinput)' diag(d^2/doutput^2) (doutput/dinput) In particular: if 'C' depends on 'y' and 'y' depends on x ...
d^2C/dx^2 = d^2C/dy^2 * (dy/dx)^2 + dC/dy * d^2y/dx^2 (diaghessian) (gradient)
Reimplemented from PLearn::Variable.
Definition at line 164 of file SubMatVariable.cc.
References PLearn::Variable::diaghessiandata, i, PLearn::UnaryVariable::input, j, PLearn::Var::length(), PLearn::Variable::length(), PLearn::Variable::nelems(), startk, PLearn::Variable::width(), and PLearn::Var::width().
{ if (input->diaghessian.length()==0) input->resizeDiagHessian(); if(width()==input->width()) // optimized version for this special case { real* inputdiaghessian = input->diaghessian.data()+startk; for(int k=0; k<nelems(); k++) inputdiaghessian[k] += diaghessiandata[k]; } else // general version { real* inputrowdiaghessian = input->diaghessiandata+startk; int thisk=0; for(int i=0; i<length(); i++) { for(int j=0; j<width(); j++) inputrowdiaghessian[j] += diaghessiandata[thisk++]; inputrowdiaghessian += input->width(); } } }
void PLearn::SubMatVariable::bprop | ( | ) | [virtual] |
Nothing to do by default.
Reimplemented from PLearn::UnaryVariable.
Definition at line 142 of file SubMatVariable.cc.
References PLearn::Variable::gradientdata, i, PLearn::UnaryVariable::input, j, PLearn::Variable::length(), PLearn::Variable::nelems(), startk, PLearn::Variable::width(), and PLearn::Var::width().
{ if(width()==input->width()) // optimized version for this special case { real* inputgradient = input->gradientdata+startk; for(int k=0; k<nelems(); k++) inputgradient[k] += gradientdata[k]; } else // general version { real* inputrowgradient = input->gradientdata+startk; int thisk=0; for(int i=0; i<length(); i++) { for(int j=0; j<width(); j++) inputrowgradient[j] += gradientdata[thisk++]; inputrowgradient += input->width(); } } }
void PLearn::SubMatVariable::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 74 of file SubMatVariable.cc.
References PLearn::UnaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::SubMatVariable::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 80 of file SubMatVariable.cc.
References i_, PLearn::UnaryVariable::input, j_, PLearn::Var::length(), PLearn::Variable::length(), PLERROR, startk, and PLearn::Var::width().
Referenced by build(), and SubMatVariable().
{ if (input) { // input is v from constructor if(i_ < 0 || i_ + length() > input->length() || j_ < 0 || j_ + width() > input->width()) PLERROR("In SubMatVariable: requested sub-matrix is out of matrix bounds"); startk = i_ * input->width() + j_; } }
string PLearn::SubMatVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 61 of file SubMatVariable.cc.
void PLearn::SubMatVariable::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 91 of file SubMatVariable.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::UnaryVariable::declareOptions(), i_, j_, PLearn::OptionBase::learntoption, length_, startk, and width_.
{ declareOption( ol, "length_", &SubMatVariable::length_, OptionBase::buildoption, "New length (number of rows) of the SubVMatrix variable"); declareOption( ol, "width_", &SubMatVariable::width_, OptionBase::buildoption, "New width (number of columns) of the SubVMatrix variable"); declareOption( ol, "i_", &SubMatVariable::i_, OptionBase::buildoption, "Starting ROW in the input variable"); declareOption( ol, "j_", &SubMatVariable::j_, OptionBase::buildoption, "Starting COLUMN in the input variable"); declareOption( ol, "startk", &SubMatVariable::startk, OptionBase::learntoption, "Should not be set directly: this is equal to the starting element\n" "in the INPUT MATRIX corresponding to the settings of i_ and j_."); inherited::declareOptions(ol); }
static const PPath& PLearn::SubMatVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 87 of file SubMatVariable.h.
: void build_();
SubMatVariable * PLearn::SubMatVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 61 of file SubMatVariable.cc.
void PLearn::SubMatVariable::fprop | ( | ) | [virtual] |
Nothing to do by default.
Reimplemented from PLearn::UnaryVariable.
Definition at line 120 of file SubMatVariable.cc.
References i, PLearn::UnaryVariable::input, j, PLearn::Variable::length(), PLearn::Variable::nelems(), startk, PLearn::Variable::valuedata, PLearn::Variable::width(), and PLearn::Var::width().
{ if(width()==input->width()) // optimized version for this special case { real* inputdata = input->valuedata+startk; for(int k=0; k<nelems(); k++) valuedata[k] = inputdata[k]; } else // general version { real* inputrowdata = input->valuedata+startk; int thisk=0; for(int i=0; i<length(); i++) { for(int j=0; j<width(); j++) valuedata[thisk++] = inputrowdata[j]; inputrowdata += input->width(); } } }
OptionList & PLearn::SubMatVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 61 of file SubMatVariable.cc.
OptionMap & PLearn::SubMatVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 61 of file SubMatVariable.cc.
RemoteMethodMap & PLearn::SubMatVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 61 of file SubMatVariable.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 117 of file SubMatVariable.cc.
void PLearn::SubMatVariable::rfprop | ( | ) | [virtual] |
Reimplemented from PLearn::Variable.
Definition at line 200 of file SubMatVariable.cc.
References i, PLearn::UnaryVariable::input, j, 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(width()==input->width()) // optimized version for this special case { real* inputrdata = input->rvaluedata+startk; for(int k=0; k<nelems(); k++) rvaluedata[k] = inputrdata[k]; } else // general version { real* inputrowrdata = input->rvaluedata+startk; int thisk=0; for(int i=0; i<length(); i++) { for(int j=0; j<width(); j++) rvaluedata[thisk++] = inputrowrdata[j]; inputrowrdata += input->width(); } } }
void PLearn::SubMatVariable::symbolicBprop | ( | ) | [virtual] |
compute a piece of new Var graph that represents the symbolic derivative of this Var
Reimplemented from PLearn::Variable.
Definition at line 188 of file SubMatVariable.cc.
References PLearn::extend(), PLearn::Variable::g, i, PLearn::UnaryVariable::input, j, PLearn::Var::length(), PLearn::Variable::length(), startk, 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+length()); int leftextent = j; int rightextent = input->width()-(j+width()); input->accg(extend(g,topextent,bottomextent,leftextent,rightextent)); }
Reimplemented from PLearn::UnaryVariable.
Definition at line 87 of file SubMatVariable.h.
int PLearn::SubMatVariable::i_ [protected] |
Starting ROW in the input variable.
Definition at line 77 of file SubMatVariable.h.
Referenced by build_(), and declareOptions().
int PLearn::SubMatVariable::j_ [protected] |
Starting COLUMN in the input variable.
Definition at line 80 of file SubMatVariable.h.
Referenced by build_(), and declareOptions().
int PLearn::SubMatVariable::length_ [protected] |
New length (number of rows) of the SubVMatrix variable.
Definition at line 71 of file SubMatVariable.h.
Referenced by declareOptions(), and recomputeSize().
int PLearn::SubMatVariable::startk [protected] |
Should not be set directly: this is equal to the starting element in the INPUT MATRIX corresponding to the settings of i_ and j_.
Definition at line 68 of file SubMatVariable.h.
Referenced by bbprop(), bprop(), build_(), declareOptions(), fprop(), rfprop(), and symbolicBprop().
int PLearn::SubMatVariable::width_ [protected] |
New width (number of columns) of the SubVMatrix variable.
Definition at line 74 of file SubMatVariable.h.
Referenced by declareOptions(), and recomputeSize().