PLearn 0.1
|
********************************************************* The following 'kernels' are rather used as cost functions More...
#include <SquaredErrorCostFunction.h>
Public Member Functions | |
SquaredErrorCostFunction (int the_targetindex=-1) | |
SquaredErrorCostFunction (real hot_value, real cold_value) | |
Constructor for classification (target is interpreted as onehot) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual SquaredErrorCostFunction * | deepCopy (CopiesMap &copies) const |
virtual string | info () const |
Returns a bit more informative string about object (default returns classname()) | |
virtual real | evaluate (const Vec &output, const Vec &target) const |
** Subclasses must override this method ** | |
Static Public Member Functions | |
static string | _classname_ () |
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) |
recognized option is "targetindex" | |
Protected Attributes | |
int | targetindex |
index in target vector of the target value to use to compute the squared error (if -1, sum all the squared errors) | |
bool | classification |
real | hotvalue |
real | coldvalue |
Private Types | |
typedef Kernel | inherited |
********************************************************* The following 'kernels' are rather used as cost functions
Definition at line 55 of file SquaredErrorCostFunction.h.
typedef Kernel PLearn::SquaredErrorCostFunction::inherited [private] |
Reimplemented from PLearn::Kernel.
Definition at line 57 of file SquaredErrorCostFunction.h.
PLearn::SquaredErrorCostFunction::SquaredErrorCostFunction | ( | int | the_targetindex = -1 | ) | [inline] |
Definition at line 67 of file SquaredErrorCostFunction.h.
:targetindex(the_targetindex), classification(false), hotvalue(1), coldvalue(0) {};
PLearn::SquaredErrorCostFunction::SquaredErrorCostFunction | ( | real | hot_value, |
real | cold_value | ||
) | [inline] |
Constructor for classification (target is interpreted as onehot)
Definition at line 71 of file SquaredErrorCostFunction.h.
: targetindex(-1), classification(true), hotvalue(hot_value), coldvalue(cold_value) {};
string PLearn::SquaredErrorCostFunction::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::Kernel.
Definition at line 50 of file SquaredErrorCostFunction.cc.
OptionList & PLearn::SquaredErrorCostFunction::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::Kernel.
Definition at line 50 of file SquaredErrorCostFunction.cc.
RemoteMethodMap & PLearn::SquaredErrorCostFunction::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::Kernel.
Definition at line 50 of file SquaredErrorCostFunction.cc.
Reimplemented from PLearn::Kernel.
Definition at line 50 of file SquaredErrorCostFunction.cc.
Object * PLearn::SquaredErrorCostFunction::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 50 of file SquaredErrorCostFunction.cc.
StaticInitializer SquaredErrorCostFunction::_static_initializer_ & PLearn::SquaredErrorCostFunction::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::Kernel.
Definition at line 50 of file SquaredErrorCostFunction.cc.
string PLearn::SquaredErrorCostFunction::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 50 of file SquaredErrorCostFunction.cc.
void PLearn::SquaredErrorCostFunction::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
recognized option is "targetindex"
Reimplemented from PLearn::Kernel.
Definition at line 83 of file SquaredErrorCostFunction.cc.
References PLearn::OptionBase::buildoption, classification, coldvalue, PLearn::declareOption(), hotvalue, and targetindex.
{ declareOption(ol, "targetindex", &SquaredErrorCostFunction::targetindex, OptionBase::buildoption, "Index of target"); declareOption(ol, "hotvalue", &SquaredErrorCostFunction::hotvalue, OptionBase::buildoption, "Hot value"); declareOption(ol, "coldvalue", &SquaredErrorCostFunction::coldvalue, OptionBase::buildoption, "Cold value"); declareOption(ol, "classification", &SquaredErrorCostFunction::classification, OptionBase::buildoption, "Used as classification cost"); inherited::declareOptions(ol); }
static const PPath& PLearn::SquaredErrorCostFunction::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::Kernel.
Definition at line 74 of file SquaredErrorCostFunction.h.
{ return "squared_error"; }
SquaredErrorCostFunction * PLearn::SquaredErrorCostFunction::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::Kernel.
Definition at line 50 of file SquaredErrorCostFunction.cc.
** Subclasses must override this method **
returns K(x1,x2)
Implements PLearn::Kernel.
Definition at line 52 of file SquaredErrorCostFunction.cc.
References PLearn::TVec< T >::data(), i, PLearn::TVec< T >::length(), PLERROR, and PLearn::square().
{ #ifdef BOUNDCHECK if(target.length()!=output.length() && classification==false) PLERROR("In SquaredErrorCostFunction::evaluate target.length() %d should be equal to output.length() %d",target.length(),output.length()); #endif real result = 0.0; if (targetindex>=0) result = square(output[targetindex]-target[targetindex]); else { real* outputdata = output.data(); real* targetdata = target.data(); if (classification) { if (target.length() != 1) PLERROR("In SquaredErrorCostFunction::evaluate target.length() %s should be 1", target.length()); for (int i = 0; i < output.length(); ++i) if (i == targetdata[0]) result += square(outputdata[i] - hotvalue); else result += square(outputdata[i] - coldvalue); } else { for(int i=0; i<output.length(); i++) result += square(outputdata[i]-targetdata[i]); } } return result; }
OptionList & PLearn::SquaredErrorCostFunction::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 50 of file SquaredErrorCostFunction.cc.
OptionMap & PLearn::SquaredErrorCostFunction::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 50 of file SquaredErrorCostFunction.cc.
RemoteMethodMap & PLearn::SquaredErrorCostFunction::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 50 of file SquaredErrorCostFunction.cc.
virtual string PLearn::SquaredErrorCostFunction::info | ( | ) | const [inline, virtual] |
Returns a bit more informative string about object (default returns classname())
Reimplemented from PLearn::Object.
Definition at line 76 of file SquaredErrorCostFunction.h.
{ return "squared_error"; }
Reimplemented from PLearn::Kernel.
Definition at line 74 of file SquaredErrorCostFunction.h.
bool PLearn::SquaredErrorCostFunction::classification [protected] |
Definition at line 63 of file SquaredErrorCostFunction.h.
Referenced by declareOptions().
real PLearn::SquaredErrorCostFunction::coldvalue [protected] |
Definition at line 64 of file SquaredErrorCostFunction.h.
Referenced by declareOptions().
real PLearn::SquaredErrorCostFunction::hotvalue [protected] |
Definition at line 64 of file SquaredErrorCostFunction.h.
Referenced by declareOptions().
int PLearn::SquaredErrorCostFunction::targetindex [protected] |
index in target vector of the target value to use to compute the squared error (if -1, sum all the squared errors)
Definition at line 62 of file SquaredErrorCostFunction.h.
Referenced by declareOptions().