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

Takes a submatrix of an input variable. More...

#include <SubMatVariable.h>

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

List of all members.

Public Member Functions

 SubMatVariable ()
 Default constructor for persistence.
 SubMatVariable (Variable *v, int i, int j, int the_length, int the_width)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual SubMatVariabledeepCopy (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 ()

Static Public Member Functions

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

int startk
 Should not be set directly: this is equal to the starting element in the INPUT MATRIX corresponding to the settings of i_ and j_.
int length_
 New length (number of rows) of the SubVMatrix variable.
int width_
 New width (number of columns) of the SubVMatrix variable.
int i_
 Starting ROW in the input variable.
int j_
 Starting COLUMN in the input variable.

Private Types

typedef UnaryVariable inherited

Private Member Functions

void build_ ()
 Object-specific post-constructor.

Detailed Description

Takes a submatrix of an input variable.

This Variable performs creates a view of a subset of an input variable. The starting row and column in the input variable must be specified, as well as the new number of rows and columns.

Variables of this kind can also be created from C++ through the subMat function.

Definition at line 61 of file SubMatVariable.h.


Member Typedef Documentation

Reimplemented from PLearn::UnaryVariable.

Definition at line 63 of file SubMatVariable.h.


Constructor & Destructor Documentation

PLearn::SubMatVariable::SubMatVariable ( ) [inline]

Default constructor for persistence.

Definition at line 85 of file SubMatVariable.h.

: startk(0), length_(0), width_(0), i_(0), j_(0) {}
PLearn::SubMatVariable::SubMatVariable ( Variable v,
int  i,
int  j,
int  the_length,
int  the_width 
)

Definition at line 63 of file SubMatVariable.cc.

References build_().

    : inherited(v, the_length, the_width),
      startk(i*v->width()+j),
      length_(the_length),
      width_(the_width),
      i_(i),
      j_(j)
{
    build_();
}

Here is the call graph for this function:


Member Function Documentation

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

SubMatVariable.

Reimplemented from PLearn::UnaryVariable.

Definition at line 61 of file SubMatVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 61 of file SubMatVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 61 of file SubMatVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 61 of file SubMatVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 61 of file SubMatVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 61 of file SubMatVariable.cc.

void PLearn::SubMatVariable::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 164 of file SubMatVariable.cc.

References PLearn::Variable::diaghessiandata, i, PLearn::UnaryVariable::input, j, PLearn::Var::length(), PLearn::Variable::length(), PLearn::Variable::nelems(), startk, PLearn::Variable::width(), and PLearn::Var::width().

{
    if (input->diaghessian.length()==0)
        input->resizeDiagHessian();
    if(width()==input->width()) // optimized version for this special case
    {
        real* inputdiaghessian = input->diaghessian.data()+startk;
        for(int k=0; k<nelems(); k++)
            inputdiaghessian[k] += diaghessiandata[k]; 
    }
    else // general version
    {
        real* inputrowdiaghessian = input->diaghessiandata+startk;
        int thisk=0;
        for(int i=0; i<length(); i++)
        {
            for(int j=0; j<width(); j++)
                inputrowdiaghessian[j] += diaghessiandata[thisk++];
            inputrowdiaghessian += input->width();
        }
    }
}

Here is the call graph for this function:

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

Nothing to do by default.

Reimplemented from PLearn::UnaryVariable.

Definition at line 142 of file SubMatVariable.cc.

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

{
    if(width()==input->width()) // optimized version for this special case
    {
        real* inputgradient = input->gradientdata+startk;
        for(int k=0; k<nelems(); k++)
            inputgradient[k] += gradientdata[k]; 
    }
    else // general version
    {
        real* inputrowgradient = input->gradientdata+startk;
        int thisk=0;
        for(int i=0; i<length(); i++)
        {
            for(int j=0; j<width(); j++)
                inputrowgradient[j] += gradientdata[thisk++];
            inputrowgradient += input->width();
        }
    }
}

Here is the call graph for this function:

void PLearn::SubMatVariable::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 SubMatVariable.cc.

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

Here is the call graph for this function:

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

References i_, PLearn::UnaryVariable::input, j_, PLearn::Var::length(), PLearn::Variable::length(), PLERROR, startk, and PLearn::Var::width().

Referenced by build(), and SubMatVariable().

{
    if (input) {
        // input is v from constructor
        if(i_ < 0 || i_ + length() > input->length() || j_ < 0 || j_ + width() > input->width())
            PLERROR("In SubMatVariable: requested sub-matrix is out of matrix bounds");
        startk = i_ * input->width() + j_;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 61 of file SubMatVariable.cc.

void PLearn::SubMatVariable::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 91 of file SubMatVariable.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::UnaryVariable::declareOptions(), i_, j_, PLearn::OptionBase::learntoption, length_, startk, and width_.

{
    declareOption(
        ol, "length_", &SubMatVariable::length_, OptionBase::buildoption,
        "New length (number of rows) of the SubVMatrix variable");

    declareOption(
        ol, "width_", &SubMatVariable::width_, OptionBase::buildoption,
        "New width (number of columns) of the SubVMatrix variable");

    declareOption(
        ol, "i_", &SubMatVariable::i_, OptionBase::buildoption,
        "Starting ROW in the input variable");
    
    declareOption(
        ol, "j_", &SubMatVariable::j_, OptionBase::buildoption,
        "Starting COLUMN in the input variable");
    
    declareOption(
        ol, "startk", &SubMatVariable::startk, OptionBase::learntoption,
        "Should not be set directly: this is equal to the starting element\n"
        "in the INPUT MATRIX corresponding to the settings of i_ and j_.");

    inherited::declareOptions(ol);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 87 of file SubMatVariable.h.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 61 of file SubMatVariable.cc.

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

Nothing to do by default.

Reimplemented from PLearn::UnaryVariable.

Definition at line 120 of file SubMatVariable.cc.

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

{
    if(width()==input->width()) // optimized version for this special case
    {
        real* inputdata = input->valuedata+startk;
        for(int k=0; k<nelems(); k++)
            valuedata[k] = inputdata[k];
    }
    else // general version
    {
        real* inputrowdata = input->valuedata+startk;
        int thisk=0;
        for(int i=0; i<length(); i++)
        {
            for(int j=0; j<width(); j++)
                valuedata[thisk++] = inputrowdata[j];
            inputrowdata += input->width();
        }
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 61 of file SubMatVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 61 of file SubMatVariable.cc.

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

Reimplemented from PLearn::UnaryVariable.

Definition at line 61 of file SubMatVariable.cc.

void PLearn::SubMatVariable::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 117 of file SubMatVariable.cc.

References length_, and width_.

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

Reimplemented from PLearn::Variable.

Definition at line 200 of file SubMatVariable.cc.

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

{
    if (rValue.length()==0) resizeRValue();
    if(width()==input->width()) // optimized version for this special case
    {
        real* inputrdata = input->rvaluedata+startk;
        for(int k=0; k<nelems(); k++)
            rvaluedata[k] = inputrdata[k];
    }
    else // general version
    {
        real* inputrowrdata = input->rvaluedata+startk;
        int thisk=0;
        for(int i=0; i<length(); i++)
        {
            for(int j=0; j<width(); j++)
                rvaluedata[thisk++] = inputrowrdata[j];
            inputrowrdata += input->width();
        }
    }
}

Here is the call graph for this function:

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

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

Reimplemented from PLearn::Variable.

Definition at line 188 of file SubMatVariable.cc.

References PLearn::extend(), PLearn::Variable::g, i, PLearn::UnaryVariable::input, j, PLearn::Var::length(), PLearn::Variable::length(), startk, PLearn::Variable::width(), and PLearn::Var::width().

{
    int i = startk/input->width();
    int j = startk%input->width();
    int topextent = i;
    int bottomextent = input->length()-(i+length());
    int leftextent = j;
    int rightextent = input->width()-(j+width());
    input->accg(extend(g,topextent,bottomextent,leftextent,rightextent));
}

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::UnaryVariable.

Definition at line 87 of file SubMatVariable.h.

Starting ROW in the input variable.

Definition at line 77 of file SubMatVariable.h.

Referenced by build_(), and declareOptions().

Starting COLUMN in the input variable.

Definition at line 80 of file SubMatVariable.h.

Referenced by build_(), and declareOptions().

New length (number of rows) of the SubVMatrix variable.

Definition at line 71 of file SubMatVariable.h.

Referenced by declareOptions(), and recomputeSize().

Should not be set directly: this is equal to the starting element in the INPUT MATRIX corresponding to the settings of i_ and j_.

Definition at line 68 of file SubMatVariable.h.

Referenced by bbprop(), bprop(), build_(), declareOptions(), fprop(), rfprop(), and symbolicBprop().

New width (number of columns) of the SubVMatrix variable.

Definition at line 74 of file SubMatVariable.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