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

#include <MatrixOneHotSquaredLoss.h>

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

List of all members.

Public Member Functions

 MatrixOneHotSquaredLoss ()
 Default constructor for persistence.
 MatrixOneHotSquaredLoss (Variable *netout, Variable *classnum, real coldval=0., real hotval=1.)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual MatrixOneHotSquaredLossdeepCopy (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 ()
virtual void symbolicBprop ()
 compute a piece of new Var graph that represents the symbolic derivative of this Var

Static Public Member Functions

static string _classname_ ()
 MatrixOneHotSquaredLoss.
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 coldval_
real hotval_

Private Types

typedef BinaryVariable inherited

Detailed Description

Definition at line 52 of file MatrixOneHotSquaredLoss.h.


Member Typedef Documentation

Reimplemented from PLearn::BinaryVariable.

Definition at line 54 of file MatrixOneHotSquaredLoss.h.


Constructor & Destructor Documentation

PLearn::MatrixOneHotSquaredLoss::MatrixOneHotSquaredLoss ( )

Default constructor for persistence.

Definition at line 55 of file MatrixOneHotSquaredLoss.cc.

    : coldval_(0.0), hotval_(0.0)
{ }
PLearn::MatrixOneHotSquaredLoss::MatrixOneHotSquaredLoss ( Variable netout,
Variable classnum,
real  coldval = 0.,
real  hotval = 1. 
)

Definition at line 59 of file MatrixOneHotSquaredLoss.cc.

References build_().

    : inherited(input1,input2,input2->length(),input2->width()), coldval_(coldval), hotval_(hotval)
{
    build_();
}

Here is the call graph for this function:


Member Function Documentation

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

MatrixOneHotSquaredLoss.

Reimplemented from PLearn::BinaryVariable.

Definition at line 53 of file MatrixOneHotSquaredLoss.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 53 of file MatrixOneHotSquaredLoss.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 53 of file MatrixOneHotSquaredLoss.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 53 of file MatrixOneHotSquaredLoss.cc.

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

Reimplemented from PLearn::Object.

Definition at line 53 of file MatrixOneHotSquaredLoss.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 53 of file MatrixOneHotSquaredLoss.cc.

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

Implements PLearn::Variable.

Definition at line 110 of file MatrixOneHotSquaredLoss.cc.

References coldval_, PLearn::fast_exact_is_equal(), PLearn::Variable::gradientdata, hotval_, i, if(), PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Variable::length(), PLearn::Var::length(), n, and PLearn::two().

{
    int n = input1->length();
    for(int k=0; k<length(); k++)
    {
        real gr = gradientdata[k];
        int classnum = (int) input2->valuedata[k];
        if (!fast_exact_is_equal(gr, 1.))
        {
            gr = gr+gr;
            for (int i=0; i<n; i++)
                input1->matGradient[i][k] += gr*(input1->matValue[i][k] - (i==classnum ? hotval_ : coldval_));
        }
        else // specialised version for gr==1
        {
            for (int i=0; i<n; i++)
                input1->matGradient[i][k] += two(input1->matValue[i][k] - (i==classnum ? hotval_ : coldval_));
        }
    }
}

Here is the call graph for this function:

void PLearn::MatrixOneHotSquaredLoss::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 66 of file MatrixOneHotSquaredLoss.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::BinaryVariable.

Definition at line 73 of file MatrixOneHotSquaredLoss.cc.

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

Referenced by build(), and MatrixOneHotSquaredLoss().

{
    if (input2 && !input2->isVec())
        PLERROR("In MatrixOneHotSquaredLoss: classnum must be a vector variable representing the indexs of netouts (typically some classnums)");
}

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 53 of file MatrixOneHotSquaredLoss.cc.

void PLearn::MatrixOneHotSquaredLoss::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 80 of file MatrixOneHotSquaredLoss.cc.

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

Here is the call graph for this function:

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 64 of file MatrixOneHotSquaredLoss.h.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 53 of file MatrixOneHotSquaredLoss.cc.

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

compute output given input

Implements PLearn::Variable.

Definition at line 96 of file MatrixOneHotSquaredLoss.cc.

References coldval_, hotval_, i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, PLearn::Variable::length(), PLearn::Var::length(), n, PLearn::square(), and PLearn::Variable::valuedata.

{
    int n = input1->length();
    for (int k=0; k<length(); k++)
    {
        int classnum = (int) input2->valuedata[k];
        real res = 0.;
        for(int i=0; i<n; i++)
            res += square(input1->matValue[i][k] - (i==classnum ? hotval_ : coldval_));
        valuedata[k] = res;
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 53 of file MatrixOneHotSquaredLoss.cc.

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

Reimplemented from PLearn::Object.

Definition at line 53 of file MatrixOneHotSquaredLoss.cc.

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

Reimplemented from PLearn::Object.

Definition at line 53 of file MatrixOneHotSquaredLoss.cc.

void PLearn::MatrixOneHotSquaredLoss::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 87 of file MatrixOneHotSquaredLoss.cc.

References PLearn::BinaryVariable::input2, PLearn::Var::length(), and PLearn::Var::width().

{
    if (input2) {
        l = input2->length();
        w = input2->width();
    } else
        l = w = 0;
}

Here is the call graph for this function:

void PLearn::MatrixOneHotSquaredLoss::symbolicBprop ( ) [virtual]

compute a piece of new Var graph that represents the symbolic derivative of this Var

Reimplemented from PLearn::Variable.

Definition at line 132 of file MatrixOneHotSquaredLoss.cc.

References PLERROR.

{
    PLERROR("MatrixOneHotSquaredLoss::symbolicBprop not implemented.");
}

Member Data Documentation

Reimplemented from PLearn::BinaryVariable.

Definition at line 64 of file MatrixOneHotSquaredLoss.h.

Definition at line 57 of file MatrixOneHotSquaredLoss.h.

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

Definition at line 57 of file MatrixOneHotSquaredLoss.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