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

#include <VarElementVariable.h>

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

List of all members.

Public Member Functions

 VarElementVariable ()
 Default constructor.
 VarElementVariable (Variable *input1, Variable *input2, bool call_build_=true)
 Convenience constructor.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual VarElementVariabledeepCopy (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_ ()
 VarElementVariable.
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_

Private Types

typedef BinaryVariable inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Definition at line 52 of file VarElementVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::BinaryVariable.

Definition at line 54 of file VarElementVariable.h.


Constructor & Destructor Documentation

PLearn::VarElementVariable::VarElementVariable ( ) [inline]

Default constructor.

Definition at line 59 of file VarElementVariable.h.

{}
PLearn::VarElementVariable::VarElementVariable ( Variable input1,
Variable input2,
bool  call_build_ = true 
)

Convenience constructor.

Definition at line 64 of file VarElementVariable.cc.

References build_().

                                                        :
    inherited(input1, input2, 1, 1, call_build_)
{
    if (call_build_)
        build_();
}

Here is the call graph for this function:


Member Function Documentation

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

VarElementVariable.

Reimplemented from PLearn::BinaryVariable.

Definition at line 59 of file VarElementVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 59 of file VarElementVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 59 of file VarElementVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 59 of file VarElementVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 59 of file VarElementVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 59 of file VarElementVariable.cc.

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

Implements PLearn::Variable.

Definition at line 118 of file VarElementVariable.cc.

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

{
    if(input2->isScalar()) // scalar position index k
    {
        int k = int(input2->valuedata[0]);
        input1->gradientdata[k] += gradientdata[0];
    }
    else // (i,j) position index
    {
        int i = int(input2->valuedata[0]);
        int j = int(input2->valuedata[1]);
        input1->gradientdata[i*input1->width()+j] += gradientdata[0];
    }
}

Here is the call graph for this function:

void PLearn::VarElementVariable::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 75 of file VarElementVariable.cc.

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

Here is the call graph for this function:

void PLearn::VarElementVariable::build_ ( ) [private]

This does the actual building.

Reimplemented from PLearn::BinaryVariable.

Definition at line 84 of file VarElementVariable.cc.

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

Referenced by build(), and VarElementVariable().

{
    if (input2 && input2->nelems() > 2)
        PLERROR("IN VarElementVariable(Variable* input1, Variable* input2) input2 must have 1 (a k position index) or 2 elements (an i,j position index)");
}

Here is the caller graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 59 of file VarElementVariable.cc.

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

Reimplemented from PLearn::BinaryVariable.

Definition at line 65 of file VarElementVariable.h.

:

VarElementVariable * PLearn::VarElementVariable::deepCopy ( CopiesMap copies) const [virtual]

Reimplemented from PLearn::BinaryVariable.

Definition at line 59 of file VarElementVariable.cc.

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

compute output given input

Implements PLearn::Variable.

Definition at line 93 of file VarElementVariable.cc.

References i, PLearn::BinaryVariable::input1, PLearn::BinaryVariable::input2, j, PLearn::Var::length(), PLERROR, PLearn::Variable::valuedata, and PLearn::Var::width().

{
    if(input2->isScalar()) // scalar position index k
    {
        int k = int(input2->valuedata[0]);
#ifdef BOUNDCHECK
        if (k >= input1->length() && k>= input1->width()) // we want to allow acces both to row vectors and column vectors.
            PLERROR("VarElementVariable::fprop() - k = %d is out of range (size is %d)", k, input1->length());
#endif
        valuedata[0] = input1->valuedata[k];
    }
    else // (i,j) position index
    {
        int i = int(input2->valuedata[0]);
        int j = int(input2->valuedata[1]);
#ifdef BOUNDCHECK
        if ((i * input1->width() + j) >= input1->width() * input1->length())
            PLERROR("VarElementVariable::fprop() - (%d, %d) out of range"
                    "(size is %d)", i, j, input1->length() * input1->width());
#endif
        valuedata[0] = input1->valuedata[i*input1->width()+j];
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 59 of file VarElementVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 59 of file VarElementVariable.cc.

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

Reimplemented from PLearn::Object.

Definition at line 59 of file VarElementVariable.cc.

void PLearn::VarElementVariable::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 90 of file VarElementVariable.cc.

{ l=1; w=1; }
void PLearn::VarElementVariable::rfprop ( ) [virtual]

Reimplemented from PLearn::Variable.

Definition at line 140 of file VarElementVariable.cc.

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

{
    if (rValue.length()==0) resizeRValue();
    if(input2->isScalar()) // scalar position index k
    {
        int k = int(input2->valuedata[0]);
        rvaluedata[0] = input1->rvaluedata[k];
    }
    else // (i,j) position index
    {
        int i = int(input2->valuedata[0]);
        int j = int(input2->valuedata[1]);
        rvaluedata[0] = input1->rvaluedata[i*input1->width()+j];
    }
}

Here is the call graph for this function:

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

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

Reimplemented from PLearn::Variable.

Definition at line 134 of file VarElementVariable.cc.

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

{
    input1->accg(new ElementAtPositionVariable(g,input2,input1->length(),input1->width()));
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::BinaryVariable.

Definition at line 65 of file VarElementVariable.h.


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