PLearn 0.1
|
#include <ClassErrorCostFunction.h>
Public Member Functions | |
ClassErrorCostFunction (bool the_output_is_classnum=false, bool the_ignore_missing_values=true) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual ClassErrorCostFunction * | 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 "output_is_classnum" | |
Protected Attributes | |
bool | output_is_classnum |
bool | ignore_missing_values |
Private Types | |
typedef Kernel | inherited |
* If output and target both have length 1, then binary classification with targets -1 and +1 is assumed and the sign of the output is considered If ouput is MISSING_VALUE, evaluation returns MISSING_VALUE; MISSING_VALUE can be considered as an error if ignore_missing_value is set to false. If output has length>1 and target has length 1, then output is understood as giving a score for each class while target is the index of the correct class (numbered from 0) If both output and target have a length>1 then then output is understood as giving a score for each class while the correct class is given by argmax(target) In any case, evaluation returns 0 if classification was correct, 1 otherwise
Definition at line 66 of file ClassErrorCostFunction.h.
typedef Kernel PLearn::ClassErrorCostFunction::inherited [private] |
Reimplemented from PLearn::Kernel.
Definition at line 68 of file ClassErrorCostFunction.h.
PLearn::ClassErrorCostFunction::ClassErrorCostFunction | ( | bool | the_output_is_classnum = false , |
bool | the_ignore_missing_values = true |
||
) | [inline] |
There are several cases: 1) target is a single value +1 or -1 , and output is a single value whose sign stands for the class 2) target is a single value in 0..n-1 indicating classnumber and output is a n-dimensional vector of scores 3) target is a n-dimensional vector whose argmax indicates the class, and output is a n-dimensional vector of scores 4) target is a single value indicating classnumber, and output is a single value indicating classnumber 5) target is a single value 0 or 1 , and output is a single value with the threshold 0.5 Cases 1,2,3 are handled correctly with the default output_is_classnum=false For case 4 and 5, you must specify output_is_classnum=true
Definition at line 84 of file ClassErrorCostFunction.h.
:output_is_classnum(the_output_is_classnum),ignore_missing_values(the_ignore_missing_values) {}
string PLearn::ClassErrorCostFunction::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::Kernel.
Definition at line 52 of file ClassErrorCostFunction.cc.
OptionList & PLearn::ClassErrorCostFunction::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::Kernel.
Definition at line 52 of file ClassErrorCostFunction.cc.
RemoteMethodMap & PLearn::ClassErrorCostFunction::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::Kernel.
Definition at line 52 of file ClassErrorCostFunction.cc.
Reimplemented from PLearn::Kernel.
Definition at line 52 of file ClassErrorCostFunction.cc.
Object * PLearn::ClassErrorCostFunction::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 52 of file ClassErrorCostFunction.cc.
StaticInitializer ClassErrorCostFunction::_static_initializer_ & PLearn::ClassErrorCostFunction::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::Kernel.
Definition at line 52 of file ClassErrorCostFunction.cc.
string PLearn::ClassErrorCostFunction::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 52 of file ClassErrorCostFunction.cc.
void PLearn::ClassErrorCostFunction::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
recognized option is "output_is_classnum"
Reimplemented from PLearn::Kernel.
Definition at line 86 of file ClassErrorCostFunction.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), ignore_missing_values, and output_is_classnum.
{ declareOption(ol, "output_is_classnum", &ClassErrorCostFunction::output_is_classnum, OptionBase::buildoption, "Output of learner is class number"); inherited::declareOptions(ol); declareOption(ol, "ignore_missing_values", &ClassErrorCostFunction::ignore_missing_values, OptionBase::buildoption, "When output is missing, do not compute cost and return MISSING_VALUE"); inherited::declareOptions(ol); }
static const PPath& PLearn::ClassErrorCostFunction::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::Kernel.
Definition at line 87 of file ClassErrorCostFunction.h.
{ return "class_error"; }
ClassErrorCostFunction * PLearn::ClassErrorCostFunction::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::Kernel.
Definition at line 52 of file ClassErrorCostFunction.cc.
** Subclasses must override this method **
returns K(x1,x2)
Implements PLearn::Kernel.
Definition at line 54 of file ClassErrorCostFunction.cc.
References PLearn::argmax(), PLearn::fast_exact_is_equal(), PLearn::is_integer(), PLearn::is_missing(), PLearn::TVec< T >::length(), and MISSING_VALUE.
{ if(is_missing(output[0]) && ignore_missing_values && output.length()==1 )return MISSING_VALUE; if(output_is_classnum) { if(is_integer(output[0])) return fast_exact_is_equal(output[0], target[0]) ? 0 :1; else if(fast_exact_is_equal(target[0], 1.)) return output[0]>0.5 ?0 :1; else // target[0]==0 or -1 return output[0]<=0.5 ?0 :1; } if(output.length()==1) // we assume the sign of output indicates the chosen class { if(target[0]>0) return output[0]>0 ?0. :1.; else return output[0]<0 ?0. :1.; } else // we assume output gives a score for each class { int trueclass; if(target.length()==1) trueclass = int(target[0]); else trueclass = argmax(target); return argmax(output)==trueclass ?0. :1.; } }
OptionList & PLearn::ClassErrorCostFunction::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 52 of file ClassErrorCostFunction.cc.
OptionMap & PLearn::ClassErrorCostFunction::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 52 of file ClassErrorCostFunction.cc.
RemoteMethodMap & PLearn::ClassErrorCostFunction::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 52 of file ClassErrorCostFunction.cc.
virtual string PLearn::ClassErrorCostFunction::info | ( | ) | const [inline, virtual] |
Returns a bit more informative string about object (default returns classname())
Reimplemented from PLearn::Object.
Definition at line 89 of file ClassErrorCostFunction.h.
{ return "class_error"; }
Reimplemented from PLearn::Kernel.
Definition at line 87 of file ClassErrorCostFunction.h.
Definition at line 72 of file ClassErrorCostFunction.h.
Referenced by declareOptions().
Definition at line 71 of file ClassErrorCostFunction.h.
Referenced by declareOptions().