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

cost = - sum_i {target_i * log(output_i) + (1-target_i) * log(1-output_i)} More...

#include <CrossEntropyVariable.h>

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

List of all members.

Public Member Functions

 CrossEntropyVariable ()
 Default constructor for persistence.
 CrossEntropyVariable (Variable *netout, Variable *target)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual CrossEntropyVariabledeepCopy (CopiesMap &copies) const
virtual void build ()
 Post-constructor.
virtual void recomputeSize (int &l, int &w) const
 Recomputes the length l and width w that this variable should have, according to its parent variables.
virtual void fprop ()
 compute output given input
virtual void bprop ()

Static Public Member Functions

static string _classname_ ()
 CrossEntropyVariable.
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_

Protected Member Functions

void build_ ()
 This does the actual building.

Private Types

typedef BinaryVariable inherited

Detailed Description

cost = - sum_i {target_i * log(output_i) + (1-target_i) * log(1-output_i)}

Definition at line 53 of file CrossEntropyVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::BinaryVariable.

Definition at line 55 of file CrossEntropyVariable.h.


Constructor & Destructor Documentation

PLearn::CrossEntropyVariable::CrossEntropyVariable ( ) [inline]

Default constructor for persistence.

Definition at line 59 of file CrossEntropyVariable.h.

{}
PLearn::CrossEntropyVariable::CrossEntropyVariable ( Variable netout,
Variable target 
)

Definition at line 56 of file CrossEntropyVariable.cc.

References build_().

    : inherited(netout,target,1,1)
{
    build_();
}

Here is the call graph for this function:


Member Function Documentation

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

CrossEntropyVariable.

Reimplemented from PLearn::BinaryVariable.

Definition at line 54 of file CrossEntropyVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 54 of file CrossEntropyVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 54 of file CrossEntropyVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 54 of file CrossEntropyVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 54 of file CrossEntropyVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 54 of file CrossEntropyVariable.cc.

void PLearn::CrossEntropyVariable::bprop ( ) [virtual]

Implements PLearn::Variable.

Definition at line 102 of file CrossEntropyVariable.cc.

References PLearn::fast_exact_is_equal(), PLearn::Variable::gradientdata, i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, and PLERROR.

{
    real gr = *gradientdata;
    for (int i=0; i<input1->size(); i++)
    {
        real output = input1->valuedata[i];
        real target = input2->valuedata[i];
#ifdef BOUNDCHECK
        if (fast_exact_is_equal(output, target))
            PLERROR("CrossEntropyVariable::bprop: model output is either exactly "
                    "0.0 or 1.0; cannot compute bprop");
#endif
        input1->gradientdata[i] += gr*(-target/output + (1.0-target)/(1.0-output));
    }
}

Here is the call graph for this function:

void PLearn::CrossEntropyVariable::build ( ) [virtual]

Post-constructor.

The normal implementation should call simply inherited::build(), then this class's build_(). This method should be callable again at later times, after modifying some option fields to change the "architecture" of the object.

Reimplemented from PLearn::BinaryVariable.

Definition at line 63 of file CrossEntropyVariable.cc.

References PLearn::BinaryVariable::build(), and build_().

Here is the call graph for this function:

void PLearn::CrossEntropyVariable::build_ ( ) [protected]

This does the actual building.

Reimplemented from PLearn::BinaryVariable.

Definition at line 70 of file CrossEntropyVariable.cc.

References PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, and PLERROR.

Referenced by build(), and CrossEntropyVariable().

{
    // input1 and input2 are (respectively) netout and target from constructor
    if (input1 && input2 && (input1->size() != input2->size()))
        PLERROR("In CrossEntropyVariable: netout and target must have the same size");
}

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 54 of file CrossEntropyVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 62 of file CrossEntropyVariable.h.

:
    void build_();
CrossEntropyVariable * PLearn::CrossEntropyVariable::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::BinaryVariable.

Definition at line 54 of file CrossEntropyVariable.cc.

void PLearn::CrossEntropyVariable::fprop ( ) [virtual]

compute output given input

Implements PLearn::Variable.

Definition at line 81 of file CrossEntropyVariable.cc.

References PLearn::fast_exact_is_equal(), i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, pl_log, PLASSERT, PLERROR, and PLearn::Variable::valuedata.

{
    real cost = 0.0;
    for (int i=0; i<input1->size(); i++)
    {
        real output = input1->valuedata[i];
        real target = input2->valuedata[i];
        PLASSERT( fast_exact_is_equal(target, 0) ||
                fast_exact_is_equal(target, 1)    );
        PLASSERT( output >= 0 && output <= 1 );
        if ((fast_exact_is_equal(output,0) && !fast_exact_is_equal(target,0))
         || (fast_exact_is_equal(output,1) && !fast_exact_is_equal(target,1)))
            PLERROR("CrossEntropyVariable::fprop: model output is either exactly "
                    "0.0 or 1.0; cannot compute cost function");
        if (!fast_exact_is_equal(output,0) && !fast_exact_is_equal(output,1)) {
            cost += target*pl_log(output) + (1.0-target)*pl_log(1.0-output);
        }
    }
    valuedata[0] = -cost;
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 54 of file CrossEntropyVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 54 of file CrossEntropyVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 54 of file CrossEntropyVariable.cc.

void PLearn::CrossEntropyVariable::recomputeSize ( int l,
int w 
) const [virtual]

Recomputes the length l and width w that this variable should have, according to its parent variables.

This is used for ex. by sizeprop() The default version stupidly returns the current dimensions, so make sure to overload it in subclasses if this is not appropriate.

Reimplemented from PLearn::Variable.

Definition at line 78 of file CrossEntropyVariable.cc.

{ l=1, w=1; }

Member Data Documentation

Reimplemented from PLearn::BinaryVariable.

Definition at line 62 of file CrossEntropyVariable.h.


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