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

#include <ExtendedVMatrix.h>

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

List of all members.

Public Member Functions

 ExtendedVMatrix (bool call_build_=false)
 default constructor (for automatic deserialization)
 ExtendedVMatrix (VMat the_source, int the_top_extent, int the_bottom_extent, int the_left_extent, int the_right_extent, real the_fill_value, bool call_build_=false)
 Warning: VMFields are NOT YET handled by this constructor.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual ExtendedVMatrixdeepCopy (CopiesMap &copies) const
virtual void build ()
 Simply calls inherited::build() then build_().
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.
virtual void reset_dimensions ()
 In case the dimensions of an underlying VMat has changed, recompute it.

Static Public Member Functions

static string _classname_ ()
 ExtendedVMatrix.
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)
 Declares this class' options.

Public Attributes

int top_extent
int bottom_extent
int left_extent
int right_extent
real fill_value
TVec< string > extfieldnames

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Member Functions

virtual void getNewRow (int i, const Vec &v) const
 Must be implemented in subclasses: default version returns an error.

Private Types

typedef SourceVMatrix inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

VMatrix that extends the underlying VMat 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.

Definition at line 60 of file ExtendedVMatrix.h.


Member Typedef Documentation

Reimplemented from PLearn::SourceVMatrix.

Definition at line 62 of file ExtendedVMatrix.h.


Constructor & Destructor Documentation

PLearn::ExtendedVMatrix::ExtendedVMatrix ( bool  call_build_ = false)

default constructor (for automatic deserialization)

Definition at line 60 of file ExtendedVMatrix.cc.

References build_().

    : inherited(call_build_),
      top_extent(0), bottom_extent(0), left_extent(0), right_extent(0),
      fill_value(0)
{
    if( call_build_ )
        build_();
}

Here is the call graph for this function:

PLearn::ExtendedVMatrix::ExtendedVMatrix ( VMat  the_source,
int  the_top_extent,
int  the_bottom_extent,
int  the_left_extent,
int  the_right_extent,
real  the_fill_value,
bool  call_build_ = false 
)

Warning: VMFields are NOT YET handled by this constructor.

Definition at line 69 of file ExtendedVMatrix.cc.

References build_().

    : inherited(the_source,
                the_source->length()+the_top_extent+the_bottom_extent,
                the_source->width()+the_left_extent+the_right_extent,
                call_build_),
      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)
{
    if( call_build_ )
        build_();
}

Here is the call graph for this function:


Member Function Documentation

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

ExtendedVMatrix.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file ExtendedVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file ExtendedVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file ExtendedVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file ExtendedVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file ExtendedVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file ExtendedVMatrix.cc.

void PLearn::ExtendedVMatrix::build ( ) [virtual]

Simply calls inherited::build() then build_().

Reimplemented from PLearn::SourceVMatrix.

Definition at line 117 of file ExtendedVMatrix.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 123 of file ExtendedVMatrix.cc.

References bottom_extent, PLearn::VMatrix::declareFieldNames(), extfieldnames, PLearn::TVec< T >::isEmpty(), left_extent, PLearn::TVec< T >::length(), PLearn::VMat::length(), PLearn::VMatrix::length_, PLASSERT, right_extent, PLearn::SourceVMatrix::setMetaInfoFromSource(), PLearn::SourceVMatrix::source, top_extent, PLearn::VMatrix::width(), PLearn::VMat::width(), and PLearn::VMatrix::width_.

Referenced by build(), and ExtendedVMatrix().

{
    this->length_ = source->length() + top_extent  + bottom_extent;
    this->width_  = source->width()  + left_extent + right_extent;

    if ( ! extfieldnames.isEmpty() )
        PLASSERT( extfieldnames.length() == left_extent + right_extent );

    TVec<string> fieldnames = source->fieldNames( );
    TVec<string> extended_fieldnames( width() );
    for ( int fno = 0, extno=0; fno < width(); fno++ )
        if ( fno < left_extent )
        {
            if ( extfieldnames.isEmpty() )
                extended_fieldnames[fno] = "extended";
            else
                extended_fieldnames[fno] = extfieldnames[extno++];
        }
        else if ( fno >= width()-right_extent )
        {
            if ( extfieldnames.isEmpty() )
                extended_fieldnames[fno] = "extended";
            else
                extended_fieldnames[fno] = extfieldnames[extno++];
        }
        else
            extended_fieldnames[fno]   = fieldnames[fno-left_extent];

    declareFieldNames( extended_fieldnames );

    setMetaInfoFromSource();
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file ExtendedVMatrix.cc.

void PLearn::ExtendedVMatrix::declareOptions ( OptionList ol) [static]

Declares this class' options.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 85 of file ExtendedVMatrix.cc.

References bottom_extent, PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::SourceVMatrix::declareOptions(), extfieldnames, fill_value, PLearn::OptionBase::learntoption, left_extent, PLearn::OptionBase::nosave, right_extent, PLearn::SourceVMatrix::source, and top_extent.

{
    declareOption(ol, "distr", &ExtendedVMatrix::source,
                  (OptionBase::learntoption | OptionBase::nosave),
                  "DEPRECATED - Use 'source' instead.");
    declareOption(ol, "top_extent", &ExtendedVMatrix::top_extent,
                  OptionBase::buildoption,
                  "Number of rows to add at the top");
    declareOption(ol, "bottom_extent", &ExtendedVMatrix::bottom_extent,
                  OptionBase::buildoption,
                  "Number of rows to add at the bottom");
    declareOption(ol, "left_extent", &ExtendedVMatrix::left_extent,
                  OptionBase::buildoption,
                  "Number of columns to add at the left");
    declareOption(ol, "right_extent", &ExtendedVMatrix::right_extent,
                  OptionBase::buildoption,
                  "Number of columns to add at the right");
    declareOption(ol, "fill_value", &ExtendedVMatrix::fill_value,
                  OptionBase::buildoption,
                  "Value to use to fill the added columns/rows");

    declareOption(
        ol, "extfieldnames", &ExtendedVMatrix::extfieldnames,
        OptionBase::buildoption,
        "The fieldnames to use for the added fields. Length must be equal to\n"
        "left_extent+right_extent.\n"
        "\n"
        "Default: [], i.e all are set to \"extended\"." );

    inherited::declareOptions(ol);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 93 of file ExtendedVMatrix.h.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file ExtendedVMatrix.cc.

void PLearn::ExtendedVMatrix::getNewRow ( int  i,
const Vec v 
) const [protected, virtual]

Must be implemented in subclasses: default version returns an error.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 156 of file ExtendedVMatrix.cc.

References bottom_extent, PLearn::TVec< T >::fill(), fill_value, left_extent, PLearn::VMatrix::length(), PLearn::TVec< T >::length(), PLERROR, right_extent, PLearn::SourceVMatrix::source, PLearn::TVec< T >::subVec(), top_extent, PLearn::VMat::width(), and PLearn::VMatrix::width().

{
#ifdef BOUNDCHECK
    if(i<0 || i>=length())
        PLERROR("In ExtendedVMatrix::getNewRow OUT OF BOUNDS");
    if(v.length() != width())
        PLERROR("In ExtendedVMatrix::getNewRow v.length() must be equal to the VMat's width");
#endif

    if(i<top_extent || i>=length()-bottom_extent)
        v.fill(fill_value);
    else
    {
        Vec subv = v.subVec(left_extent, source->width());
        source->getRow(i-top_extent,subv);
        if(left_extent>0)
            v.subVec(0,left_extent).fill(fill_value);
        if(right_extent>0)
            v.subVec(width()-right_extent,right_extent).fill(fill_value);
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file ExtendedVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file ExtendedVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file ExtendedVMatrix.cc.

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 181 of file ExtendedVMatrix.cc.

References PLearn::deepCopyField(), extfieldnames, and PLearn::SourceVMatrix::makeDeepCopyFromShallowCopy().

{
    inherited::makeDeepCopyFromShallowCopy(copies);

    // ### Call deepCopyField on all "pointer-like" fields.
    // ### that you wish to be deepCopied rather than.
    // ### shallow-copied.
    // ### ex:
    // deepCopyField(trainvec, copies);

    deepCopyField(extfieldnames, copies);

}

Here is the call graph for this function:

virtual void PLearn::ExtendedVMatrix::reset_dimensions ( ) [inline, virtual]

In case the dimensions of an underlying VMat has changed, recompute it.

Reimplemented from PLearn::VMatrix.

Definition at line 101 of file ExtendedVMatrix.h.

    {
        source->reset_dimensions();
        width_=source->width()+left_extent+right_extent;
        length_=source->length()+top_extent+bottom_extent;
    }

Member Data Documentation

Reimplemented from PLearn::SourceVMatrix.

Definition at line 93 of file ExtendedVMatrix.h.

Definition at line 67 of file ExtendedVMatrix.h.

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

The fieldnames to use for the added fields. Length must be equal to left_extent+right_extent.

Default: [], i.e all are set to "extended".

Definition at line 78 of file ExtendedVMatrix.h.

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

Definition at line 70 of file ExtendedVMatrix.h.

Referenced by declareOptions(), and getNewRow().

Definition at line 68 of file ExtendedVMatrix.h.

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

Definition at line 69 of file ExtendedVMatrix.h.

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

Definition at line 66 of file ExtendedVMatrix.h.

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


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