PLearn 0.1
Public Member Functions | Static Public Member Functions | Static Public Attributes | Static Protected Member Functions | Protected Attributes | Private Types
PLearn::ClassErrorCostFunction Class Reference

#include <ClassErrorCostFunction.h>

Inheritance diagram for PLearn::ClassErrorCostFunction:
Inheritance graph
[legend]
Collaboration diagram for PLearn::ClassErrorCostFunction:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ClassErrorCostFunction (bool the_output_is_classnum=false, bool the_ignore_missing_values=true)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual ClassErrorCostFunctiondeepCopy (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 PPathdeclaringFile ()

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

Detailed Description

* 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.


Member Typedef Documentation

Reimplemented from PLearn::Kernel.

Definition at line 68 of file ClassErrorCostFunction.h.


Constructor & Destructor Documentation

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) {}

Member Function Documentation

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.

bool PLearn::ClassErrorCostFunction::_isa_ ( const Object o) [static]

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);
}

Here is the call graph for this function:

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.

real PLearn::ClassErrorCostFunction::evaluate ( const Vec x1,
const Vec x2 
) const [virtual]

** 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.;
    }
}

Here is the call graph for this function:

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())

Returns:
Information about the object

Reimplemented from PLearn::Object.

Definition at line 89 of file ClassErrorCostFunction.h.

    { return "class_error"; }

Member Data Documentation

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().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines