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

#include <NegLogProbCostFunction.h>

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

List of all members.

Public Member Functions

 NegLogProbCostFunction (bool do_normalize=false, bool do_smooth_map_outputs=false)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual NegLogProbCostFunctiondeepCopy (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 ()

Public Attributes

bool normalize
bool smooth_map_outputs

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

static void declareOptions (OptionList &ol)
 recognized options are "normalize" and "smooth_map_outputs"

Private Types

typedef Kernel inherited

Detailed Description

The target is an integer between 0 and n_classes-1 corresponding to a class Y, and the output is a vector of length n_classes of non-negative estimated conditional probabilities P(Y=i|X) for class i (i=0 to n_classes-1), or if n_classes=2, the output could be a vector of length 1 containing P(Y=1|X). The cost is

Definition at line 62 of file NegLogProbCostFunction.h.


Member Typedef Documentation

Reimplemented from PLearn::Kernel.

Definition at line 64 of file NegLogProbCostFunction.h.


Constructor & Destructor Documentation

PLearn::NegLogProbCostFunction::NegLogProbCostFunction ( bool  do_normalize = false,
bool  do_smooth_map_outputs = false 
) [inline]

Definition at line 80 of file NegLogProbCostFunction.h.

        : normalize(do_normalize), smooth_map_outputs(do_smooth_map_outputs) {}

Member Function Documentation

string PLearn::NegLogProbCostFunction::_classname_ ( ) [static]

Reimplemented from PLearn::Kernel.

Definition at line 55 of file NegLogProbCostFunction.cc.

OptionList & PLearn::NegLogProbCostFunction::_getOptionList_ ( ) [static]

Reimplemented from PLearn::Kernel.

Definition at line 55 of file NegLogProbCostFunction.cc.

RemoteMethodMap & PLearn::NegLogProbCostFunction::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::Kernel.

Definition at line 55 of file NegLogProbCostFunction.cc.

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

Reimplemented from PLearn::Kernel.

Definition at line 55 of file NegLogProbCostFunction.cc.

Object * PLearn::NegLogProbCostFunction::_new_instance_for_typemap_ ( ) [static]

Reimplemented from PLearn::Object.

Definition at line 55 of file NegLogProbCostFunction.cc.

StaticInitializer NegLogProbCostFunction::_static_initializer_ & PLearn::NegLogProbCostFunction::_static_initialize_ ( ) [static]

Reimplemented from PLearn::Kernel.

Definition at line 55 of file NegLogProbCostFunction.cc.

string PLearn::NegLogProbCostFunction::classname ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 55 of file NegLogProbCostFunction.cc.

void PLearn::NegLogProbCostFunction::declareOptions ( OptionList ol) [static, protected]

recognized options are "normalize" and "smooth_map_outputs"

Reimplemented from PLearn::Kernel.

Definition at line 133 of file NegLogProbCostFunction.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), normalize, and smooth_map_outputs.

Here is the call graph for this function:

static const PPath& PLearn::NegLogProbCostFunction::declaringFile ( ) [inline, static]

Reimplemented from PLearn::Kernel.

Definition at line 83 of file NegLogProbCostFunction.h.

{ return "negative_log_probability"; }
NegLogProbCostFunction * PLearn::NegLogProbCostFunction::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::Kernel.

Definition at line 55 of file NegLogProbCostFunction.cc.

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

** Subclasses must override this method **

returns K(x1,x2)

Implements PLearn::Kernel.

Definition at line 59 of file NegLogProbCostFunction.cc.

References PLearn::TVec< T >::data(), i, PLearn::TVec< T >::length(), PLearn::normalize(), PLERROR, PLearn::PLMPI::rank, PLearn::safeflog(), PLearn::PLMPI::size, smoothmap, and PLearn::sum().

{
    real prob = 0.;
    int desired_class = int(target[0]);
    if (desired_class == -1) desired_class=0;
    if(output.length()==1) // we assume output[0] gives the probability of having class 1 
    {
        prob = output[0];
        if(smooth_map_outputs)
            prob = smoothmap(prob);
        if(desired_class==0)
            prob = 1-prob;
    }
    else 
    {
        if(!normalize) // we assume output gives a real probability for each class
#if USING_MPI
#define SEND_PROB_TAG 981
        {
            // EACH CPU ONLY CARRIES THE CORRECT outputs IN THE INTERVAL
            // GIVEN BY [out_start,out_end).
            // THE RESULT WILL BE THAT CPU 0 WILL HAVE
            // THE PROBABILITY OF desired_class IN prob
            // (and the other CPUs will have some dummy value)
            if (PLMPI::size>1 && out_end>=0)
            {
                if (desired_class>=out_start && desired_class<out_end)
                {
                    prob = output[desired_class];
                    if (PLMPI::rank>0) // send it to CPU 0
                    {
                        MPI_Send(&prob,1,PLMPI_REAL,0,SEND_PROB_TAG,MPI_COMM_WORLD);
                    }
                }
                else
                {
                    if (PLMPI::rank==0)
                    {
                        MPI_Status status;
                        MPI_Recv(&prob,1,PLMPI_REAL,MPI_ANY_SOURCE,SEND_PROB_TAG,MPI_COMM_WORLD,&status);
                    }
                    else 
                    {
                        prob = 1; // dummy value (whose log exists)
                    }
                }
            }
            else
                prob = output[desired_class];
        }
#else
        prob = output[desired_class];
#endif
        else // outputs may not sum to 1, so we'll normalize them
        {
#if USING_MPI
            if (PLMPI::size>1 && out_end>=0)
                PLERROR("condprob used in parallel mode: normalize not implemented");
#endif
            real* outputdata = output.data();
            if(smooth_map_outputs) // outputs may be slightly smaller than 0 or slightly larger than 1
            {                      // so we'll smooth-map them to fit in range [0,1] before normalizing 
                real outputsum = 0.0;
                for(int i=0; i<output.length(); i++)
                    outputsum += smoothmap(outputdata[i]);
                prob = smoothmap(outputdata[desired_class])/outputsum;
            }
            else
                prob = output[desired_class]/sum(output, false);
        }
    }
    return -safeflog(prob);
}

Here is the call graph for this function:

OptionList & PLearn::NegLogProbCostFunction::getOptionList ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 55 of file NegLogProbCostFunction.cc.

OptionMap & PLearn::NegLogProbCostFunction::getOptionMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 55 of file NegLogProbCostFunction.cc.

RemoteMethodMap & PLearn::NegLogProbCostFunction::getRemoteMethodMap ( ) const [virtual]

Reimplemented from PLearn::Object.

Definition at line 55 of file NegLogProbCostFunction.cc.

virtual string PLearn::NegLogProbCostFunction::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 85 of file NegLogProbCostFunction.h.

    { return "negative_log_probability"; }

Member Data Documentation

Reimplemented from PLearn::Kernel.

Definition at line 83 of file NegLogProbCostFunction.h.

Definition at line 67 of file NegLogProbCostFunction.h.

Referenced by declareOptions().

Definition at line 68 of file NegLogProbCostFunction.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