PLearn 0.1
|
#include <InsertZerosVariable.h>
Public Member Functions | |
InsertZerosVariable () | |
Default constructor for persistence. | |
InsertZerosVariable (Variable *input, TVec< int > rows) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual InsertZerosVariable * | 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 () |
void | setInput (Var the_input) |
Set this Variable's input (simply call build after setting the new input). | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be. | |
Static Public Member Functions | |
static string | _classname_ () |
InsertZerosVariable. | |
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< int > | rows |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Private Types | |
typedef UnaryVariable | inherited |
Private Member Functions | |
void | build_ () |
Object-specific post-constructor. |
Definition at line 43 of file InsertZerosVariable.h.
typedef UnaryVariable PLearn::InsertZerosVariable::inherited [private] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 44 of file InsertZerosVariable.h.
PLearn::InsertZerosVariable::InsertZerosVariable | ( | ) | [inline] |
string PLearn::InsertZerosVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 45 of file InsertZerosVariable.cc.
OptionList & PLearn::InsertZerosVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 45 of file InsertZerosVariable.cc.
RemoteMethodMap & PLearn::InsertZerosVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 45 of file InsertZerosVariable.cc.
Reimplemented from PLearn::UnaryVariable.
Definition at line 45 of file InsertZerosVariable.cc.
Object * PLearn::InsertZerosVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 45 of file InsertZerosVariable.cc.
StaticInitializer InsertZerosVariable::_static_initializer_ & PLearn::InsertZerosVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 45 of file InsertZerosVariable.cc.
void PLearn::InsertZerosVariable::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 121 of file InsertZerosVariable.cc.
References PLERROR.
{ PLERROR("bbprop is not implemented for InsertZerosVariable"); }
void PLearn::InsertZerosVariable::bprop | ( | ) | [virtual] |
Nothing to do by default.
Reimplemented from PLearn::UnaryVariable.
Definition at line 103 of file InsertZerosVariable.cc.
References i, PLearn::UnaryVariable::input, j, PLearn::TMat< T >::length(), PLearn::TVec< T >::length(), PLearn::Variable::matGradient, rows, and PLearn::TMat< T >::width().
{ real* gptr; real* ginputptr; int r=0; for(int i=0; i<matGradient.length(); i++) { if(r<rows.length() && i==rows[r]) r++; else { gptr = matGradient[i]; ginputptr = input->matGradient[i-r]; for(int j=0; j<matGradient.width(); j++) *ginputptr++ += *gptr++; } } }
void PLearn::InsertZerosVariable::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 InsertZerosVariable.cc.
References PLearn::UnaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::InsertZerosVariable::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 59 of file InsertZerosVariable.cc.
References i, PLearn::UnaryVariable::input, PLearn::Var::length(), PLearn::TVec< T >::length(), PLERROR, rows, and PLearn::sortElements().
Referenced by build().
{ if(input) { sortElements(rows); // Check if all elements are unique for(int i=0; i<rows.length()-1; i++) { if(rows[i] == rows[i+1]) PLERROR("InsertZerosVariable::build_(): some elements in rows are the same"); if(rows[i] > input->length()+i) PLERROR("InsertZerosVariable::build_(): cannot add row of zeros at positon %d", rows[i+1]); } } }
string PLearn::InsertZerosVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 45 of file InsertZerosVariable.cc.
static const PPath& PLearn::InsertZerosVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 55 of file InsertZerosVariable.h.
: void build_();
InsertZerosVariable * PLearn::InsertZerosVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 45 of file InsertZerosVariable.cc.
void PLearn::InsertZerosVariable::fprop | ( | ) | [virtual] |
Nothing to do by default.
Reimplemented from PLearn::UnaryVariable.
Definition at line 80 of file InsertZerosVariable.cc.
References i, PLearn::UnaryVariable::input, j, PLearn::TMat< T >::length(), PLearn::TVec< T >::length(), PLearn::Variable::matValue, rows, and PLearn::TMat< T >::width().
{ real* ptr; real* inputptr; int r=0; for(int i=0; i<matValue.length(); i++) { ptr = matValue[i]; if(r<rows.length() && i==rows[r]) { for(int j=0; j<matValue.width(); j++) *ptr++ = 0; r++; } else { inputptr = input->matValue[i-r]; for(int j=0; j<matValue.width(); j++) *ptr++ = *inputptr++; } } }
OptionList & PLearn::InsertZerosVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 45 of file InsertZerosVariable.cc.
OptionMap & PLearn::InsertZerosVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 45 of file InsertZerosVariable.cc.
RemoteMethodMap & PLearn::InsertZerosVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 45 of file InsertZerosVariable.cc.
void PLearn::InsertZerosVariable::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be.
This needs to be overridden by every class that adds "complex" data members to the class, such as Vec
, Mat
, PP<Something>
, etc. Typical implementation:
void CLASS_OF_THIS::makeDeepCopyFromShallowCopy(CopiesMap& copies) { inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(complex_data_member1, copies); deepCopyField(complex_data_member2, copies); ... }
copies | A map used by the deep-copy mechanism to keep track of already-copied objects. |
Reimplemented from PLearn::UnaryVariable.
Definition at line 134 of file InsertZerosVariable.cc.
References PLearn::deepCopyField(), PLearn::UnaryVariable::makeDeepCopyFromShallowCopy(), and rows.
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(rows, copies); }
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 51 of file InsertZerosVariable.cc.
References PLearn::UnaryVariable::input, PLearn::Var::length(), PLearn::TVec< T >::length(), rows, and PLearn::Var::width().
void PLearn::InsertZerosVariable::rfprop | ( | ) | [virtual] |
Reimplemented from PLearn::Variable.
Definition at line 130 of file InsertZerosVariable.cc.
References PLERROR.
{ PLERROR("rfprop is not implemented for InsertZerosVariable"); }
void PLearn::InsertZerosVariable::setInput | ( | Var | the_input | ) | [inline] |
Set this Variable's input (simply call build after setting the new input).
Reimplemented from PLearn::UnaryVariable.
Definition at line 68 of file InsertZerosVariable.h.
{ input = the_input;}
void PLearn::InsertZerosVariable::symbolicBprop | ( | ) | [virtual] |
compute a piece of new Var graph that represents the symbolic derivative of this Var
Reimplemented from PLearn::Variable.
Definition at line 126 of file InsertZerosVariable.cc.
References PLERROR.
{ PLERROR("symbolicBprop is not implemented for InsertZerosVariable"); }
Reimplemented from PLearn::UnaryVariable.
Definition at line 55 of file InsertZerosVariable.h.
Definition at line 48 of file InsertZerosVariable.h.
Referenced by bprop(), build_(), fprop(), makeDeepCopyFromShallowCopy(), and recomputeSize().