PLearn 0.1
|
#include <ConcatColumnsVMatrix.h>
Public Member Functions | |
ConcatColumnsVMatrix (TVec< VMat > the_sources=TVec< VMat >()) | |
The lists of VMFields are appended upon construction. | |
ConcatColumnsVMatrix (VMat d1, VMat d2) | |
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). | |
const map< string, real > & | getStringMapping (int col) const |
returns the whole string->value mapping | |
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 | reset_dimensions () |
In case the dimensions of an underlying VMat has changed, recompute it. | |
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 string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual ConcatColumnsVMatrix * | 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 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. | |
virtual void | put (int i, int j, real value) |
Sets element (i,j) to value. | |
Static Public Member Functions | |
static string | _classname_ () |
ConcatColumnsVMatrix. | |
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 | |
bool | no_duplicate_fieldnames |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
virtual void | getNewRow (int i, const Vec &samplevec) const |
This is the only method requiring implementation in subclasses. | |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declare this class' options. | |
Protected Attributes | |
TVec< VMat > | sources |
Private Types | |
typedef RowBufferedVMatrix | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Definition at line 54 of file ConcatColumnsVMatrix.h.
typedef RowBufferedVMatrix PLearn::ConcatColumnsVMatrix::inherited [private] |
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 56 of file ConcatColumnsVMatrix.h.
The lists of VMFields are appended upon construction.
The case where some VMat may have some fields and others not is handled properly.
Definition at line 51 of file ConcatColumnsVMatrix.cc.
References build_(), PLearn::TVec< T >::size(), and sources.
: sources(the_sources), no_duplicate_fieldnames(false) { if (sources.size()) build_(); }
Definition at line 59 of file ConcatColumnsVMatrix.cc.
References build_(), and sources.
: sources(2), no_duplicate_fieldnames(false) { sources[0] = d1; sources[1] = d2; build_(); }
string PLearn::ConcatColumnsVMatrix::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 49 of file ConcatColumnsVMatrix.cc.
OptionList & PLearn::ConcatColumnsVMatrix::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 49 of file ConcatColumnsVMatrix.cc.
RemoteMethodMap & PLearn::ConcatColumnsVMatrix::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 49 of file ConcatColumnsVMatrix.cc.
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 49 of file ConcatColumnsVMatrix.cc.
Object * PLearn::ConcatColumnsVMatrix::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 49 of file ConcatColumnsVMatrix.cc.
StaticInitializer ConcatColumnsVMatrix::_static_initializer_ & PLearn::ConcatColumnsVMatrix::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 49 of file ConcatColumnsVMatrix.cc.
void PLearn::ConcatColumnsVMatrix::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::VMatrix.
Definition at line 89 of file ConcatColumnsVMatrix.cc.
References PLearn::VMatrix::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::ConcatColumnsVMatrix::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::VMatrix.
Definition at line 95 of file ConcatColumnsVMatrix.cc.
References PLearn::VMatrix::computeMissingSizeValue(), PLearn::VMatrix::fieldinfos, i, PLearn::VMatrix::init_map_sr(), j, PLearn::VMatrix::length(), PLearn::VMatrix::length_, no_duplicate_fieldnames, PLERROR, PLearn::TVec< T >::resize(), PLearn::VMatrix::setStringMapping(), PLearn::TVec< T >::size(), sources, PLearn::tostring(), PLearn::VMatrix::unduplicateFieldNames(), PLearn::VMatrix::updateMtime(), PLearn::VMatrix::width(), and PLearn::VMatrix::width_.
Referenced by build(), and ConcatColumnsVMatrix().
{ length_ = width_ = 0; if(sources.size()) length_ = sources[0]->length(); // else // PLERROR("ConcatColumnsVMatrix expects >= 1 underlying-sources, got 0"); for(int i=0; i<sources.size(); i++) { updateMtime(sources[i]); if(sources[i]->length()!=length_ && sources[i]->length()!=-1) PLERROR("ConcatColumnsVMatrix: Problem concatenating two VMat with" " different lengths"); if(sources[i]->width() == -1) PLERROR("In ConcatColumnsVMatrix constructor. Non-fixed width" " distribution not supported"); width_ += sources[i]->width(); } // Copy the original fieldinfos. Be careful if only some of the // matrices have fieldinfos fieldinfos.resize(width_); TVec<string> names; int fieldindex = 0; init_map_sr(); for (int i=0; i<sources.size(); ++i) { int len = sources[i]->getFieldInfos().size(); if (len > 0) // infos exist for this VMat { for (int j=0; j<len; ++j) { map<string,real> map = sources[i]->getStringToRealMapping(j); if (!map.empty()) setStringMapping(fieldindex, map); fieldinfos[fieldindex++] = sources[i]->getFieldInfos()[j]; } } else // infos don't exist for this VMat, use the index as the name for those fields. { len = sources[i]->width(); for(int j=0; j<len; ++j) { map<string,real> map = sources[i]->getStringToRealMapping(j); if (!map.empty()) setStringMapping(fieldindex, map); fieldinfos[fieldindex] = VMField(tostring(fieldindex)); fieldindex++; } } } if (no_duplicate_fieldnames) { unduplicateFieldNames(); } computeMissingSizeValue(false); }
string PLearn::ConcatColumnsVMatrix::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 49 of file ConcatColumnsVMatrix.cc.
void PLearn::ConcatColumnsVMatrix::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declare this class' options.
Reimplemented from PLearn::VMatrix.
Definition at line 69 of file ConcatColumnsVMatrix.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::VMatrix::declareOptions(), PLearn::OptionBase::learntoption, no_duplicate_fieldnames, PLearn::OptionBase::nosave, and sources.
{ declareOption(ol, "array", &ConcatColumnsVMatrix::sources, (OptionBase::learntoption | OptionBase::nosave), "DEPRECATED - Use 'sources' instead."); declareOption(ol, "sources", &ConcatColumnsVMatrix::sources, OptionBase::buildoption, "The VMat to concatenate (horizontally)."); declareOption(ol, "no_duplicate_fieldnames", &ConcatColumnsVMatrix::no_duplicate_fieldnames, OptionBase::buildoption, "If set to 1, will ensure no fieldnames are duplicated by" " adding\n" "numerical values '.1', '.2', ...\n"); inherited::declareOptions(ol); }
static const PPath& PLearn::ConcatColumnsVMatrix::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 89 of file ConcatColumnsVMatrix.h.
: void build_();
ConcatColumnsVMatrix * PLearn::ConcatColumnsVMatrix::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 49 of file ConcatColumnsVMatrix.cc.
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 245 of file ConcatColumnsVMatrix.cc.
References PLearn::TVec< T >::length(), PLearn::VMatrix::length_, PLearn::min(), n, PLERROR, PLearn::TVec< T >::size(), sources, PLearn::TVec< T >::subVec(), and PLearn::VMatrix::width().
{ if (length_==-1) PLERROR("In ConcatColumnsVMatrix::getRow(int i, Vec samplevec) not supported for distributions with different (or infinite) lengths\nCall sample without index instead"); real res = 0.; int pos = 0; for(int n=0; n<sources.size(); n++) { int nvars = std::min(sources[n]->width(),v.length()-pos); if(nvars<=0) break; Vec subv = v.subVec(pos, nvars); res += sources[n]->dot(i,subv); pos += nvars; } return res; }
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 224 of file ConcatColumnsVMatrix.cc.
References sources, and PLearn::VMat::width().
{ real res = 0.; for(int k=0; ;k++) { const VMat& vm = sources[k]; int vmwidth = vm.width(); if(inputsize<=vmwidth) { res += vm->dot(i1,i2,inputsize); break; } else { res += vm->dot(i1,i2,vmwidth); inputsize -= vmwidth; } } return res; }
PP< Dictionary > PLearn::ConcatColumnsVMatrix::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::VMatrix.
Definition at line 264 of file ConcatColumnsVMatrix.cc.
References PLERROR, sources, PLearn::VMatrix::width(), and PLearn::VMatrix::width_.
{ #ifdef BOUNDCHECK if(col>=width_) PLERROR("access out of bound. Width=%i accessed col=%i",width_,col); #endif int pos=0,k=0; while(col>=pos+sources[k]->width()) { pos += sources[k]->width(); k++; } return sources[k]->getDictionary(col-pos); }
This is the only method requiring implementation in subclasses.
Implements PLearn::RowBufferedVMatrix.
Definition at line 152 of file ConcatColumnsVMatrix.cc.
References PLearn::VMatrix::length_, n, PLERROR, PLearn::TVec< T >::size(), sources, and PLearn::TVec< T >::subVec().
{ if (length_==-1) PLERROR("In ConcatColumnsVMatrix::getNewRow(int i, Vec samplevec) not supported for distributions with different (or infinite) lengths\nCall sample without index instead"); int pos = 0; for(int n=0; n<sources.size(); n++) { int nvars = sources[n]->width(); Vec samplesubvec = samplevec.subVec(pos, nvars); sources[n]->getRow(i,samplesubvec); pos += nvars; } }
OptionList & PLearn::ConcatColumnsVMatrix::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 49 of file ConcatColumnsVMatrix.cc.
OptionMap & PLearn::ConcatColumnsVMatrix::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 49 of file ConcatColumnsVMatrix.cc.
RemoteMethodMap & PLearn::ConcatColumnsVMatrix::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 49 of file ConcatColumnsVMatrix.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 208 of file ConcatColumnsVMatrix.cc.
References PLERROR, sources, PLearn::VMatrix::width(), and PLearn::VMatrix::width_.
{ if(col>=width_) PLERROR("access out of bound. Width=%i accessed col=%i",width_,col); int pos=0,k=0; while(col>=pos+sources[k]->width()) { pos += sources[k]->width(); k++; } // return sources[k]->getString(row,pos+col); return sources[k]->getString(row,col-pos); }
returns the whole string->value mapping
Definition at line 194 of file ConcatColumnsVMatrix.cc.
References PLERROR, sources, PLearn::VMatrix::width(), and PLearn::VMatrix::width_.
{ if(col>=width_) PLERROR("access out of bound. Width=%i accessed col=%i",width_,col); int pos=0,k=0; while(col>=pos+sources[k]->width()) { pos += sources[k]->width(); k++; } // return sources[k]->getStringToRealMapping(pos+col); return sources[k]->getStringToRealMapping(col-pos); }
Returns value associated with a string (or MISSING_VALUE if there's no association for this string).
Reimplemented from PLearn::VMatrix.
Definition at line 166 of file ConcatColumnsVMatrix.cc.
References PLERROR, sources, PLearn::VMatrix::width(), and PLearn::VMatrix::width_.
{ if(col>=width_) PLERROR("access out of bound. Width=%i accessed col=%i",width_,col); int pos=0,k=0; while(col>=pos+sources[k]->width()) { pos += sources[k]->width(); k++; } // return sources[k]->getStringVal(pos+col,str); return sources[k]->getStringVal(col-pos,str); }
Returns the string associated with value val for field# col.
Or returns "" if no string is associated.
Reimplemented from PLearn::VMatrix.
Definition at line 180 of file ConcatColumnsVMatrix.cc.
References PLERROR, sources, PLearn::VMatrix::width(), and PLearn::VMatrix::width_.
{ if(col>=width_) PLERROR("access out of bound. Width=%i accessed col=%i",width_,col); int pos=0,k=0; while(col>=pos+sources[k]->width()) { pos += sources[k]->width(); k++; } // return sources[k]->getValString(pos+col,val); return sources[k]->getValString(col-pos,val); }
Gives the possible values for a certain field in the VMatrix.
Reimplemented from PLearn::VMatrix.
Definition at line 280 of file ConcatColumnsVMatrix.cc.
References PLERROR, sources, PLearn::VMatrix::width(), and PLearn::VMatrix::width_.
{ #ifdef BOUNDCHECK if(col>=width_) PLERROR("access out of bound. Width=%i accessed col=%i",width_,col); #endif int pos=0,k=0; while(col>=pos+sources[k]->width()) { pos += sources[k]->width(); k++; } sources[k]->getValues(row,col-pos,values); }
void PLearn::ConcatColumnsVMatrix::getValues | ( | const Vec & | input, |
int | col, | ||
Vec & | values | ||
) | const [virtual] |
Gives the possible values of a certain field (column) given the input.
Reimplemented from PLearn::VMatrix.
Definition at line 295 of file ConcatColumnsVMatrix.cc.
References PLERROR, sources, PLearn::TVec< T >::subVec(), PLearn::VMatrix::width(), and PLearn::VMatrix::width_.
{ #ifdef BOUNDCHECK if(col>=width_) PLERROR("access out of bound. Width=%i accessed col=%i",width_,col); #endif int pos=0,k=0; while(col>=pos+sources[k]->width()) { pos += sources[k]->width(); k++; } sources[k]->getValues(input.subVec(pos,sources[k]->width()), col-pos, values); }
void PLearn::ConcatColumnsVMatrix::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 310 of file ConcatColumnsVMatrix.cc.
References PLearn::deepCopyField(), PLearn::RowBufferedVMatrix::makeDeepCopyFromShallowCopy(), and sources.
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(sources, copies); }
Sets element (i,j) to value.
Reimplemented from PLearn::VMatrix.
Definition at line 316 of file ConcatColumnsVMatrix.cc.
References PLERROR, sources, PLearn::VMatrix::width(), and PLearn::VMatrix::width_.
{ #ifdef BOUNDCHECK if(j>=width_) PLERROR("access out of bound. Width=%i accessed col=%i",width_,j); #endif int pos=0,k=0; while(j>=pos+sources[k]->width()) { pos += sources[k]->width(); k++; } sources[k]->put(i,j-pos,value); }
virtual void PLearn::ConcatColumnsVMatrix::reset_dimensions | ( | ) | [inline, virtual] |
In case the dimensions of an underlying VMat has changed, recompute it.
Reimplemented from PLearn::VMatrix.
Definition at line 83 of file ConcatColumnsVMatrix.h.
References PLERROR.
{ PLERROR("ConcatColumnsVMatrix::reset_dimensions() not implemented"); }
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 89 of file ConcatColumnsVMatrix.h.
Definition at line 64 of file ConcatColumnsVMatrix.h.
Referenced by build_(), and declareOptions().
TVec<VMat> PLearn::ConcatColumnsVMatrix::sources [protected] |
Definition at line 60 of file ConcatColumnsVMatrix.h.
Referenced by build_(), ConcatColumnsVMatrix(), declareOptions(), dot(), getDictionary(), getNewRow(), getString(), getStringMapping(), getStringVal(), getValString(), getValues(), makeDeepCopyFromShallowCopy(), and put().