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

********************************************************* The following 'kernels' are rather used as cost functions More...

#include <SquaredErrorCostFunction.h>

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

List of all members.

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 OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual SquaredErrorCostFunctiondeepCopy (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 "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

Detailed Description

********************************************************* The following 'kernels' are rather used as cost functions

Definition at line 55 of file SquaredErrorCostFunction.h.


Member Typedef Documentation

Reimplemented from PLearn::Kernel.

Definition at line 57 of file SquaredErrorCostFunction.h.


Constructor & Destructor Documentation

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

Member Function Documentation

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.

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

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.

Here is the call graph for this function:

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.

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

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

Here is the call graph for this function:

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

Returns:
Information about the object

Reimplemented from PLearn::Object.

Definition at line 76 of file SquaredErrorCostFunction.h.

    { return "squared_error"; }

Member Data Documentation

Reimplemented from PLearn::Kernel.

Definition at line 74 of file SquaredErrorCostFunction.h.

Definition at line 63 of file SquaredErrorCostFunction.h.

Referenced by declareOptions().

Definition at line 64 of file SquaredErrorCostFunction.h.

Referenced by declareOptions().

Definition at line 64 of file SquaredErrorCostFunction.h.

Referenced by declareOptions().

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


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