PLearn 0.1
|
#include <AffineTransformVariable.h>
Public Member Functions | |
AffineTransformVariable () | |
Default constructor for persistence. | |
AffineTransformVariable (Variable *vec, Variable *transformation, bool call_build_=true) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual AffineTransformVariable * | 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 () |
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_ () |
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 | force_row_vec |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declare options (data fields) for the class. | |
Private Types | |
typedef BinaryVariable | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Definition at line 54 of file AffineTransformVariable.h.
typedef BinaryVariable PLearn::AffineTransformVariable::inherited [private] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 56 of file AffineTransformVariable.h.
PLearn::AffineTransformVariable::AffineTransformVariable | ( | ) | [inline] |
PLearn::AffineTransformVariable::AffineTransformVariable | ( | Variable * | vec, |
Variable * | transformation, | ||
bool | call_build_ = true |
||
) |
Definition at line 65 of file AffineTransformVariable.cc.
References build_().
: inherited(vec, transformation, vec->isScalar() || vec->isColumnVec() ? transformation->width() : 1, vec->isScalar() || vec->isColumnVec() ? 1 : transformation->width(), call_build_), force_row_vec(false) { if (call_build_) build_(); }
string PLearn::AffineTransformVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 60 of file AffineTransformVariable.cc.
OptionList & PLearn::AffineTransformVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 60 of file AffineTransformVariable.cc.
RemoteMethodMap & PLearn::AffineTransformVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 60 of file AffineTransformVariable.cc.
Reimplemented from PLearn::BinaryVariable.
Definition at line 60 of file AffineTransformVariable.cc.
Object * PLearn::AffineTransformVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 60 of file AffineTransformVariable.cc.
StaticInitializer AffineTransformVariable::_static_initializer_ & PLearn::AffineTransformVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 60 of file AffineTransformVariable.cc.
void PLearn::AffineTransformVariable::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Definition at line 144 of file AffineTransformVariable.cc.
References PLearn::externalProductAcc(), PLearn::TMat< T >::firstRow(), PLearn::Variable::gradient, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::TMat< T >::length(), PLearn::productAcc(), and PLearn::TMat< T >::subMatRows().
{ Mat& afftr = input2->matValue; int l = afftr.length(); // Vec bias = afftr.firstRow(); Mat lintr = afftr.subMatRows(1,l-1); Mat& afftr_g = input2->matGradient; Vec bias_g = afftr_g.firstRow(); Mat lintr_g = afftr_g.subMatRows(1,l-1); bias_g += gradient; if(!input1->dont_bprop_here) productAcc(input1->gradient, lintr, gradient); externalProductAcc(lintr_g, input1->value, gradient); }
void PLearn::AffineTransformVariable::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::BinaryVariable.
Definition at line 83 of file AffineTransformVariable.cc.
References PLearn::BinaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::AffineTransformVariable::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::BinaryVariable.
Definition at line 92 of file AffineTransformVariable.cc.
References PLearn::BinaryVariable::input1, and PLERROR.
Referenced by AffineTransformVariable(), and build().
{ // input1 is vec from constructor if (input1 && !input1->isVec()) PLERROR("In AffineTransformVariable: expecting a vector Var (row or column) as first argument"); }
string PLearn::AffineTransformVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 60 of file AffineTransformVariable.cc.
void PLearn::AffineTransformVariable::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
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::BinaryVariable.
Definition at line 102 of file AffineTransformVariable.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::BinaryVariable::declareOptions(), and force_row_vec.
{ declareOption(ol, "force_row_vec", &AffineTransformVariable::force_row_vec, OptionBase::buildoption, "If set to true, then the resulting vector will always be a row\n" "vector, even when the input is a column or a scalar."); inherited::declareOptions(ol); }
static const PPath& PLearn::AffineTransformVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 70 of file AffineTransformVariable.h.
:
AffineTransformVariable * PLearn::AffineTransformVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 60 of file AffineTransformVariable.cc.
void PLearn::AffineTransformVariable::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 134 of file AffineTransformVariable.cc.
References PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Var::length(), PLearn::transposeProductAcc(), and PLearn::Variable::value.
{ value << input2->matValue.firstRow(); Mat lintransform = input2->matValue.subMatRows(1,input2->length()-1); transposeProductAcc(value, lintransform, input1->value); }
OptionList & PLearn::AffineTransformVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 60 of file AffineTransformVariable.cc.
OptionMap & PLearn::AffineTransformVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 60 of file AffineTransformVariable.cc.
RemoteMethodMap & PLearn::AffineTransformVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 60 of file AffineTransformVariable.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 115 of file AffineTransformVariable.cc.
References force_row_vec, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, and PLearn::Var::width().
{ if (input1 && input2) { if (force_row_vec || (!input1->isScalar() && input1->isRowVec())) { // Result is a row vector. l = 1; w = input2->width(); } else { // Result is a column vector. l = input2->width(); w = 1; } } else l = w = 0; }
void PLearn::AffineTransformVariable::symbolicBprop | ( | ) | [virtual] |
compute a piece of new Var graph that represents the symbolic derivative of this Var
Reimplemented from PLearn::Variable.
Definition at line 162 of file AffineTransformVariable.cc.
References PLERROR.
{ PLERROR("AffineTransformVariable::symbolicBprop() not implemented"); }
Reimplemented from PLearn::BinaryVariable.
Definition at line 70 of file AffineTransformVariable.h.
Definition at line 62 of file AffineTransformVariable.h.
Referenced by declareOptions(), and recomputeSize().