PLearn 0.1
|
#include <MatrixOneHotSquaredLoss.h>
Public Member Functions | |
MatrixOneHotSquaredLoss () | |
Default constructor for persistence. | |
MatrixOneHotSquaredLoss (Variable *netout, Variable *classnum, real coldval=0., real hotval=1.) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual MatrixOneHotSquaredLoss * | 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 | symbolicBprop () |
compute a piece of new Var graph that represents the symbolic derivative of this Var | |
Static Public Member Functions | |
static string | _classname_ () |
MatrixOneHotSquaredLoss. | |
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 void | declareOptions (OptionList &ol) |
Declare options (data fields) for the class. | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
void | build_ () |
This does the actual building. | |
Protected Attributes | |
real | coldval_ |
real | hotval_ |
Private Types | |
typedef BinaryVariable | inherited |
Definition at line 52 of file MatrixOneHotSquaredLoss.h.
typedef BinaryVariable PLearn::MatrixOneHotSquaredLoss::inherited [private] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 54 of file MatrixOneHotSquaredLoss.h.
PLearn::MatrixOneHotSquaredLoss::MatrixOneHotSquaredLoss | ( | ) |
Default constructor for persistence.
Definition at line 55 of file MatrixOneHotSquaredLoss.cc.
string PLearn::MatrixOneHotSquaredLoss::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 53 of file MatrixOneHotSquaredLoss.cc.
OptionList & PLearn::MatrixOneHotSquaredLoss::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 53 of file MatrixOneHotSquaredLoss.cc.
RemoteMethodMap & PLearn::MatrixOneHotSquaredLoss::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 53 of file MatrixOneHotSquaredLoss.cc.
Reimplemented from PLearn::BinaryVariable.
Definition at line 53 of file MatrixOneHotSquaredLoss.cc.
Object * PLearn::MatrixOneHotSquaredLoss::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 53 of file MatrixOneHotSquaredLoss.cc.
StaticInitializer MatrixOneHotSquaredLoss::_static_initializer_ & PLearn::MatrixOneHotSquaredLoss::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 53 of file MatrixOneHotSquaredLoss.cc.
void PLearn::MatrixOneHotSquaredLoss::bprop | ( | ) | [virtual] |
Implements PLearn::Variable.
Definition at line 110 of file MatrixOneHotSquaredLoss.cc.
References coldval_, PLearn::fast_exact_is_equal(), PLearn::Variable::gradientdata, hotval_, i, if(), PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Variable::length(), PLearn::Var::length(), n, and PLearn::two().
{ int n = input1->length(); for(int k=0; k<length(); k++) { real gr = gradientdata[k]; int classnum = (int) input2->valuedata[k]; if (!fast_exact_is_equal(gr, 1.)) { gr = gr+gr; for (int i=0; i<n; i++) input1->matGradient[i][k] += gr*(input1->matValue[i][k] - (i==classnum ? hotval_ : coldval_)); } else // specialised version for gr==1 { for (int i=0; i<n; i++) input1->matGradient[i][k] += two(input1->matValue[i][k] - (i==classnum ? hotval_ : coldval_)); } } }
void PLearn::MatrixOneHotSquaredLoss::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 66 of file MatrixOneHotSquaredLoss.cc.
References PLearn::BinaryVariable::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::MatrixOneHotSquaredLoss::build_ | ( | ) | [protected] |
This does the actual building.
Reimplemented from PLearn::BinaryVariable.
Definition at line 73 of file MatrixOneHotSquaredLoss.cc.
References PLearn::BinaryVariable::input2, and PLERROR.
Referenced by build(), and MatrixOneHotSquaredLoss().
{ if (input2 && !input2->isVec()) PLERROR("In MatrixOneHotSquaredLoss: classnum must be a vector variable representing the indexs of netouts (typically some classnums)"); }
string PLearn::MatrixOneHotSquaredLoss::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file MatrixOneHotSquaredLoss.cc.
void PLearn::MatrixOneHotSquaredLoss::declareOptions | ( | OptionList & | ol | ) | [static] |
Declare options (data fields) for the class.
Redefine this in subclasses: call declareOption
(...) for each option, and then call inherited::declareOptions(options)
. Please call the inherited
method AT THE END to get the options listed in a consistent order (from most recently defined to least recently defined).
static void MyDerivedClass::declareOptions(OptionList& ol) { declareOption(ol, "inputsize", &MyObject::inputsize_, OptionBase::buildoption, "The size of the input; it must be provided"); declareOption(ol, "weights", &MyObject::weights, OptionBase::learntoption, "The learned model weights"); inherited::declareOptions(ol); }
ol | List of options that is progressively being constructed for the current class. |
Reimplemented from PLearn::BinaryVariable.
Definition at line 80 of file MatrixOneHotSquaredLoss.cc.
References PLearn::OptionBase::buildoption, coldval_, PLearn::declareOption(), PLearn::BinaryVariable::declareOptions(), and hotval_.
{ declareOption(ol, "coldval_", &MatrixOneHotSquaredLoss::coldval_, OptionBase::buildoption, ""); declareOption(ol, "hotval_", &MatrixOneHotSquaredLoss::hotval_, OptionBase::buildoption, ""); inherited::declareOptions(ol); }
static const PPath& PLearn::MatrixOneHotSquaredLoss::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 64 of file MatrixOneHotSquaredLoss.h.
: void build_();
MatrixOneHotSquaredLoss * PLearn::MatrixOneHotSquaredLoss::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::BinaryVariable.
Definition at line 53 of file MatrixOneHotSquaredLoss.cc.
void PLearn::MatrixOneHotSquaredLoss::fprop | ( | ) | [virtual] |
compute output given input
Implements PLearn::Variable.
Definition at line 96 of file MatrixOneHotSquaredLoss.cc.
References coldval_, hotval_, i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Variable::length(), PLearn::Var::length(), n, PLearn::square(), and PLearn::Variable::valuedata.
{ int n = input1->length(); for (int k=0; k<length(); k++) { int classnum = (int) input2->valuedata[k]; real res = 0.; for(int i=0; i<n; i++) res += square(input1->matValue[i][k] - (i==classnum ? hotval_ : coldval_)); valuedata[k] = res; } }
OptionList & PLearn::MatrixOneHotSquaredLoss::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file MatrixOneHotSquaredLoss.cc.
OptionMap & PLearn::MatrixOneHotSquaredLoss::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file MatrixOneHotSquaredLoss.cc.
RemoteMethodMap & PLearn::MatrixOneHotSquaredLoss::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 53 of file MatrixOneHotSquaredLoss.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 87 of file MatrixOneHotSquaredLoss.cc.
References PLearn::BinaryVariable::input2, PLearn::Var::length(), and PLearn::Var::width().
void PLearn::MatrixOneHotSquaredLoss::symbolicBprop | ( | ) | [virtual] |
compute a piece of new Var graph that represents the symbolic derivative of this Var
Reimplemented from PLearn::Variable.
Definition at line 132 of file MatrixOneHotSquaredLoss.cc.
References PLERROR.
{ PLERROR("MatrixOneHotSquaredLoss::symbolicBprop not implemented."); }
Reimplemented from PLearn::BinaryVariable.
Definition at line 64 of file MatrixOneHotSquaredLoss.h.
real PLearn::MatrixOneHotSquaredLoss::coldval_ [protected] |
Definition at line 57 of file MatrixOneHotSquaredLoss.h.
Referenced by bprop(), declareOptions(), and fprop().
real PLearn::MatrixOneHotSquaredLoss::hotval_ [protected] |
Definition at line 57 of file MatrixOneHotSquaredLoss.h.
Referenced by bprop(), declareOptions(), and fprop().