PLearn 0.1
|
#include <SubVMatrix.h>
Public Member Functions | |
SubVMatrix (bool call_build_=false) | |
The appropriate VMFields of the source VMat are copied upon construction. | |
SubVMatrix (VMat the_source, int the_istart, int the_jstart, int the_length, int the_width, bool call_build_=true) | |
SubVMatrix (VMat the_source, real the_fistart, int the_jstart, real the_flength, int the_width, bool call_build_=true) | |
virtual void | getNewRow (int i, const Vec &v) const |
Must be implemented in subclasses: default version returns an error. | |
virtual real | get (int i, int j) const |
These methods are implemented by buffering calls to getNewRow. | |
virtual void | getSubRow (int i, int j, Vec v) const |
fills v with the subrow i laying between columns j (inclusive) and j+v.length() (exclusive) | |
virtual real | getStringVal (int col, const string &str) const |
Returns value associated with a string (or MISSING_VALUE if there's no association for this string). | |
virtual string | getValString (int col, real val) const |
Returns the string associated with value val for field# col. | |
virtual string | getString (int row, int col) const |
Returns element as a string, even if value doesn't map to a string, in which case tostring(value) is returned. | |
virtual void | getMat (int i, int j, Mat m) const |
Copies the submatrix starting at i,j into m (which must have appropriate length and width). | |
virtual void | put (int i, int j, real value) |
This method must be implemented in all subclasses of writable matrices. | |
virtual void | putSubRow (int i, int j, Vec v) |
It is suggested that this method be implemented in subclasses of writable matrices to speed up accesses (default version repeatedly calls put(i,j,value) which may have a significant overhead) | |
virtual void | putMat (int i, int j, Mat m) |
Copies matrix m at position i,j of this VMat. | |
virtual VMat | subMat (int i, int j, int l, int w) |
Default version returns a SubVMatrix referencing the current VMatrix however this can be overridden to provide more efficient shortcuts (see MemoryVMatrix::subMat and SubVMatrix::subMat for examples) | |
virtual real | dot (int i1, int i2, int inputsize) const |
Returns the dot product between row i1 and row i2 (considering only the inputsize first elements). | |
virtual real | dot (int i, const Vec &v) const |
Returns the result of the dot product between row i and the given vec (only v.length() first elements of row i are considered). | |
virtual void | reset_dimensions () |
In case the dimensions of an underlying VMat has changed, recompute it. | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual SubVMatrix * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Simply calls inherited::build() then build_(). | |
virtual PP< Dictionary > | getDictionary (int col) const |
Return the Dictionary object for a certain field, or a null pointer if there isn't one. | |
virtual void | getValues (int row, int col, Vec &values) const |
Gives the possible values for a certain field in the VMatrix. | |
virtual void | getValues (const Vec &input, int col, Vec &values) const |
Gives the possible values of a certain field (column) given the input. | |
Static Public Member Functions | |
static string | _classname_ () |
SubVMatrix. | |
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 () |
Public Attributes | |
int | istart |
Build options. | |
int | jstart |
real | fistart |
real | flength |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares this class' options. | |
Private Types | |
typedef SourceVMatrix | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Definition at line 53 of file SubVMatrix.h.
typedef SourceVMatrix PLearn::SubVMatrix::inherited [private] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 58 of file SubVMatrix.h.
PLearn::SubVMatrix::SubVMatrix | ( | bool | call_build_ = false | ) |
PLearn::SubVMatrix::SubVMatrix | ( | VMat | the_source, |
real | the_fistart, | ||
int | the_jstart, | ||
real | the_flength, | ||
int | the_width, | ||
bool | call_build_ = true |
||
) |
Definition at line 79 of file SubVMatrix.cc.
References build_(), PLearn::VMat::length(), and PLASSERT.
: inherited(the_source, int(the_flength * the_source->length()), the_width, call_build_), istart(-1), jstart(the_jstart), fistart(the_fistart), flength(the_flength) // Note that istart will be set to the right value in build_(). { PLASSERT( the_source->length() >= 0 ); if( call_build_ ) build_(); }
string PLearn::SubVMatrix::_classname_ | ( | ) | [static] |
OptionList & PLearn::SubVMatrix::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file SubVMatrix.cc.
RemoteMethodMap & PLearn::SubVMatrix::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file SubVMatrix.cc.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file SubVMatrix.cc.
Object * PLearn::SubVMatrix::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file SubVMatrix.cc.
StaticInitializer SubVMatrix::_static_initializer_ & PLearn::SubVMatrix::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file SubVMatrix.cc.
void PLearn::SubVMatrix::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::SourceVMatrix.
Definition at line 127 of file SubVMatrix.cc.
References PLearn::SourceVMatrix::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::SubVMatrix::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 136 of file SubVMatrix.cc.
References classname(), PLearn::VMatrix::computeMissingSizeValue(), PLearn::VMatrix::copySizesFrom(), PLearn::VMatrix::extrasize_, PLearn::VMatrix::fieldinfos, fistart, flength, PLearn::VMatrix::hasMetaDataDir(), PLearn::VMatrix::inputsize(), PLearn::VMatrix::inputsize_, istart, j, jstart, PLearn::VMatrix::length(), PLearn::VMat::length(), PLearn::VMatrix::length_, PLearn::VMatrix::map_rs, PLearn::VMatrix::map_sr, PLearn::min(), PLASSERT, PLERROR, PLearn::TVec< T >::resize(), PLearn::SourceVMatrix::setMetaDataDir(), PLearn::SourceVMatrix::source, PLearn::VMatrix::targetsize(), PLearn::VMatrix::targetsize_, PLearn::tostring(), PLearn::VMatrix::updateMtime(), PLearn::VMatrix::weightsize(), PLearn::VMatrix::weightsize_, PLearn::VMatrix::width(), PLearn::VMat::width(), and PLearn::VMatrix::width_.
Referenced by build(), and SubVMatrix().
{ updateMtime(source); int sl = source->length(); int sw = source->width(); if (fistart >= 0) { PLASSERT( sl >= 0 ); istart = int(fistart * sl); } if (flength >= 0) { PLASSERT( sl >= 0 ); length_ = int(flength * sl); } if(length_ < 0) { PLASSERT( sl >= 0 ); length_ = sl - istart; } if(width_ < 0 && sw >= 0) width_ = sw - jstart; if((sl >= 0 && istart + length() > sl) || jstart+width() > sw) PLERROR("In SubVMatrix::build_ - Out of bounds of the source's length " "or width"); // Copy the source field names. fieldinfos.resize(width()); if (source->getFieldInfos().size() > 0) for(int j=0; j<width(); j++) fieldinfos[j] = source->getFieldInfos()[jstart+j]; // Copy the source string mappings. map_rs.resize(width()); map_sr.resize(width()); for (int j = jstart; j < width_ + jstart; j++) { map_rs[j - jstart] = source->getRealToStringMapping(j); map_sr[j - jstart] = source->getStringToRealMapping(j); } // determine sizes if(jstart==0 && width()==source->width() && inputsize()<0 && targetsize()<0 && weightsize()<0) //We don't change the columns, so we can copy their size copySizesFrom(source); computeMissingSizeValue(false); /* if (width_ == source->width()) { if(inputsize_<0) inputsize_ = source->inputsize(); if(targetsize_<0) targetsize_ = source->targetsize(); if(weightsize_<0) weightsize_ = source->weightsize(); } else { // The width has changed: if no sizes are specified, // we assume it's all input and no target. if(targetsize_<0) targetsize_ = 0; if(weightsize_<0) weightsize_ = 0; if(inputsize_<0) inputsize_ = width_ - targetsize_ - weightsize_; } // */ //* bool sizes_are_inconsistent = inputsize_ < 0 || targetsize_ < 0 || weightsize_ < 0 || inputsize_ + targetsize_ + weightsize_ + extrasize_ != width(); if( sizes_are_inconsistent ) { int source_is = source->inputsize(); int source_ts = source->targetsize(); int source_ws = source->weightsize(); bool source_sizes_are_inconsistent = source_is < 0 || source_ts < 0 || source_ws < 0 || source_is + source_ts + source_ws != source->width(); // if source sizes are inconsistent too, we assume it's all input if( source_sizes_are_inconsistent ) { inputsize_ = width(); targetsize_ = 0; weightsize_ = 0; } else { // We can rely on the source sizes, and determine which columns // have been cropped if( jstart <= source_is ) { inputsize_ = min(source_is - jstart, width()); targetsize_ = min(source_ts, width() - inputsize()); weightsize_ = width() - inputsize() - targetsize(); } else if( jstart <= source_is + source_ts ) { inputsize_ = 0; targetsize_ = min(source_is + source_ts - jstart, width()); weightsize_ = width() - targetsize(); } else // jstart <= source_is + source_ts + source_ws { inputsize_ = 0; targetsize_ = 0; weightsize_ = width(); } } } // else, nothing to change if(!hasMetaDataDir() && source->hasMetaDataDir()) setMetaDataDir(source->getMetaDataDir() / classname()+ "_istart=" + tostring(istart) + "_jstart=" +tostring(jstart) + "_length="+tostring(length()) + "_width="+tostring(width()) + ".metadata"); // cerr << "inputsize: "<<inputsize_ << " targetsize:"<<targetsize_<<"weightsize:"<<weightsize_<<endl; }
string PLearn::SubVMatrix::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file SubVMatrix.cc.
Referenced by build_().
void PLearn::SubVMatrix::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 99 of file SubVMatrix.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::SourceVMatrix::declareOptions(), fistart, flength, istart, jstart, and PLearn::SourceVMatrix::source.
{ //WARNING: If you add option make sure the we correctly build the metadatadir! //search for setMetaDataDir in this file. declareOption(ol, "parent", &SubVMatrix::source, OptionBase::buildoption, "DEPRECATED - Use 'source' instead."); declareOption(ol, "istart", &SubVMatrix::istart, OptionBase::buildoption, "Start i coordinate (row wise)"); declareOption(ol, "jstart", &SubVMatrix::jstart, OptionBase::buildoption, "Start j coordinate (column wise)"); declareOption(ol, "fistart", &SubVMatrix::fistart, OptionBase::buildoption, "If provided, will override istart to" " fistart * source.length()"); declareOption(ol, "flength", &SubVMatrix::flength, OptionBase::buildoption, "If provided, will override length to" " flength * source.length()"); inherited::declareOptions(ol); }
static const PPath& PLearn::SubVMatrix::declaringFile | ( | ) | [inline, static] |
SubVMatrix * PLearn::SubVMatrix::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file SubVMatrix.cc.
Returns the dot product between row i1 and row i2 (considering only the inputsize first elements).
The default version in VMatrix is somewhat inefficient, as it repeatedly calls get(i,j) The default version in RowBufferedVMatrix is a little better as it buffers the 2 Vecs between calls in case one of them is needed again. But the real strength of this method is for specialised and efficient versions in subbclasses. This method is typically used by SmartKernels so that they can compute kernel values between input samples efficiently.
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 372 of file SubVMatrix.cc.
References PLearn::RowBufferedVMatrix::dot(), istart, jstart, and PLearn::SourceVMatrix::source.
{ if(jstart==0) return source->dot(istart+i1, istart+i2, inputsize); else return inherited::dot(i1, i2, inputsize); }
Returns the result of the dot product between row i and the given vec (only v.length() first elements of row i are considered).
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 380 of file SubVMatrix.cc.
References PLearn::RowBufferedVMatrix::dot(), istart, jstart, and PLearn::SourceVMatrix::source.
{ if(jstart==0) return source->dot(istart+i, v); else return inherited::dot(i, v); }
These methods are implemented by buffering calls to getNewRow.
returns element (i,j)
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 285 of file SubVMatrix.cc.
References istart, jstart, PLearn::VMatrix::length(), PLERROR, PLearn::SourceVMatrix::source, and PLearn::VMatrix::width().
{ #ifdef BOUNDCHECK if(i<0 || i>=length() || j<0 || j>=width()) PLERROR("In SubVMatrix::get(i,j) OUT OF BOUND access"); #endif return source->get(i+istart,j+jstart); }
PP< Dictionary > PLearn::SubVMatrix::getDictionary | ( | int | col | ) | const [virtual] |
Return the Dictionary object for a certain field, or a null pointer if there isn't one.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 396 of file SubVMatrix.cc.
References jstart, PLERROR, PLearn::SourceVMatrix::source, and PLearn::VMatrix::width().
{ #ifdef BOUNDCHECK if(col<0 || col>=width()) PLERROR("In SubVMatrix::getDictionary(col) OUT OF BOUND access"); #endif return source->getDictionary(col+jstart); }
Copies the submatrix starting at i,j into m (which must have appropriate length and width).
Reimplemented from PLearn::VMatrix.
Definition at line 329 of file SubVMatrix.cc.
References istart, jstart, PLearn::TMat< T >::length(), PLearn::VMatrix::length(), PLERROR, PLearn::SourceVMatrix::source, PLearn::VMatrix::width(), and PLearn::TMat< T >::width().
{ #ifdef BOUNDCHECK if(i<0 || i+m.length()>length() || j<0 || j+m.width()>width()) PLERROR("In SubVMatrix::getMat OUT OF BOUND access"); #endif source->getMat(i+istart, j+jstart, m); }
Must be implemented in subclasses: default version returns an error.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 276 of file SubVMatrix.cc.
References PLearn::VMat::getSubRow(), istart, jstart, PLearn::VMatrix::length(), PLERROR, and PLearn::SourceVMatrix::source.
{ #ifdef BOUNDCHECK if(i<0 || i>=length()) PLERROR("In SubVMatrix::getNewRow(i, v) OUT OF BOUND access"); #endif source->getSubRow(i+istart, jstart, v); }
OptionList & PLearn::SubVMatrix::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file SubVMatrix.cc.
OptionMap & PLearn::SubVMatrix::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file SubVMatrix.cc.
RemoteMethodMap & PLearn::SubVMatrix::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 52 of file SubVMatrix.cc.
Returns element as a string, even if value doesn't map to a string, in which case tostring(value) is returned.
Reimplemented from PLearn::VMatrix.
Definition at line 320 of file SubVMatrix.cc.
References istart, jstart, PLearn::VMatrix::length(), PLERROR, PLearn::SourceVMatrix::source, and PLearn::VMatrix::width().
{ #ifdef BOUNDCHECK if(row<0 || row>=length() || col<0 || col>=width()) PLERROR("In SubVMatrix::getString(): OUT OF BOUND access"); #endif return source->getString(row + istart, jstart+col); }
Returns value associated with a string (or MISSING_VALUE if there's no association for this string).
Reimplemented from PLearn::VMatrix.
Definition at line 302 of file SubVMatrix.cc.
References jstart, PLERROR, PLearn::SourceVMatrix::source, and PLearn::VMatrix::width().
{ #ifdef BOUNDCHECK if(col<0 || col>=width()) PLERROR("In SubVMatrix::getStringVal(): OUT OF BOUND access"); #endif return source->getStringVal(jstart+col, str); }
fills v with the subrow i laying between columns j (inclusive) and j+v.length() (exclusive)
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 293 of file SubVMatrix.cc.
References PLearn::VMat::getSubRow(), istart, jstart, PLearn::VMatrix::length(), PLearn::TVec< T >::length(), PLERROR, PLearn::SourceVMatrix::source, and PLearn::VMatrix::width().
{ #ifdef BOUNDCHECK if(i<0 || i>=length() || j<0 || j+v.length()>width()) PLERROR("In SubVMatrix::getSubRow(i,j,v) OUT OF BOUND access"); #endif source->getSubRow(i+istart,j+jstart,v); }
Returns the string associated with value val for field# col.
Or returns "" if no string is associated.
Reimplemented from PLearn::VMatrix.
Definition at line 311 of file SubVMatrix.cc.
References jstart, PLERROR, PLearn::SourceVMatrix::source, and PLearn::VMatrix::width().
{ #ifdef BOUNDCHECK if(col<0 || col>=width()) PLERROR("In SubVMatrix::getValString(): OUT OF BOUND access"); #endif return source->getValString(jstart+col,val); }
Gives the possible values of a certain field (column) given the input.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 414 of file SubVMatrix.cc.
References jstart, PLearn::TVec< T >::length(), PLERROR, PLearn::SourceVMatrix::source, PLearn::TVec< T >::subVec(), and PLearn::VMatrix::width().
{ #ifdef BOUNDCHECK if(col<0 || col>=width()) PLERROR("In SubVMatrix::getValues(row,col) OUT OF BOUND access"); #endif source->getValues(input.subVec(jstart, input.length()-jstart), col+jstart, values); }
Gives the possible values for a certain field in the VMatrix.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 405 of file SubVMatrix.cc.
References istart, jstart, PLearn::VMatrix::length(), PLERROR, PLearn::SourceVMatrix::source, and PLearn::VMatrix::width().
{ #ifdef BOUNDCHECK if(row<0 || row>=length() || col<0 || col>=width()) PLERROR("In SubVMatrix::getValues(row,col) OUT OF BOUND access"); #endif source->getValues(row+istart,col+jstart, values); }
void PLearn::SubVMatrix::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 391 of file SubVMatrix.cc.
References PLearn::SourceVMatrix::makeDeepCopyFromShallowCopy().
{ inherited::makeDeepCopyFromShallowCopy(copies); }
This method must be implemented in all subclasses of writable matrices.
Sets element (i,j) to value.
Reimplemented from PLearn::VMatrix.
Definition at line 338 of file SubVMatrix.cc.
References istart, jstart, PLearn::VMatrix::length(), PLERROR, PLearn::SourceVMatrix::source, and PLearn::VMatrix::width().
{ #ifdef BOUNDCHECK if(i<0 || i>=length() || j<0 || j>=width()) PLERROR("In SubVMatrix::put(i,j,value) OUT OF BOUND access"); #endif return source->put(i+istart,j+jstart,value); }
Copies matrix m at position i,j of this VMat.
Reimplemented from PLearn::VMatrix.
Definition at line 355 of file SubVMatrix.cc.
References istart, jstart, PLearn::TMat< T >::length(), PLearn::VMatrix::length(), PLERROR, PLearn::SourceVMatrix::source, PLearn::VMatrix::width(), and PLearn::TMat< T >::width().
{ #ifdef BOUNDCHECK if(i<0 || i+m.length()>length() || j<0 || j+m.width()>width()) PLERROR("In SubVMatrix::putMat(i,j,m) OUT OF BOUND access"); #endif source->putMat(i+istart, j+jstart, m); }
It is suggested that this method be implemented in subclasses of writable matrices to speed up accesses (default version repeatedly calls put(i,j,value) which may have a significant overhead)
Reimplemented from PLearn::VMatrix.
Definition at line 346 of file SubVMatrix.cc.
References istart, jstart, PLearn::VMatrix::length(), PLERROR, PLearn::SourceVMatrix::source, and PLearn::VMatrix::width().
{ #ifdef BOUNDCHECK if(i<0 || i>=length() || j<0 || j>=width()) PLERROR("In SubVMatrix::putSubRow(i,j,v) OUT OF BOUND access"); #endif source->putSubRow(i+istart,j+jstart,v); }
void PLearn::SubVMatrix::reset_dimensions | ( | ) | [virtual] |
In case the dimensions of an underlying VMat has changed, recompute it.
Reimplemented from PLearn::VMatrix.
Definition at line 259 of file SubVMatrix.cc.
References PLearn::VMat::length(), PLearn::VMatrix::length_, PLERROR, PLearn::SourceVMatrix::source, PLearn::VMat::width(), and PLearn::VMatrix::width_.
{ // This seems like an old method that is not used anymore, and should not // be used anyway as it probably does not work correctly. Keeping it with // an error message until it is removed for good, in order to possibly // detect some uses of it. PLERROR("In SubVMatrix::reset_dimensions - Not working anymore"); int delta_length = source->length()-length_; int delta_width = 0; // source->width()-width_; HACK source->reset_dimensions(); length_=source->length()-delta_length; width_=source->width()-delta_width; }
Default version returns a SubVMatrix referencing the current VMatrix however this can be overridden to provide more efficient shortcuts (see MemoryVMatrix::subMat and SubVMatrix::subMat for examples)
Reimplemented from PLearn::VMatrix.
Definition at line 364 of file SubVMatrix.cc.
References istart, jstart, PLearn::SourceVMatrix::source, and PLearn::VMat::subMat().
Reimplemented from PLearn::SourceVMatrix.
Definition at line 103 of file SubVMatrix.h.
Definition at line 66 of file SubVMatrix.h.
Referenced by build_(), and declareOptions().
Definition at line 67 of file SubVMatrix.h.
Referenced by build_(), and declareOptions().
Build options.
Definition at line 64 of file SubVMatrix.h.
Referenced by build_(), declareOptions(), dot(), get(), getMat(), getNewRow(), getString(), getSubRow(), getValues(), put(), putMat(), putSubRow(), and subMat().
Definition at line 65 of file SubVMatrix.h.
Referenced by build_(), declareOptions(), dot(), get(), getDictionary(), getMat(), getNewRow(), getString(), getStringVal(), getSubRow(), getValString(), getValues(), put(), putMat(), putSubRow(), and subMat().