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

#include <InsertZerosVariable.h>

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

List of all members.

Public Member Functions

 InsertZerosVariable ()
 Default constructor for persistence.
 InsertZerosVariable (Variable *input, TVec< int > rows)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual InsertZerosVariabledeepCopy (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 bbprop ()
 compute an approximation to diag(d^2/dinput^2) given diag(d^2/doutput^2), with diag(d^2/dinput^2) ~=~ (doutput/dinput)' diag(d^2/doutput^2) (doutput/dinput) In particular: if 'C' depends on 'y' and 'y' depends on x ...
virtual void symbolicBprop ()
 compute a piece of new Var graph that represents the symbolic derivative of this Var
virtual void rfprop ()
void setInput (Var the_input)
 Set this Variable's input (simply call build after setting the new input).
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be.

Static Public Member Functions

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

Public Attributes

TVec< introws

Static Public Attributes

static StaticInitializer _static_initializer_

Private Types

typedef UnaryVariable inherited

Private Member Functions

void build_ ()
 Object-specific post-constructor.

Detailed Description

Definition at line 43 of file InsertZerosVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::UnaryVariable.

Definition at line 44 of file InsertZerosVariable.h.


Constructor & Destructor Documentation

PLearn::InsertZerosVariable::InsertZerosVariable ( ) [inline]

Default constructor for persistence.

Definition at line 52 of file InsertZerosVariable.h.

{}
PLearn::InsertZerosVariable::InsertZerosVariable ( Variable input,
TVec< int rows 
)

Definition at line 47 of file InsertZerosVariable.cc.

    : inherited(input, input->length()+the_rows.length(), input->width()), rows(the_rows)
{}

Member Function Documentation

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

InsertZerosVariable.

Reimplemented from PLearn::UnaryVariable.

Definition at line 45 of file InsertZerosVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 45 of file InsertZerosVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 45 of file InsertZerosVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 45 of file InsertZerosVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 45 of file InsertZerosVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 45 of file InsertZerosVariable.cc.

void PLearn::InsertZerosVariable::bbprop ( ) [virtual]

compute an approximation to diag(d^2/dinput^2) given diag(d^2/doutput^2), with diag(d^2/dinput^2) ~=~ (doutput/dinput)' diag(d^2/doutput^2) (doutput/dinput) In particular: if 'C' depends on 'y' and 'y' depends on x ...

d^2C/dx^2 = d^2C/dy^2 * (dy/dx)^2 + dC/dy * d^2y/dx^2 (diaghessian) (gradient)

Reimplemented from PLearn::Variable.

Definition at line 121 of file InsertZerosVariable.cc.

References PLERROR.

                                 {
    PLERROR("bbprop is not implemented for InsertZerosVariable");
}
void PLearn::InsertZerosVariable::bprop ( ) [virtual]

Nothing to do by default.

Reimplemented from PLearn::UnaryVariable.

Definition at line 103 of file InsertZerosVariable.cc.

References i, PLearn::UnaryVariable::input, j, PLearn::TMat< T >::length(), PLearn::TVec< T >::length(), PLearn::Variable::matGradient, rows, and PLearn::TMat< T >::width().

                                {
    real* gptr;
    real* ginputptr;
    int r=0;
    for(int i=0; i<matGradient.length(); i++)
    {
        if(r<rows.length() && i==rows[r])
            r++;
        else
        {
            gptr = matGradient[i];
            ginputptr = input->matGradient[i-r];
            for(int j=0; j<matGradient.width(); j++)
                *ginputptr++ += *gptr++;
        }
    }
}

Here is the call graph for this function:

void PLearn::InsertZerosVariable::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 74 of file InsertZerosVariable.cc.

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

Here is the call graph for this function:

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

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 59 of file InsertZerosVariable.cc.

References i, PLearn::UnaryVariable::input, PLearn::Var::length(), PLearn::TVec< T >::length(), PLERROR, rows, and PLearn::sortElements().

Referenced by build().

{ 
    if(input)
    {
        sortElements(rows);
        // Check if all elements are unique
        for(int i=0; i<rows.length()-1; i++)
        {
            if(rows[i] == rows[i+1]) PLERROR("InsertZerosVariable::build_(): some elements in rows are the same");
            
            if(rows[i] > input->length()+i) PLERROR("InsertZerosVariable::build_(): cannot add row of zeros at positon %d", rows[i+1]);
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 45 of file InsertZerosVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 55 of file InsertZerosVariable.h.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 45 of file InsertZerosVariable.cc.

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

Nothing to do by default.

Reimplemented from PLearn::UnaryVariable.

Definition at line 80 of file InsertZerosVariable.cc.

References i, PLearn::UnaryVariable::input, j, PLearn::TMat< T >::length(), PLearn::TVec< T >::length(), PLearn::Variable::matValue, rows, and PLearn::TMat< T >::width().

                                {
    real* ptr;
    real* inputptr;
    int r=0;
    for(int i=0; i<matValue.length(); i++)
    {
        ptr = matValue[i];
        if(r<rows.length() && i==rows[r])
        {
            for(int j=0; j<matValue.width(); j++)         
                *ptr++ = 0;
            r++;
        }
        else
        {
            inputptr = input->matValue[i-r];
            for(int j=0; j<matValue.width(); j++)
                *ptr++ = *inputptr++;
        }
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 45 of file InsertZerosVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 45 of file InsertZerosVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 45 of file InsertZerosVariable.cc.

void PLearn::InsertZerosVariable::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be.

This needs to be overridden by every class that adds "complex" data members to the class, such as Vec, Mat, PP<Something>, etc. Typical implementation:

  void CLASS_OF_THIS::makeDeepCopyFromShallowCopy(CopiesMap& copies)
  {
      inherited::makeDeepCopyFromShallowCopy(copies);
      deepCopyField(complex_data_member1, copies);
      deepCopyField(complex_data_member2, copies);
      ...
  }
Parameters:
copiesA map used by the deep-copy mechanism to keep track of already-copied objects.

Reimplemented from PLearn::UnaryVariable.

Definition at line 134 of file InsertZerosVariable.cc.

References PLearn::deepCopyField(), PLearn::UnaryVariable::makeDeepCopyFromShallowCopy(), and rows.

Here is the call graph for this function:

void PLearn::InsertZerosVariable::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 51 of file InsertZerosVariable.cc.

References PLearn::UnaryVariable::input, PLearn::Var::length(), PLearn::TVec< T >::length(), rows, and PLearn::Var::width().

                                                            {
    if (input) {
        l = input->length()+rows.length();
        w = input->width();
    } else
        l = w = 0;
}

Here is the call graph for this function:

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

Reimplemented from PLearn::Variable.

Definition at line 130 of file InsertZerosVariable.cc.

References PLERROR.

                                 {
    PLERROR("rfprop is not implemented for InsertZerosVariable");
}
void PLearn::InsertZerosVariable::setInput ( Var  the_input) [inline]

Set this Variable's input (simply call build after setting the new input).

Reimplemented from PLearn::UnaryVariable.

Definition at line 68 of file InsertZerosVariable.h.

{ input = the_input;}
void PLearn::InsertZerosVariable::symbolicBprop ( ) [virtual]

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

Reimplemented from PLearn::Variable.

Definition at line 126 of file InsertZerosVariable.cc.

References PLERROR.

                                        {
    PLERROR("symbolicBprop is not implemented for InsertZerosVariable");
}

Member Data Documentation

Reimplemented from PLearn::UnaryVariable.

Definition at line 55 of file InsertZerosVariable.h.


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