PLearn 0.1
|
Let W, M and H be the inputs and nw the length of W. More...
#include <TransposedDoubleProductVariable.h>
Public Member Functions | |
TransposedDoubleProductVariable () | |
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //! | |
TransposedDoubleProductVariable (Var h, Var w, Var m) | |
Constructor initializing from input variables. | |
Var & | varH () |
Var & | varW () |
Var & | varM () |
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 string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual TransposedDoubleProductVariable * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Post-constructor. | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
Static Public Member Functions | |
static string | _classname_ () |
TransposedDoubleProductVariable. | |
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 Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
Private Types | |
typedef NaryVariable | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Let W, M and H be the inputs and nw the length of W.
* TransposedDoubleProductVariable * Then output(n,k) = sum_i{ sum_j { W(i,k)*M(j,k)*H(n,i+j*nw) } }
Definition at line 59 of file TransposedDoubleProductVariable.h.
typedef NaryVariable PLearn::TransposedDoubleProductVariable::inherited [private] |
Reimplemented from PLearn::NaryVariable.
Definition at line 61 of file TransposedDoubleProductVariable.h.
PLearn::TransposedDoubleProductVariable::TransposedDoubleProductVariable | ( | ) |
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
Default constructor, usually does nothing
Definition at line 53 of file TransposedDoubleProductVariable.cc.
{}
string PLearn::TransposedDoubleProductVariable::_classname_ | ( | ) | [static] |
TransposedDoubleProductVariable.
Reimplemented from PLearn::NaryVariable.
Definition at line 51 of file TransposedDoubleProductVariable.cc.
OptionList & PLearn::TransposedDoubleProductVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 51 of file TransposedDoubleProductVariable.cc.
RemoteMethodMap & PLearn::TransposedDoubleProductVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 51 of file TransposedDoubleProductVariable.cc.
Reimplemented from PLearn::NaryVariable.
Definition at line 51 of file TransposedDoubleProductVariable.cc.
Object * PLearn::TransposedDoubleProductVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 51 of file TransposedDoubleProductVariable.cc.
StaticInitializer TransposedDoubleProductVariable::_static_initializer_ & PLearn::TransposedDoubleProductVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 51 of file TransposedDoubleProductVariable.cc.
void PLearn::TransposedDoubleProductVariable::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Definition at line 97 of file TransposedDoubleProductVariable.cc.
References d, i, j, PLearn::TMat< T >::length(), m, PLearn::Variable::matGradient, n, varH(), varM(), varW(), w, and PLearn::TMat< T >::width().
{ Mat w = varW()->matValue, m = varM()->matValue, h = varH()->matValue, w_grad = varW()->matGradient, m_grad = varM()->matGradient, h_grad = varH()->matGradient, x_grad = matGradient; int nw = w.length(), nm = m.length(), nx = h.length(), d = w.width(); for(int n=0; n<nx; n++) for(int k=0; k<d; k++) for(int i=0; i<nw; i++) for(int j=0; j<nm; j++) { w_grad(i,k) += x_grad(n,k)*m(j,k)*h(n,i+j*nw); m_grad(j,k) += x_grad(n,k)*w(i,k)*h(n,i+j*nw); h_grad(n,i+j*nw) += x_grad(n,k)*w(i,k)*m(j,k); } }
void PLearn::TransposedDoubleProductVariable::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 130 of file TransposedDoubleProductVariable.cc.
References PLearn::NaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::TransposedDoubleProductVariable::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::NaryVariable.
Definition at line 170 of file TransposedDoubleProductVariable.cc.
References PLearn::Variable::length(), PLERROR, varH(), varM(), varW(), and PLearn::Variable::width().
Referenced by build(), and TransposedDoubleProductVariable().
{ // ### This method should do the real building of the object, // ### according to set 'options', in *any* situation. // ### Typical situations include: // ### - Initial building of an object from a few user-specified options // ### - Building of a "reloaded" object: i.e. from the complete set of // ### all serialised options. // ### - Updating or "re-building" of an object after a few "tuning" // ### options have been modified. // ### You should assume that the parent class' build_() has already been // ### called. if (varH().width() != varW().length()*varM().length()) PLERROR("The width of matrix H is incompatible with the lengths of matrix W and M in TranposedDoubleProductVariable"); if (varM().width() != varW().width()) PLERROR("Matrix W and M must have the same width in TranposedDoubleProduct"); }
string PLearn::TransposedDoubleProductVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 51 of file TransposedDoubleProductVariable.cc.
void PLearn::TransposedDoubleProductVariable::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::NaryVariable.
Definition at line 150 of file TransposedDoubleProductVariable.cc.
References PLearn::NaryVariable::declareOptions().
{ // ### Declare all of this object's options here. // ### For the "flags" of each option, you should typically specify // ### one of OptionBase::buildoption, OptionBase::learntoption or // ### OptionBase::tuningoption. If you don't provide one of these three, // ### this option will be ignored when loading values from a script. // ### You can also combine flags, for example with OptionBase::nosave: // ### (OptionBase::buildoption | OptionBase::nosave) // ### ex: // declareOption(ol, "myoption", &TransposedDoubleProductVariable::myoption, // OptionBase::buildoption, // "Help text describing this option"); // ... // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::TransposedDoubleProductVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::NaryVariable.
Definition at line 104 of file TransposedDoubleProductVariable.h.
:
//##### Protected Options ###############################################
TransposedDoubleProductVariable * PLearn::TransposedDoubleProductVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::NaryVariable.
Definition at line 51 of file TransposedDoubleProductVariable.cc.
void PLearn::TransposedDoubleProductVariable::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 75 of file TransposedDoubleProductVariable.cc.
References d, i, j, PLearn::TMat< T >::length(), m, PLearn::Variable::matValue, n, varH(), varM(), varW(), w, and PLearn::TMat< T >::width().
{ Mat w = varW()->matValue, m = varM()->matValue, h = varH()->matValue; int nw = w.length(), nm = m.length(), nx = h.length(), d = w.width(); for(int n=0; n<nx; n++) for(int k=0; k<d; k++) { matValue(n,k)=0.; for(int i=0; i<nw; i++) for(int j=0; j<nm; j++) matValue(n,k) += w(i,k)*m(j,k)*h(n,i+j*nw); } }
OptionList & PLearn::TransposedDoubleProductVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 51 of file TransposedDoubleProductVariable.cc.
OptionMap & PLearn::TransposedDoubleProductVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 51 of file TransposedDoubleProductVariable.cc.
RemoteMethodMap & PLearn::TransposedDoubleProductVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 51 of file TransposedDoubleProductVariable.cc.
void PLearn::TransposedDoubleProductVariable::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::NaryVariable.
Definition at line 136 of file TransposedDoubleProductVariable.cc.
References PLearn::NaryVariable::makeDeepCopyFromShallowCopy().
{ inherited::makeDeepCopyFromShallowCopy(copies); // ### Call deepCopyField on all "pointer-like" fields // ### that you wish to be deepCopied rather than // ### shallow-copied. // ### ex: // deepCopyField(trainvec, copies); // ### If you want to deepCopy a Var field: // varDeepCopyField(somevariable, 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 63 of file TransposedDoubleProductVariable.cc.
References PLearn::TVec< T >::length(), PLearn::TVec< T >::size(), and PLearn::NaryVariable::varray.
{ if (varray.size() > 0) { // l = varH()->length(); // the computed length of this Var //w = varW()->width(); // the computed width l = varray[0].length(); w = varray[1].width(); } else l = w = 0; }
Var& PLearn::TransposedDoubleProductVariable::varH | ( | ) | [inline] |
Var& PLearn::TransposedDoubleProductVariable::varM | ( | ) | [inline] |
Var& PLearn::TransposedDoubleProductVariable::varW | ( | ) | [inline] |
Reimplemented from PLearn::NaryVariable.
Definition at line 104 of file TransposedDoubleProductVariable.h.