PLearn 0.1
|
Affine transformation of a vector variable, from a weight and bias variable. More...
#include <BiasWeightAffineTransformVariable.h>
Public Member Functions | |
BiasWeightAffineTransformVariable () | |
Default constructor for persistence. | |
BiasWeightAffineTransformVariable (const VarArray &the_varray, bool the_transpose_weights=false) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual BiasWeightAffineTransformVariable * | deepCopy (CopiesMap &copies) const |
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. | |
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 () |
compute output given input | |
virtual void | bprop () |
virtual void | symbolicBprop () |
compute a piece of new Var graph that represents the symbolic derivative of this Var | |
Static Public Member Functions | |
static string | _classname_ () |
NaryVariable. | |
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 | |
bool | transpose_weights |
Indication that the transpose of the weights should be used for the linear transformation. | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
void | build_ () |
Object-specific post-constructor. | |
Protected Attributes | |
Var | vec |
Input vector. | |
Var | weights |
Weight matrix. | |
Var | bias |
Bias vector. | |
Private Types | |
typedef NaryVariable | inherited |
Affine transformation of a vector variable, from a weight and bias variable.
Should work for both column and row vectors: result vector will be of same kind (row or col) Will compute b + x.T (if you consider b and x to be row vectors) or b + x.T' if transpose_weights is true.
Definition at line 56 of file BiasWeightAffineTransformVariable.h.
typedef NaryVariable PLearn::BiasWeightAffineTransformVariable::inherited [private] |
Reimplemented from PLearn::NaryVariable.
Definition at line 58 of file BiasWeightAffineTransformVariable.h.
PLearn::BiasWeightAffineTransformVariable::BiasWeightAffineTransformVariable | ( | ) | [inline] |
Default constructor for persistence.
Definition at line 70 of file BiasWeightAffineTransformVariable.h.
{}
PLearn::BiasWeightAffineTransformVariable::BiasWeightAffineTransformVariable | ( | const VarArray & | the_varray, |
bool | the_transpose_weights = false |
||
) |
Definition at line 54 of file BiasWeightAffineTransformVariable.cc.
References build_().
: inherited(the_varray, (the_varray[0]->size() == 1) ? the_varray[2]->size() : (the_varray[0]->isRowVec() ? 1 : the_varray[2]->size()), (the_varray[0]->size() == 1) ? 1 : (the_varray[0]->isRowVec() ? the_varray[2]->size() : 1)), transpose_weights(the_transpose_weights) { build_(); }
string PLearn::BiasWeightAffineTransformVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 52 of file BiasWeightAffineTransformVariable.cc.
OptionList & PLearn::BiasWeightAffineTransformVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 52 of file BiasWeightAffineTransformVariable.cc.
RemoteMethodMap & PLearn::BiasWeightAffineTransformVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 52 of file BiasWeightAffineTransformVariable.cc.
Reimplemented from PLearn::NaryVariable.
Definition at line 52 of file BiasWeightAffineTransformVariable.cc.
Object * PLearn::BiasWeightAffineTransformVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 52 of file BiasWeightAffineTransformVariable.cc.
StaticInitializer BiasWeightAffineTransformVariable::_static_initializer_ & PLearn::BiasWeightAffineTransformVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 52 of file BiasWeightAffineTransformVariable.cc.
void PLearn::BiasWeightAffineTransformVariable::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Definition at line 127 of file BiasWeightAffineTransformVariable.cc.
References bias, PLearn::externalProductAcc(), PLearn::Variable::gradient, PLearn::productAcc(), transpose_weights, PLearn::transposeProductAcc(), vec, and weights.
{ bias->gradient += gradient; if(!vec->dont_bprop_here) { if(transpose_weights) transposeProductAcc(vec->gradient, weights->matValue, gradient); else productAcc(vec->gradient, weights->matValue, gradient); } if(transpose_weights) externalProductAcc(weights->matGradient, gradient, vec->value); else externalProductAcc(weights->matGradient, vec->value, gradient); }
void PLearn::BiasWeightAffineTransformVariable::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::NaryVariable.
Definition at line 79 of file BiasWeightAffineTransformVariable.cc.
References PLearn::NaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::BiasWeightAffineTransformVariable::build_ | ( | ) | [protected] |
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::NaryVariable.
Definition at line 86 of file BiasWeightAffineTransformVariable.cc.
References bias, PLearn::Var::length(), PLearn::TVec< T >::length(), PLERROR, transpose_weights, PLearn::NaryVariable::varray, vec, weights, and PLearn::Var::width().
Referenced by BiasWeightAffineTransformVariable(), and build().
{ if(varray.length() != 3) PLERROR("In BiasWeightAffineTransformVariable():build_(): needs an input" " vector, a weight matrix and a bias vector"); vec = varray[0]; weights = varray[1]; bias = varray[2]; if (!vec->isVec()) PLERROR("In BiasWeightAffineTransformVariable: expecting a vector Var" " for the input vector"); if(vec->size() != (!transpose_weights ? weights->length() : weights->width())) PLERROR("In BiasWeightAffineTransformVariable: weight matrix has" " incompatible size"); }
string PLearn::BiasWeightAffineTransformVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 52 of file BiasWeightAffineTransformVariable.cc.
static const PPath& PLearn::BiasWeightAffineTransformVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 74 of file BiasWeightAffineTransformVariable.h.
:
BiasWeightAffineTransformVariable * PLearn::BiasWeightAffineTransformVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::NaryVariable.
Definition at line 52 of file BiasWeightAffineTransformVariable.cc.
void PLearn::BiasWeightAffineTransformVariable::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 114 of file BiasWeightAffineTransformVariable.cc.
References bias, PLearn::productAcc(), transpose_weights, PLearn::transposeProductAcc(), PLearn::Variable::value, vec, and weights.
{ value << bias->value; // Seems contradictive, but we are considering x.T versus x.T', // not T.x versus T'.x, for consistency with AffineTransformVariable! if(transpose_weights) productAcc(value, weights->matValue, vec->value); else transposeProductAcc(value, weights->matValue, vec->value); }
OptionList & PLearn::BiasWeightAffineTransformVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 52 of file BiasWeightAffineTransformVariable.cc.
OptionMap & PLearn::BiasWeightAffineTransformVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 52 of file BiasWeightAffineTransformVariable.cc.
RemoteMethodMap & PLearn::BiasWeightAffineTransformVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 52 of file BiasWeightAffineTransformVariable.cc.
void PLearn::BiasWeightAffineTransformVariable::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::NaryVariable.
Definition at line 69 of file BiasWeightAffineTransformVariable.cc.
References bias, PLearn::NaryVariable::makeDeepCopyFromShallowCopy(), PLearn::varDeepCopyField(), vec, and weights.
{ inherited::makeDeepCopyFromShallowCopy(copies); varDeepCopyField(vec, copies); varDeepCopyField(weights, copies); varDeepCopyField(bias, 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 104 of file BiasWeightAffineTransformVariable.cc.
void PLearn::BiasWeightAffineTransformVariable::symbolicBprop | ( | ) | [virtual] |
compute a piece of new Var graph that represents the symbolic derivative of this Var
Reimplemented from PLearn::Variable.
Definition at line 145 of file BiasWeightAffineTransformVariable.cc.
References PLERROR.
{ PLERROR("BiasWeightAffineTransformVariable::symbolicBprop() not implemented"); }
Reimplemented from PLearn::NaryVariable.
Definition at line 74 of file BiasWeightAffineTransformVariable.h.
Var PLearn::BiasWeightAffineTransformVariable::bias [protected] |
Bias vector.
Definition at line 91 of file BiasWeightAffineTransformVariable.h.
Referenced by bprop(), build_(), fprop(), makeDeepCopyFromShallowCopy(), and recomputeSize().
Indication that the transpose of the weights should be used for the linear transformation.
The transformation then corresponds to row-wise scalar products, instead of column wise.
Definition at line 66 of file BiasWeightAffineTransformVariable.h.
Var PLearn::BiasWeightAffineTransformVariable::vec [protected] |
Input vector.
Definition at line 87 of file BiasWeightAffineTransformVariable.h.
Referenced by bprop(), build_(), fprop(), makeDeepCopyFromShallowCopy(), and recomputeSize().
Weight matrix.
Definition at line 89 of file BiasWeightAffineTransformVariable.h.
Referenced by bprop(), build_(), fprop(), makeDeepCopyFromShallowCopy(), and recomputeSize().