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

#include <ElementAtPositionVariable.h>

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

List of all members.

Public Member Functions

 ElementAtPositionVariable ()
 Default constructor for persistence.
 ElementAtPositionVariable (Variable *input1, Variable *input2, int the_length, int the_width)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual ElementAtPositionVariabledeepCopy (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
virtual void rfprop ()

Static Public Member Functions

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

int length_
int width_

Private Types

typedef BinaryVariable inherited

Detailed Description

A variable of size length() x width(), filled with zeros except for the single element indexed by input2 =(i,j) or input2 = (k). This element will be a copied from input1 (a scalar) (this is used in particular for the symbolic bprop of VarElementVariable)

Definition at line 57 of file ElementAtPositionVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::BinaryVariable.

Definition at line 59 of file ElementAtPositionVariable.h.


Constructor & Destructor Documentation

PLearn::ElementAtPositionVariable::ElementAtPositionVariable ( )

Default constructor for persistence.

Definition at line 58 of file ElementAtPositionVariable.cc.

    : length_(0), width_(0)
{ }
PLearn::ElementAtPositionVariable::ElementAtPositionVariable ( Variable input1,
Variable input2,
int  the_length,
int  the_width 
)

Definition at line 63 of file ElementAtPositionVariable.cc.

References build_().

    : inherited(input1, input2, the_length, the_width), length_(the_length), width_(the_width)
{
    build_();
}

Here is the call graph for this function:


Member Function Documentation

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

ElementAtPositionVariable.

Reimplemented from PLearn::BinaryVariable.

Definition at line 56 of file ElementAtPositionVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 56 of file ElementAtPositionVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 56 of file ElementAtPositionVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 56 of file ElementAtPositionVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 56 of file ElementAtPositionVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 56 of file ElementAtPositionVariable.cc.

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

Implements PLearn::Variable.

Definition at line 113 of file ElementAtPositionVariable.cc.

References PLearn::Variable::gradientdata, i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, j, and PLearn::Variable::width().

{
    if (input2->isScalar()) // input2 is a scalar (interpreted as a k)
    {
        int k = (int)input2->valuedata[0];
        input1->gradientdata[0] += gradientdata[k];
    }
    else // input2 has 2 elements (interpreted as (i,j) coordinates)
    {
        int i = (int)input2->valuedata[0];
        int j = (int)input2->valuedata[1];
        input1->gradientdata[0] += gradientdata[i*width()+j];
    }  
}

Here is the call graph for this function:

void PLearn::ElementAtPositionVariable::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 70 of file ElementAtPositionVariable.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::BinaryVariable.

Definition at line 77 of file ElementAtPositionVariable.cc.

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

Referenced by build(), and ElementAtPositionVariable().

{
    if (input1 && !input1->isScalar())
        PLERROR("In ElementAtPositionVariable: element must be a scalar var");
    if (input2 && input2->nelems()>2)
        PLERROR("In ElementAtPositionVariable: position must have 1 or 2 elements");
}

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 56 of file ElementAtPositionVariable.cc.

void PLearn::ElementAtPositionVariable::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 86 of file ElementAtPositionVariable.cc.

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

Here is the call graph for this function:

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 69 of file ElementAtPositionVariable.h.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 56 of file ElementAtPositionVariable.cc.

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

compute output given input

Implements PLearn::Variable.

Definition at line 96 of file ElementAtPositionVariable.cc.

References PLearn::TVec< T >::clear(), i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, j, PLearn::Variable::value, PLearn::Variable::valuedata, and PLearn::Variable::width().

{
    value.clear();
    if (input2->isScalar()) // input2 is a scalar (interpreted as a k)
    {
        int k = (int)input2->valuedata[0];
        valuedata[k] = input1->valuedata[0];
    }
    else // input2 has 2 elements (interpreted as (i,j) coordinates)
    {
        int i = (int)input2->valuedata[0];
        int j = (int)input2->valuedata[1];
        valuedata[i*width()+j] = input1->valuedata[0];
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 56 of file ElementAtPositionVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 56 of file ElementAtPositionVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 56 of file ElementAtPositionVariable.cc.

void PLearn::ElementAtPositionVariable::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 93 of file ElementAtPositionVariable.cc.

References length_, and width_.

{ l=length_; w=width_; }
void PLearn::ElementAtPositionVariable::rfprop ( ) [virtual]

Reimplemented from PLearn::Variable.

Definition at line 136 of file ElementAtPositionVariable.cc.

References PLearn::TVec< T >::clear(), i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, j, PLearn::TVec< T >::length(), PLearn::BinaryVariable::resizeRValue(), PLearn::Variable::rValue, PLearn::Variable::rvaluedata, and PLearn::Variable::width().

{
    if (rValue.length()==0) resizeRValue();
    rValue.clear();
    if (input2->isScalar()) // input2 is a scalar (interpreted as a k)
    {
        int k = (int)input2->valuedata[0];
        rvaluedata[k] = input1->rvaluedata[0];
    }
    else // input2 has 2 elements (interpreted as (i,j) coordinates)
    {
        int i = (int)input2->valuedata[0];
        int j = (int)input2->valuedata[1];
        rvaluedata[i*width()+j] = input1->rvaluedata[0];
    }
}

Here is the call graph for this function:

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

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

Reimplemented from PLearn::Variable.

Definition at line 129 of file ElementAtPositionVariable.cc.

References PLearn::Variable::g, PLearn::BinaryVariable::input1, and PLearn::BinaryVariable::input2.

{
    input1->accg(new VarElementVariable(g,input2));
}

Member Data Documentation

Reimplemented from PLearn::BinaryVariable.

Definition at line 69 of file ElementAtPositionVariable.h.

Definition at line 62 of file ElementAtPositionVariable.h.

Referenced by declareOptions(), and recomputeSize().

Definition at line 62 of file ElementAtPositionVariable.h.

Referenced by 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