PLearn 0.1
|
#include <MatrixSoftmaxVariable.h>
Public Member Functions | |
MatrixSoftmaxVariable () | |
Default constructor for persistence. | |
MatrixSoftmaxVariable (Variable *input) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual MatrixSoftmaxVariable * | deepCopy (CopiesMap &copies) const |
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 () |
Nothing to do by default. | |
virtual void | bprop () |
Nothing to do by default. | |
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_ () |
MatrixSoftmaxVariable. | |
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_ |
Private Types | |
typedef UnaryVariable | inherited |
Definition at line 52 of file MatrixSoftmaxVariable.h.
typedef UnaryVariable PLearn::MatrixSoftmaxVariable::inherited [private] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 54 of file MatrixSoftmaxVariable.h.
PLearn::MatrixSoftmaxVariable::MatrixSoftmaxVariable | ( | ) | [inline] |
PLearn::MatrixSoftmaxVariable::MatrixSoftmaxVariable | ( | Variable * | input | ) |
string PLearn::MatrixSoftmaxVariable::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file MatrixSoftmaxVariable.cc.
OptionList & PLearn::MatrixSoftmaxVariable::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file MatrixSoftmaxVariable.cc.
RemoteMethodMap & PLearn::MatrixSoftmaxVariable::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file MatrixSoftmaxVariable.cc.
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file MatrixSoftmaxVariable.cc.
Object * PLearn::MatrixSoftmaxVariable::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file MatrixSoftmaxVariable.cc.
StaticInitializer MatrixSoftmaxVariable::_static_initializer_ & PLearn::MatrixSoftmaxVariable::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file MatrixSoftmaxVariable.cc.
void PLearn::MatrixSoftmaxVariable::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 105 of file MatrixSoftmaxVariable.cc.
References PLERROR.
{ PLERROR("MatrixSofmaxVariable::bbprop() not implemented"); }
void PLearn::MatrixSoftmaxVariable::bprop | ( | ) | [virtual] |
Nothing to do by default.
Reimplemented from PLearn::UnaryVariable.
Definition at line 88 of file MatrixSoftmaxVariable.cc.
References i, PLearn::UnaryVariable::input, j, PLearn::Var::length(), PLearn::Variable::length(), PLearn::Variable::matGradient, PLearn::Variable::matValue, and PLearn::Var::width().
{ for(int i=0; i<input->width(); i++) for(int j=0; j<input->length(); j++) { real vali = matValue[j][i]; for(int k=0; k<length(); k++) { if(k!=j) input->matGradient[j][i] -= matGradient[k][i]*vali*matValue[k][i]; else input->matGradient[j][i] += matGradient[j][i]*vali*(1.-vali); } } }
string PLearn::MatrixSoftmaxVariable::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file MatrixSoftmaxVariable.cc.
static const PPath& PLearn::MatrixSoftmaxVariable::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 61 of file MatrixSoftmaxVariable.h.
MatrixSoftmaxVariable * PLearn::MatrixSoftmaxVariable::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file MatrixSoftmaxVariable.cc.
void PLearn::MatrixSoftmaxVariable::fprop | ( | ) | [virtual] |
Nothing to do by default.
Reimplemented from PLearn::UnaryVariable.
Definition at line 69 of file MatrixSoftmaxVariable.cc.
References PLearn::columnMax(), PLearn::fast_exact_is_equal(), i, PLearn::UnaryVariable::input, j, PLearn::Var::length(), PLearn::Variable::matValue, PLERROR, PLearn::safeexp(), PLearn::Var::width(), and PLearn::Variable::width().
{ Vec column_max(width()); columnMax(input->matValue, column_max); for(int j=0; j<input->width(); j++) { real s = 0; real curmax = column_max[j]; for(int i=0; i<input->length(); i++) s += (matValue[i][j] = safeexp(input->matValue[i][j]-curmax)); if (fast_exact_is_equal(s, 0)) PLERROR("trying to divide by 0 in softmax"); s = 1.0 / s; for(int i=0; i<input->length(); i++) matValue[i][j] *= s; } }
OptionList & PLearn::MatrixSoftmaxVariable::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file MatrixSoftmaxVariable.cc.
OptionMap & PLearn::MatrixSoftmaxVariable::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file MatrixSoftmaxVariable.cc.
RemoteMethodMap & PLearn::MatrixSoftmaxVariable::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::UnaryVariable.
Definition at line 53 of file MatrixSoftmaxVariable.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 59 of file MatrixSoftmaxVariable.cc.
References PLearn::UnaryVariable::input, PLearn::Var::length(), and PLearn::Var::width().
void PLearn::MatrixSoftmaxVariable::rfprop | ( | ) | [virtual] |
Reimplemented from PLearn::Variable.
Definition at line 118 of file MatrixSoftmaxVariable.cc.
References PLERROR.
{ PLERROR("SofmaxVariable::rfprop() not implemented"); }
void PLearn::MatrixSoftmaxVariable::symbolicBprop | ( | ) | [virtual] |
compute a piece of new Var graph that represents the symbolic derivative of this Var
Reimplemented from PLearn::Variable.
Definition at line 111 of file MatrixSoftmaxVariable.cc.
References PLERROR.
{ PLERROR("MatrixSofmaxVariable::symbolicBprop() not implemented"); }
Reimplemented from PLearn::UnaryVariable.
Definition at line 61 of file MatrixSoftmaxVariable.h.