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

#include <MarginPerceptronCostVariable.h>

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

List of all members.

Public Member Functions

 MarginPerceptronCostVariable ()
 Default constructor for persistence.
 MarginPerceptronCostVariable (Variable *output, Variable *target, real margin)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual
MarginPerceptronCostVariable
deepCopy (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_ ()
 MarginPerceptronCostVariable.
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 void declareOptions (OptionList &ol)
 Declare options (data fields) for the class.

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Member Functions

void build_ ()
 This does the actual building.

Protected Attributes

real margin

Private Types

typedef BinaryVariable inherited

Detailed Description

Definition at line 56 of file MarginPerceptronCostVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::BinaryVariable.

Definition at line 58 of file MarginPerceptronCostVariable.h.


Constructor & Destructor Documentation

PLearn::MarginPerceptronCostVariable::MarginPerceptronCostVariable ( )

Default constructor for persistence.

Definition at line 61 of file MarginPerceptronCostVariable.cc.

    : margin(0.)
{ }
PLearn::MarginPerceptronCostVariable::MarginPerceptronCostVariable ( Variable output,
Variable target,
real  margin 
)

Definition at line 65 of file MarginPerceptronCostVariable.cc.

References build_().

    : inherited(output,target,1,1),margin(m)
{
    build_();
}

Here is the call graph for this function:


Member Function Documentation

string PLearn::MarginPerceptronCostVariable::_classname_ ( ) [static]
OptionList & PLearn::MarginPerceptronCostVariable::_getOptionList_ ( ) [static]

Reimplemented from PLearn::BinaryVariable.

Definition at line 55 of file MarginPerceptronCostVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 55 of file MarginPerceptronCostVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 55 of file MarginPerceptronCostVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 55 of file MarginPerceptronCostVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 55 of file MarginPerceptronCostVariable.cc.

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

Implements PLearn::Variable.

Definition at line 120 of file MarginPerceptronCostVariable.cc.

References PLearn::diff(), PLearn::Variable::gradientdata, i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, and margin.

{
    real gr = *gradientdata;
    int target = int(input2->valuedata[0]);
    for (int i=0; i<input1->size(); i++)
    {
        real output = input1->valuedata[i];
        int signed_target = input1->size()==1?target*2-1:(target==i) - (target!=i);
        real diff = margin - signed_target * output;
        if (diff>0)
            input1->gradientdata[i] -= gr*signed_target;
    }
}

Here is the call graph for this function:

void PLearn::MarginPerceptronCostVariable::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 72 of file MarginPerceptronCostVariable.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::BinaryVariable.

Definition at line 79 of file MarginPerceptronCostVariable.cc.

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

Referenced by build(), and MarginPerceptronCostVariable().

{
    // input2 is target from constructor
    if (input2 && input2->size() != 1)
        PLERROR("In MarginPerceptronCostVariable: target represents a class (0...n_classes-1) and must be a single integer");
}

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 55 of file MarginPerceptronCostVariable.cc.

void PLearn::MarginPerceptronCostVariable::declareOptions ( OptionList ol) [static]

Declare options (data fields) for the class.

Redefine this in subclasses: call declareOption(...) for each option, and then call inherited::declareOptions(options). Please call the inherited method AT THE END to get the options listed in a consistent order (from most recently defined to least recently defined).

  static void MyDerivedClass::declareOptions(OptionList& ol)
  {
      declareOption(ol, "inputsize", &MyObject::inputsize_,
                    OptionBase::buildoption,
                    "The size of the input; it must be provided");
      declareOption(ol, "weights", &MyObject::weights,
                    OptionBase::learntoption,
                    "The learned model weights");
      inherited::declareOptions(ol);
  }
Parameters:
olList of options that is progressively being constructed for the current class.

Reimplemented from PLearn::BinaryVariable.

Definition at line 87 of file MarginPerceptronCostVariable.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::BinaryVariable::declareOptions(), and margin.

Here is the call graph for this function:

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 68 of file MarginPerceptronCostVariable.h.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 55 of file MarginPerceptronCostVariable.cc.

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

compute output given input

Implements PLearn::Variable.

Definition at line 102 of file MarginPerceptronCostVariable.cc.

References PLearn::diff(), i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, margin, and PLearn::Variable::valuedata.

{
    real cost = 0.0;
    int target = int(input2->valuedata[0]);
    for (int i=0; i<input1->size(); i++)
    {
        real output = input1->valuedata[i];
        int signed_target = input1->size()==1?target*2-1:(target==i) - (target!=i);
        real diff = margin - signed_target * output;
        if (diff>0)
            cost += diff;
    }
    valuedata[0] = cost;
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 55 of file MarginPerceptronCostVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 55 of file MarginPerceptronCostVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 55 of file MarginPerceptronCostVariable.cc.

void PLearn::MarginPerceptronCostVariable::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 96 of file MarginPerceptronCostVariable.cc.

{ l=1, w=1; }

Member Data Documentation

Reimplemented from PLearn::BinaryVariable.

Definition at line 68 of file MarginPerceptronCostVariable.h.

Definition at line 61 of file MarginPerceptronCostVariable.h.

Referenced by bprop(), declareOptions(), and fprop().


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