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

#include <ExtendedVariable.h>

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

List of all members.

Public Member Functions

 ExtendedVariable ()
 Default constructor for persistence.
 ExtendedVariable (Variable *input, int the_top_extent, int the_bottom_extent, int the_left_extent, int the_right_extent, real the_fill_value)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual ExtendedVariabledeepCopy (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 ()
 Nothing to do by default.
virtual void bprop ()
 Nothing to do by default.
virtual void symbolicBprop ()
 compute a piece of new Var graph that represents the symbolic derivative of this Var
virtual void rfprop ()

Static Public Member Functions

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

Public Attributes

int top_extent
int bottom_extent
int left_extent
int right_extent
real fill_value

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Member Functions

void build_ ()
 Object-specific post-constructor.

Private Types

typedef UnaryVariable inherited

Detailed Description

* ExtendedVariable *

Variable that extends the input variable by appending rows at its top and bottom and columns at its left and right. The appended rows/columns are filled with the given fill_value This can be used for instance to easily implement the usual trick to include the bias in the weights vectors, by appending a 1 to the inputs. It is also used in the symbolic bprop of SubMatVariable.

Definition at line 61 of file ExtendedVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::UnaryVariable.

Definition at line 63 of file ExtendedVariable.h.


Constructor & Destructor Documentation

PLearn::ExtendedVariable::ExtendedVariable ( ) [inline]

Default constructor for persistence.

Definition at line 74 of file ExtendedVariable.h.

PLearn::ExtendedVariable::ExtendedVariable ( Variable input,
int  the_top_extent,
int  the_bottom_extent,
int  the_left_extent,
int  the_right_extent,
real  the_fill_value 
)

Definition at line 58 of file ExtendedVariable.cc.

References build_().

    : inherited(input, input->length()+the_top_extent+the_bottom_extent, input->width()+the_left_extent+the_right_extent),
      top_extent(the_top_extent), bottom_extent(the_bottom_extent), 
      left_extent(the_left_extent), right_extent(the_right_extent),
      fill_value(the_fill_value)
{
    build_();
}

Here is the call graph for this function:


Member Function Documentation

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

ExtendedVariable.

Reimplemented from PLearn::UnaryVariable.

Definition at line 56 of file ExtendedVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 56 of file ExtendedVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 56 of file ExtendedVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 56 of file ExtendedVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 56 of file ExtendedVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 56 of file ExtendedVariable.cc.

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

Nothing to do by default.

Reimplemented from PLearn::UnaryVariable.

Definition at line 126 of file ExtendedVariable.cc.

References PLearn::Variable::gradientdata, i, PLearn::UnaryVariable::input, j, left_extent, PLearn::Var::length(), top_extent, PLearn::Variable::width(), and PLearn::Var::width().

{
    if(width()==input->width()) // optimized code for this special case (no left or right extents)
    {
        real* data = gradientdata+top_extent*width();
        for(int k=0; k<input->nelems(); k++)
            input->gradientdata[k] += data[k];
    }
    else // general case
    {
        real* rowdata = gradientdata+top_extent*width()+left_extent;
        int inputk = 0;
        for(int i=0; i<input->length(); i++)
        {
            for(int j=0; j<input->width(); j++)
                input->gradientdata[inputk++] += rowdata[j]; 
            rowdata += width();
        }
    }
}

Here is the call graph for this function:

void PLearn::ExtendedVariable::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::UnaryVariable.

Definition at line 69 of file ExtendedVariable.cc.

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

Here is the call graph for this function:

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

Object-specific post-constructor.

This method should be redefined in subclasses and do the actual building of the object according to previously set option fields. Constructors can just set option fields, and then call build_. This method is NOT virtual, and will typically be called only from three places: a constructor, the public virtual build() method, and possibly the public virtual read method (which calls its parent's read). build_() can assume that its parent's build_() has already been called.

Reimplemented from PLearn::UnaryVariable.

Definition at line 76 of file ExtendedVariable.cc.

References bottom_extent, fill_value, left_extent, PLearn::Variable::nelems(), PLERROR, right_extent, top_extent, and PLearn::Variable::valuedata.

Referenced by build(), and ExtendedVariable().

{
    if(top_extent<0 || bottom_extent<0 || left_extent<0 || right_extent<0)
        PLERROR("In ExtendedVariable: given extents must be >=0");
    for(int k=0; k<nelems(); k++)
        valuedata[k] = fill_value;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 56 of file ExtendedVariable.cc.

void PLearn::ExtendedVariable::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::UnaryVariable.

Definition at line 85 of file ExtendedVariable.cc.

References bottom_extent, PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::UnaryVariable::declareOptions(), fill_value, left_extent, right_extent, and top_extent.

Here is the call graph for this function:

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 82 of file ExtendedVariable.h.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 56 of file ExtendedVariable.cc.

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

Nothing to do by default.

Reimplemented from PLearn::UnaryVariable.

Definition at line 104 of file ExtendedVariable.cc.

References i, PLearn::UnaryVariable::input, j, left_extent, PLearn::Var::length(), top_extent, PLearn::Variable::valuedata, PLearn::Variable::width(), and PLearn::Var::width().

{
    if(width()==input->width()) // optimized code for this special case (no left or right extents)
    {
        real* data = valuedata+top_extent*width();
        for(int k=0; k<input->nelems(); k++)
            data[k] = input->valuedata[k];
    }
    else // general case
    {
        real* rowdata=valuedata+top_extent*width()+left_extent;
        int inputk=0;
        for(int i=0; i<input->length(); i++)
        {
            for(int j=0; j<input->width(); j++)
                rowdata[j] = input->valuedata[inputk++];
            rowdata += width();
        }
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 56 of file ExtendedVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 56 of file ExtendedVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 56 of file ExtendedVariable.cc.

void PLearn::ExtendedVariable::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 95 of file ExtendedVariable.cc.

References bottom_extent, PLearn::UnaryVariable::input, left_extent, PLearn::Var::length(), right_extent, top_extent, and PLearn::Var::width().

{
    if (input) {
        l = input->length() + top_extent + bottom_extent;
        w = input->width() + left_extent + right_extent;
    } else
        l = w = 0;
}

Here is the call graph for this function:

void PLearn::ExtendedVariable::rfprop ( ) [virtual]

Reimplemented from PLearn::Variable.

Definition at line 154 of file ExtendedVariable.cc.

References i, PLearn::UnaryVariable::input, j, left_extent, PLearn::Var::length(), PLearn::TVec< T >::length(), PLearn::UnaryVariable::resizeRValue(), PLearn::Variable::rValue, PLearn::Variable::rvaluedata, top_extent, PLearn::Variable::width(), and PLearn::Var::width().

{
    if (rValue.length()==0) resizeRValue();
    if(width()==input->width()) // optimized code for this special case (no left or right extents)
    {
        real* data = rvaluedata+top_extent*width();
        for(int k=0; k<input->nelems(); k++)
            data[k] = input->rvaluedata[k];
    }
    else // general case
    {
        real* rowdata=rvaluedata+top_extent*width()+left_extent;
        int inputk=0;
        for(int i=0; i<input->length(); i++)
        {
            for(int j=0; j<input->width(); j++)
                rowdata[j] = input->rvaluedata[inputk++];
            rowdata += width();
        }
    }
}

Here is the call graph for this function:

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

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

Reimplemented from PLearn::Variable.

Definition at line 148 of file ExtendedVariable.cc.

References PLearn::Variable::g, PLearn::UnaryVariable::input, left_extent, PLearn::Var::length(), top_extent, and PLearn::Var::width().

{
    input->accg(new SubMatVariable(g,top_extent,left_extent,input->length(),input->width()));
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::UnaryVariable.

Definition at line 82 of file ExtendedVariable.h.

Definition at line 67 of file ExtendedVariable.h.

Referenced by build_(), declareOptions(), and recomputeSize().

Definition at line 70 of file ExtendedVariable.h.

Referenced by build_(), and declareOptions().

Definition at line 69 of file ExtendedVariable.h.

Referenced by build_(), declareOptions(), and recomputeSize().


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