PLearn 0.1
|
The first sentence should be a BRIEF DESCRIPTION of what the class does. More...
#include <SumVarianceOfLinearTransformedBernoullis.h>
Public Member Functions | |
SumVarianceOfLinearTransformedBernoullis () | |
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //! | |
SumVarianceOfLinearTransformedBernoullis (Variable *input1, Variable *input2, bool call_build_=true) | |
Constructor initializing from two input variables. | |
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 SumVarianceOfLinearTransformedBernoullis * | 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_ () |
SumVarianceOfLinearTransformedBernoullis. | |
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 BinaryVariable | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. | |
void | computeWsqnorm () |
Private Attributes | |
Vec | Wsqnorm |
Vec | Wsqnormgrad |
The first sentence should be a BRIEF DESCRIPTION of what the class does.
* SumVarianceOfLinearTransformedBernoullis * Place the rest of the class programmer documentation here. Doxygen supports Javadoc-style comments. See http://www.doxygen.org/manual.html
Definition at line 60 of file SumVarianceOfLinearTransformedBernoullis.h.
typedef BinaryVariable PLearn::SumVarianceOfLinearTransformedBernoullis::inherited [private] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file SumVarianceOfLinearTransformedBernoullis.h.
PLearn::SumVarianceOfLinearTransformedBernoullis::SumVarianceOfLinearTransformedBernoullis | ( | ) |
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
Default constructor.
Definition at line 65 of file SumVarianceOfLinearTransformedBernoullis.cc.
: inherited(0,0,1,1) {}
string PLearn::SumVarianceOfLinearTransformedBernoullis::_classname_ | ( | ) | [static] |
SumVarianceOfLinearTransformedBernoullis.
Reimplemented from PLearn::BinaryVariable.
Definition at line 63 of file SumVarianceOfLinearTransformedBernoullis.cc.
OptionList & PLearn::SumVarianceOfLinearTransformedBernoullis::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 63 of file SumVarianceOfLinearTransformedBernoullis.cc.
RemoteMethodMap & PLearn::SumVarianceOfLinearTransformedBernoullis::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 63 of file SumVarianceOfLinearTransformedBernoullis.cc.
Reimplemented from PLearn::BinaryVariable.
Definition at line 63 of file SumVarianceOfLinearTransformedBernoullis.cc.
Object * PLearn::SumVarianceOfLinearTransformedBernoullis::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 63 of file SumVarianceOfLinearTransformedBernoullis.cc.
StaticInitializer SumVarianceOfLinearTransformedBernoullis::_static_initializer_ & PLearn::SumVarianceOfLinearTransformedBernoullis::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 63 of file SumVarianceOfLinearTransformedBernoullis.cc.
void PLearn::SumVarianceOfLinearTransformedBernoullis::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Definition at line 145 of file SumVarianceOfLinearTransformedBernoullis.cc.
References computeWsqnorm(), d, PLearn::TVec< T >::data(), PLearn::TVec< T >::fill(), PLearn::Variable::gradient, i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, j, PLearn::TMat< T >::length(), m, PLearn::P(), PLearn::TVec< T >::resize(), PLearn::TMat< T >::width(), Wsqnorm, and Wsqnormgrad.
{ Mat P = input1->matValue; Mat Pgrad = input1->matGradient; Mat W = input2->matValue; Mat Wgrad = input2->matGradient; int l = P.length(); int m = W.length(); int d = W.width(); real gr = gradient[0]; computeWsqnorm(); const real* pWsqnorm = Wsqnorm.data(); Wsqnormgrad.resize(m); Wsqnormgrad.fill(0); real* pWsqnormgrad = Wsqnormgrad.data(); for(int i=0; i<l; i++) { const real* P_i = P[i]; real* Pgrad_i = Pgrad[i]; for(int k=0; k<m; k++) { real P_ik = P_i[k]; Pgrad_i[k] += gr*(1-2*P_ik)*pWsqnorm[k]; pWsqnormgrad[k] += P_ik*(1-P_ik); } } for(int k=0; k<m; k++) { real coefk = 2*gr*pWsqnormgrad[k]; const real* W_k = W[k]; real* Wgrad_k = Wgrad[k]; for(int j=0; j<d; j++) Wgrad_k[j] += coefk*W_k[j]; } }
void PLearn::SumVarianceOfLinearTransformedBernoullis::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 194 of file SumVarianceOfLinearTransformedBernoullis.cc.
References PLearn::BinaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::SumVarianceOfLinearTransformedBernoullis::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::BinaryVariable.
Definition at line 236 of file SumVarianceOfLinearTransformedBernoullis.cc.
Referenced by build(), and SumVarianceOfLinearTransformedBernoullis().
{ // ### 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. }
string PLearn::SumVarianceOfLinearTransformedBernoullis::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 63 of file SumVarianceOfLinearTransformedBernoullis.cc.
void PLearn::SumVarianceOfLinearTransformedBernoullis::computeWsqnorm | ( | ) | [private] |
Definition at line 97 of file SumVarianceOfLinearTransformedBernoullis.cc.
References d, PLearn::TVec< T >::data(), PLearn::BinaryVariable::input2, j, PLearn::TMat< T >::length(), m, PLearn::TVec< T >::resize(), PLearn::TMat< T >::width(), and Wsqnorm.
Referenced by bprop(), and fprop().
{ Mat W = input2->matValue; int m = W.length(); int d = W.width(); Wsqnorm.resize(m); real* pWsqnorm = Wsqnorm.data(); for(int k=0; k<m; k++) { real* Wk = W[k]; real sqnorm = 0; for(int j=0; j<d; j++) { real Wkj = Wk[j]; sqnorm += Wkj*Wkj; } pWsqnorm[k] = sqnorm; } }
void PLearn::SumVarianceOfLinearTransformedBernoullis::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::BinaryVariable.
Definition at line 216 of file SumVarianceOfLinearTransformedBernoullis.cc.
References PLearn::BinaryVariable::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", &SumVarianceOfLinearTransformedBernoullis::myoption, // OptionBase::buildoption, // "Help text describing this option"); // ... // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::SumVarianceOfLinearTransformedBernoullis::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 104 of file SumVarianceOfLinearTransformedBernoullis.h.
:
//##### Protected Options ###############################################
SumVarianceOfLinearTransformedBernoullis * PLearn::SumVarianceOfLinearTransformedBernoullis::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 63 of file SumVarianceOfLinearTransformedBernoullis.cc.
void PLearn::SumVarianceOfLinearTransformedBernoullis::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 119 of file SumVarianceOfLinearTransformedBernoullis.cc.
References computeWsqnorm(), PLearn::TVec< T >::data(), i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Var::length(), PLearn::TMat< T >::length(), m, PLearn::P(), PLERROR, PLearn::Variable::value, PLearn::TMat< T >::width(), and Wsqnorm.
{ Mat P = input1->matValue; int l = P.length(); int m = P.width(); if(m!=input2.length()) PLERROR("Incompatible sizes: width of P (input1) must equal length of W (input2)"); computeWsqnorm(); const real* pWsqnorm = Wsqnorm.data(); double out = 0; for(int i=0; i<l; i++) { const real* P_i = P[i]; for(int k=0; k<m; k++) { real P_ik = P_i[k]; out += P_ik*(1-P_ik)*pWsqnorm[k]; } } value[0] = out; }
OptionList & PLearn::SumVarianceOfLinearTransformedBernoullis::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 63 of file SumVarianceOfLinearTransformedBernoullis.cc.
OptionMap & PLearn::SumVarianceOfLinearTransformedBernoullis::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 63 of file SumVarianceOfLinearTransformedBernoullis.cc.
RemoteMethodMap & PLearn::SumVarianceOfLinearTransformedBernoullis::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 63 of file SumVarianceOfLinearTransformedBernoullis.cc.
void PLearn::SumVarianceOfLinearTransformedBernoullis::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::BinaryVariable.
Definition at line 200 of file SumVarianceOfLinearTransformedBernoullis.cc.
References PLearn::deepCopyField(), PLearn::BinaryVariable::makeDeepCopyFromShallowCopy(), Wsqnorm, and Wsqnormgrad.
{ inherited::makeDeepCopyFromShallowCopy(copies); // ### Call deepCopyField on all "pointer-like" fields // ### that you wish to be deepCopied rather than // ### shallow-copied. // ### ex: // deepCopyField(trainvec, copies); deepCopyField(Wsqnorm, copies); deepCopyField(Wsqnormgrad, copies); // ### If you want to deepCopy a Var field: // varDeepCopyField(somevariable, copies); }
void PLearn::SumVarianceOfLinearTransformedBernoullis::recomputeSize | ( | int & | l, |
int & | w | ||
) | const [virtual] |
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 91 of file SumVarianceOfLinearTransformedBernoullis.cc.
{ l = 1; w = 1; }
Reimplemented from PLearn::BinaryVariable.
Definition at line 104 of file SumVarianceOfLinearTransformedBernoullis.h.
Definition at line 138 of file SumVarianceOfLinearTransformedBernoullis.h.
Referenced by bprop(), computeWsqnorm(), fprop(), and makeDeepCopyFromShallowCopy().
Definition at line 139 of file SumVarianceOfLinearTransformedBernoullis.h.
Referenced by bprop(), and makeDeepCopyFromShallowCopy().