PLearn 0.1
|
Log of SoftSoftMaxVariable (see SoftSoftMaxVariable for more details) More...
#include <LogSoftSoftMaxVariable.h>
Public Member Functions | |
LogSoftSoftMaxVariable () | |
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //! | |
LogSoftSoftMaxVariable (Variable *input1, Variable *input2) | |
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 LogSoftSoftMaxVariable * | 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_ () |
LogSoftSoftMaxVariable. | |
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. |
Log of SoftSoftMaxVariable (see SoftSoftMaxVariable for more details)
Definition at line 58 of file LogSoftSoftMaxVariable.h.
typedef BinaryVariable PLearn::LogSoftSoftMaxVariable::inherited [private] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 60 of file LogSoftSoftMaxVariable.h.
PLearn::LogSoftSoftMaxVariable::LogSoftSoftMaxVariable | ( | ) | [inline] |
### 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 72 of file LogSoftSoftMaxVariable.h.
{}
string PLearn::LogSoftSoftMaxVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 51 of file LogSoftSoftMaxVariable.cc.
OptionList & PLearn::LogSoftSoftMaxVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 51 of file LogSoftSoftMaxVariable.cc.
RemoteMethodMap & PLearn::LogSoftSoftMaxVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 51 of file LogSoftSoftMaxVariable.cc.
Reimplemented from PLearn::BinaryVariable.
Definition at line 51 of file LogSoftSoftMaxVariable.cc.
Object * PLearn::LogSoftSoftMaxVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 51 of file LogSoftSoftMaxVariable.cc.
StaticInitializer LogSoftSoftMaxVariable::_static_initializer_ & PLearn::LogSoftSoftMaxVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 51 of file LogSoftSoftMaxVariable.cc.
void PLearn::LogSoftSoftMaxVariable::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Definition at line 90 of file LogSoftSoftMaxVariable.cc.
References PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, j, PLearn::TMat< T >::length(), PLearn::Variable::matGradient, PLearn::Variable::matValue, n, PLearn::safeexp(), and PLearn::TMat< T >::width().
{ Mat X = input1->matValue, A = input2->matValue, grad_X = input1->matGradient, grad_A = input2->matGradient; real temp; //chacun des exemples de X for (int n=0; n<X.length(); n++) //chaque coordonné dun exemple //correspond au gradient for (int k=0; k<X.width(); k++) //même exemple, coordonnée aussi // correspond à un exemple for (int j=0; j<X.width(); j++) { temp = matGradient(n,j)*safeexp(matValue(n,j) + X(n,k) + A(j,k) - X(n,j)); if(k==j) grad_X(n,k) += matGradient(n,j)*(1.-safeexp(matValue(n,k))); else grad_X(n,k) -= temp; grad_A(j,k) -= temp; } }
void PLearn::LogSoftSoftMaxVariable::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 124 of file LogSoftSoftMaxVariable.cc.
References PLearn::BinaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::LogSoftSoftMaxVariable::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::BinaryVariable.
Definition at line 167 of file LogSoftSoftMaxVariable.cc.
References PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Var::length(), PLERROR, and PLearn::Var::width().
Referenced by build(), and LogSoftSoftMaxVariable().
{ // ### 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 (input2.length() != input1.width() || input2.width() != input1.width()) PLERROR("Length and width of input2 must be equal to width of input1 in LogSoftSoftMaxVariable"); }
string PLearn::LogSoftSoftMaxVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 51 of file LogSoftSoftMaxVariable.cc.
void PLearn::LogSoftSoftMaxVariable::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::BinaryVariable.
Definition at line 147 of file LogSoftSoftMaxVariable.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", &LogSoftSoftMaxVariable::myoption, // OptionBase::buildoption, // "Help text describing this option"); // ... // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::LogSoftSoftMaxVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 96 of file LogSoftSoftMaxVariable.h.
:
//##### Protected Options ###############################################
LogSoftSoftMaxVariable * PLearn::LogSoftSoftMaxVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 51 of file LogSoftSoftMaxVariable.cc.
void PLearn::LogSoftSoftMaxVariable::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 72 of file LogSoftSoftMaxVariable.cc.
References i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::TMat< T >::length(), PLearn::Variable::matValue, n, PLearn::safeexp(), PLearn::safelog(), PLearn::sum(), and PLearn::TMat< T >::width().
{ Mat X = input1->matValue, A = input2->matValue; real sum; for (int n=0; n<X.length(); n++) for (int k=0; k<X.width(); k++) { sum=0; for (int i=0; i<X.width(); i++) sum += safeexp(X(n,i) + A(k,i)); matValue(n,k) = X(n,k) - safelog(sum); } }
OptionList & PLearn::LogSoftSoftMaxVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 51 of file LogSoftSoftMaxVariable.cc.
OptionMap & PLearn::LogSoftSoftMaxVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 51 of file LogSoftSoftMaxVariable.cc.
RemoteMethodMap & PLearn::LogSoftSoftMaxVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 51 of file LogSoftSoftMaxVariable.cc.
void PLearn::LogSoftSoftMaxVariable::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::BinaryVariable.
Definition at line 130 of file LogSoftSoftMaxVariable.cc.
References PLearn::BinaryVariable::makeDeepCopyFromShallowCopy(), and PLERROR.
{ 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); // ### Remove this line when you have fully implemented this method. PLERROR("LogSoftSoftMaxVariable::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); }
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 62 of file LogSoftSoftMaxVariable.cc.
References PLearn::BinaryVariable::input1, PLearn::Var::length(), and PLearn::Var::width().
{ if (input1) { l = input1->length(); // the computed length of this Var w = input1->width(); // the computed width } else l = w = 0; }
Reimplemented from PLearn::BinaryVariable.
Definition at line 96 of file LogSoftSoftMaxVariable.h.