|
PLearn 0.1
|
#include <ExtendedVMatrix.h>


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 OptionList & | getOptionList () const |
| virtual OptionMap & | getOptionMap () const |
| virtual RemoteMethodMap & | getRemoteMethodMap () const |
| virtual ExtendedVMatrix * | deepCopy (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 PPath & | declaringFile () |
| 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. | |
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.
typedef SourceVMatrix PLearn::ExtendedVMatrix::inherited [private] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 62 of file ExtendedVMatrix.h.
| 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_(); }

| 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_(); }

| string PLearn::ExtendedVMatrix::_classname_ | ( | ) | [static] |
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.
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_().
{
inherited::build();
build_();
}

| 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();
}


| 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);
}

| static const PPath& PLearn::ExtendedVMatrix::declaringFile | ( | ) | [inline, static] |
| ExtendedVMatrix * PLearn::ExtendedVMatrix::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 57 of file ExtendedVMatrix.cc.
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);
}
}

| 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);
}

| 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;
}
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().
1.7.4