PLearn 0.1
|
#include <MatrixSoftmaxLossVariable.h>
Public Member Functions | |
MatrixSoftmaxLossVariable () | |
Default constructor for persistence. | |
MatrixSoftmaxLossVariable (Variable *input1, Variable *input2) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual MatrixSoftmaxLossVariable * | 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 | bbprop () |
compute an approximation to diag(d^2/dinput^2) given diag(d^2/doutput^2), with diag(d^2/dinput^2) ~=~ (doutput/dinput)' diag(d^2/doutput^2) (doutput/dinput) In particular: if 'C' depends on 'y' and 'y' depends on x ... | |
virtual void | symbolicBprop () |
compute a piece of new Var graph that represents the symbolic derivative of this Var | |
virtual void | rfprop () |
Static Public Member Functions | |
static string | _classname_ () |
MatrixSoftmaxLossVariable. | |
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_ |
Protected Member Functions | |
void | build_ () |
This does the actual building. | |
Private Types | |
typedef BinaryVariable | inherited |
Definition at line 53 of file MatrixSoftmaxLossVariable.h.
typedef BinaryVariable PLearn::MatrixSoftmaxLossVariable::inherited [private] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 55 of file MatrixSoftmaxLossVariable.h.
PLearn::MatrixSoftmaxLossVariable::MatrixSoftmaxLossVariable | ( | ) | [inline] |
string PLearn::MatrixSoftmaxLossVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 52 of file MatrixSoftmaxLossVariable.cc.
OptionList & PLearn::MatrixSoftmaxLossVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 52 of file MatrixSoftmaxLossVariable.cc.
RemoteMethodMap & PLearn::MatrixSoftmaxLossVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 52 of file MatrixSoftmaxLossVariable.cc.
Reimplemented from PLearn::BinaryVariable.
Definition at line 52 of file MatrixSoftmaxLossVariable.cc.
Object * PLearn::MatrixSoftmaxLossVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 52 of file MatrixSoftmaxLossVariable.cc.
StaticInitializer MatrixSoftmaxLossVariable::_static_initializer_ & PLearn::MatrixSoftmaxLossVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 52 of file MatrixSoftmaxLossVariable.cc.
void PLearn::MatrixSoftmaxLossVariable::bbprop | ( | ) | [virtual] |
compute an approximation to diag(d^2/dinput^2) given diag(d^2/doutput^2), with diag(d^2/dinput^2) ~=~ (doutput/dinput)' diag(d^2/doutput^2) (doutput/dinput) In particular: if 'C' depends on 'y' and 'y' depends on x ...
d^2C/dx^2 = d^2C/dy^2 * (dy/dx)^2 + dC/dy * d^2y/dx^2 (diaghessian) (gradient)
Reimplemented from PLearn::Variable.
Definition at line 117 of file MatrixSoftmaxLossVariable.cc.
References PLERROR.
{ PLERROR("MatrixSoftmaxLossVariable::bbprop() not implemented"); }
void PLearn::MatrixSoftmaxLossVariable::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Definition at line 99 of file MatrixSoftmaxLossVariable.cc.
References PLearn::Variable::gradientdata, i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, j, PLearn::Variable::length(), PLearn::Var::length(), PLearn::safeexp(), and PLearn::Variable::valuedata.
{ for (int i=0; i<input2->length(); i++) { int classnum = (int)input2->valuedata[i]; real input_index = input1->matValue[classnum][i]; real vali = valuedata[i]; for(int j=0; j<input1->length(); j++) { if (j!=classnum){ input1->matGradient[j][i] = -gradientdata[i]*vali*vali*safeexp(input1->matValue[j][i]-input_index);} else input1->matGradient[j][i] = gradientdata[i]*vali*(1.-vali); } } }
void PLearn::MatrixSoftmaxLossVariable::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 61 of file MatrixSoftmaxLossVariable.cc.
References PLearn::BinaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::MatrixSoftmaxLossVariable::build_ | ( | ) | [protected] |
This does the actual building.
Reimplemented from PLearn::BinaryVariable.
Definition at line 68 of file MatrixSoftmaxLossVariable.cc.
References PLearn::BinaryVariable::input2, and PLERROR.
Referenced by build(), and MatrixSoftmaxLossVariable().
{ if (input2 && !input2->isVec()) PLERROR("In MatrixSoftmaxLossVariable: position must be a vector"); }
string PLearn::MatrixSoftmaxLossVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 52 of file MatrixSoftmaxLossVariable.cc.
static const PPath& PLearn::MatrixSoftmaxLossVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file MatrixSoftmaxLossVariable.h.
: void build_();
MatrixSoftmaxLossVariable * PLearn::MatrixSoftmaxLossVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 52 of file MatrixSoftmaxLossVariable.cc.
void PLearn::MatrixSoftmaxLossVariable::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 85 of file MatrixSoftmaxLossVariable.cc.
References i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, j, PLearn::Variable::length(), PLearn::Var::length(), PLearn::safeexp(), PLearn::sum(), and PLearn::Variable::valuedata.
{ for (int i=0; i<input2->length(); i++) { int classnum = (int)input2->valuedata[i]; real input_index = input1->matValue[classnum][i]; real sum=0; for(int j=0; j<input1->length(); j++) sum += safeexp(input1->matValue[j][i]-input_index); valuedata[i] = 1.0/sum; } }
OptionList & PLearn::MatrixSoftmaxLossVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 52 of file MatrixSoftmaxLossVariable.cc.
OptionMap & PLearn::MatrixSoftmaxLossVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 52 of file MatrixSoftmaxLossVariable.cc.
RemoteMethodMap & PLearn::MatrixSoftmaxLossVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 52 of file MatrixSoftmaxLossVariable.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 75 of file MatrixSoftmaxLossVariable.cc.
References PLearn::BinaryVariable::input2, PLearn::Var::length(), and PLearn::Var::width().
void PLearn::MatrixSoftmaxLossVariable::rfprop | ( | ) | [virtual] |
Reimplemented from PLearn::Variable.
Definition at line 129 of file MatrixSoftmaxLossVariable.cc.
References PLERROR.
{ PLERROR("MatrixSoftmaxLossVariable::rfprop() not implemented"); }
void PLearn::MatrixSoftmaxLossVariable::symbolicBprop | ( | ) | [virtual] |
compute a piece of new Var graph that represents the symbolic derivative of this Var
Reimplemented from PLearn::Variable.
Definition at line 123 of file MatrixSoftmaxLossVariable.cc.
References PLERROR.
{ PLERROR("MatrixSoftmaxLossVariable::symbolicBprop() not implemented"); }
Reimplemented from PLearn::BinaryVariable.
Definition at line 62 of file MatrixSoftmaxLossVariable.h.