PLearn 0.1
|
#include <JoinVMatrix.h>
Public Member Functions | |
JoinVMatrix () | |
JoinVMatrix (VMat mas, VMat sla, TVec< int > mi, TVec< int > si) | |
void | addStatField (const string &statis, const string &namefrom, const string &nameto) |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual JoinVMatrix * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Simply calls inherited::build() then build_(). | |
virtual string | getValString (int col, real val) const |
Returns the string associated with value val for field# col. | |
virtual const map< string, real > & | getStringToRealMapping (int col) const |
Returns the string->real mapping for column 'col'. | |
virtual const map< real, string > & | getRealToStringMapping (int col) const |
Returns the real->string mapping for column 'col'. | |
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 | 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. | |
Static Public Member Functions | |
static string | _classname_ () |
RowBufferedVMatrix. | |
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) |
Declare this class' options. | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
virtual void | getNewRow (int idx, const Vec &v) const |
This is the only method requiring implementation in subclasses. | |
Private Types | |
typedef RowBufferedVMatrix | inherited |
typedef hash_multimap< Vec, int > | Maptype |
the fields generated by the join operation (declared with addStatField) | |
Private Member Functions | |
void | build_ () |
This does the actual building. | |
Private Attributes | |
vector< JoinFieldStat > | fld |
VMat | master |
VMat | slave |
Vec | temp |
Vec | tempkey |
TVec< int > | master_idx |
TVec< int > | slave_idx |
Maptype | mp |
Definition at line 71 of file JoinVMatrix.h.
typedef RowBufferedVMatrix PLearn::JoinVMatrix::inherited [private] |
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 73 of file JoinVMatrix.h.
typedef hash_multimap<Vec,int> PLearn::JoinVMatrix::Maptype [private] |
the fields generated by the join operation (declared with addStatField)
Definition at line 76 of file JoinVMatrix.h.
PLearn::JoinVMatrix::JoinVMatrix | ( | ) | [inline] |
Definition at line 87 of file JoinVMatrix.h.
{};
Definition at line 49 of file JoinVMatrix.cc.
References build().
: inherited(mas.length(),mas.width()),master(mas),slave(sla),master_idx(mi),slave_idx(si) { build(); }
string PLearn::JoinVMatrix::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 47 of file JoinVMatrix.cc.
OptionList & PLearn::JoinVMatrix::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 47 of file JoinVMatrix.cc.
RemoteMethodMap & PLearn::JoinVMatrix::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 47 of file JoinVMatrix.cc.
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 47 of file JoinVMatrix.cc.
Object * PLearn::JoinVMatrix::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 47 of file JoinVMatrix.cc.
StaticInitializer JoinVMatrix::_static_initializer_ & PLearn::JoinVMatrix::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 47 of file JoinVMatrix.cc.
void PLearn::JoinVMatrix::addStatField | ( | const string & | statis, |
const string & | namefrom, | ||
const string & | nameto | ||
) |
Definition at line 97 of file JoinVMatrix.cc.
References PLearn::JoinFieldStat::COUNT, PLearn::VMatrix::declareField(), fld, PLearn::JoinFieldStat::MAX, PLearn::JoinFieldStat::MEAN, PLearn::JoinFieldStat::MIN, PLearn::JoinFieldStat::NMISSING, PLearn::JoinFieldStat::NNONMISSING, PLERROR, slave, PLearn::JoinFieldStat::STDDEV, PLearn::JoinFieldStat::STDERR, PLearn::JoinFieldStat::SUM, PLearn::JoinFieldStat::SUMSQUARE, PLearn::VMField::UnknownType, PLearn::JoinFieldStat::VARIANCE, PLearn::VMatrix::width(), and PLearn::VMatrix::width_.
Referenced by PLearn::VVMatrix::processJoinSection().
{ width_++; int from=slave->fieldIndex(namefrom),to=width()-1; if(from==-1) PLERROR("Unknown field in JOIN operation : %s",namefrom.c_str()); declareField(to, nameto, VMField::UnknownType); if(statis=="COUNT") fld.push_back(JoinFieldStat(from,to,JoinFieldStat::COUNT)); else if(statis=="NMISSING") fld.push_back(JoinFieldStat(from,to,JoinFieldStat::NMISSING)); else if(statis=="NNONMISSING") fld.push_back(JoinFieldStat(from,to,JoinFieldStat::NNONMISSING)); else if(statis=="SUM") fld.push_back(JoinFieldStat(from,to,JoinFieldStat::SUM)); else if(statis=="SUMSQUARE") fld.push_back(JoinFieldStat(from,to,JoinFieldStat::SUMSQUARE)); else if(statis=="MEAN") fld.push_back(JoinFieldStat(from,to,JoinFieldStat::MEAN)); else if(statis=="VARIANCE") fld.push_back(JoinFieldStat(from,to,JoinFieldStat::VARIANCE)); else if(statis=="MIN") fld.push_back(JoinFieldStat(from,to,JoinFieldStat::MIN)); else if(statis=="MAX") fld.push_back(JoinFieldStat(from,to,JoinFieldStat::MAX)); else if(statis=="STDDEV") fld.push_back(JoinFieldStat(from,to,JoinFieldStat::STDDEV)); else if(statis=="STDERR") fld.push_back(JoinFieldStat(from,to,JoinFieldStat::STDERR)); else PLERROR("Unknown statistic in JOIN operation : %s",statis.c_str()); }
void PLearn::JoinVMatrix::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::VMatrix.
Definition at line 56 of file JoinVMatrix.cc.
References PLearn::VMatrix::build(), and build_().
Referenced by JoinVMatrix().
{ inherited::build(); build_(); }
void PLearn::JoinVMatrix::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::VMatrix.
Definition at line 63 of file JoinVMatrix.cc.
References PLearn::VMatrix::declareField(), PLearn::VMat::fieldName(), i, j, PLearn::VMat::length(), master, master_idx, mp, PLERROR, PLearn::TVec< T >::resize(), PLearn::TVec< T >::size(), slave, slave_idx, temp, tempkey, PLearn::VMField::UnknownType, PLearn::VMatrix::updateMtime(), PLearn::VMat::width(), and PLearn::VMatrix::width().
Referenced by build().
{ if (master && slave) { if(master_idx.size()!=slave_idx.size()) PLERROR("JoinVMatrix : master and slave field correspondance don't have same dimensions "); for(int j=0;j<width();j++) declareField(j, master->fieldName(j), VMField::UnknownType); temp.resize(slave.width()); tempkey.resize(master_idx.size()); for(int i=0;i<slave.length();i++) { slave->getRow(i,temp); int s=slave_idx.size(); for(int j=0;j<s;j++) tempkey[j]=temp[slave_idx[j]]; mp.insert(make_pair(tempkey,i)); } updateMtime(master); updateMtime(slave); } }
string PLearn::JoinVMatrix::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 47 of file JoinVMatrix.cc.
void PLearn::JoinVMatrix::declareOptions | ( | OptionList & | ol | ) | [static] |
Declare this class' options.
Reimplemented from PLearn::VMatrix.
Definition at line 88 of file JoinVMatrix.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::VMatrix::declareOptions(), master, master_idx, slave, and slave_idx.
{ declareOption(ol, "master", &JoinVMatrix::master, OptionBase::buildoption, ""); declareOption(ol, "slave", &JoinVMatrix::slave, OptionBase::buildoption, ""); declareOption(ol, "master_idx", &JoinVMatrix::master_idx, OptionBase::buildoption, ""); declareOption(ol, "slave_idx", &JoinVMatrix::slave_idx, OptionBase::buildoption, ""); inherited::declareOptions(ol); }
static const PPath& PLearn::JoinVMatrix::declaringFile | ( | ) | [inline, static] |
JoinVMatrix * PLearn::JoinVMatrix::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 47 of file JoinVMatrix.cc.
This is the only method requiring implementation in subclasses.
Implements PLearn::RowBufferedVMatrix.
Definition at line 130 of file JoinVMatrix.cc.
References PLearn::JoinFieldStat::COUNT, fld, i, PLearn::is_missing(), j, master, master_idx, PLearn::JoinFieldStat::MAX, PLearn::max(), PLearn::JoinFieldStat::MEAN, PLearn::JoinFieldStat::MIN, PLearn::min(), mp, PLearn::JoinFieldStat::NMISSING, PLearn::JoinFieldStat::NNONMISSING, PLERROR, PLearn::TVec< T >::size(), slave, PLearn::sqrt(), PLearn::JoinFieldStat::STDDEV, PLearn::JoinFieldStat::STDERR, PLearn::TVec< T >::subVec(), PLearn::JoinFieldStat::SUM, PLearn::sum(), PLearn::JoinFieldStat::SUMSQUARE, PLearn::sumsquare(), temp, tempkey, PLearn::JoinFieldStat::VARIANCE, PLearn::VMatrix::width(), and PLearn::VMat::width().
{ real nonmiss; master->getRow(idx,v.subVec(0,master.width())); // build a key used to search in the slave matrix int s=master_idx.size(); for(int j=0;j<s;j++) tempkey[j]=v[master_idx[j]]; Maptype::const_iterator it,low,upp; pair<Maptype::const_iterator,Maptype::const_iterator> tit=mp.equal_range(tempkey); low=tit.first; upp=tit.second; Vec popo(v.subVec(master.width(),width()-master.width())); int sz=(int)fld.size(); Vec count(sz,0.0),nmissing(sz,0.0),sum(sz,0.0),sumsquare(sz,0.0),min(sz,FLT_MAX),max(sz,-FLT_MAX); real val; if(low!=mp.end()) { for(it=low;it!=upp;++it) { slave->getRow(it->second,temp); for(int i=0;i<sz;i++) { val=temp[fld[i].from]; count[i]++; if(is_missing(val))nmissing[i]++; else { sum[i]+=val; sumsquare[i]+=val*val; if(min[i]>val)min[i]=val; if(max[i]<val)max[i]=val; } } } } for(int i=0;i<sz;i++) { nonmiss=count[i]-nmissing[i]; switch(fld[i].stat) { case JoinFieldStat::COUNT: popo[i]=count[i]; break; case JoinFieldStat::NMISSING: popo[i]=nmissing[i]; break; case JoinFieldStat::NNONMISSING: popo[i]=nonmiss; break; case JoinFieldStat::SUM: popo[i]=sum[i]; break; case JoinFieldStat::SUMSQUARE: popo[i]=sumsquare[i]; break; case JoinFieldStat::MEAN: popo[i]=sum[i]/count[i]; break; case JoinFieldStat::VARIANCE: popo[i]=(sumsquare[i] - sum[i]*sum[i]/nonmiss)/(nonmiss-1); break; case JoinFieldStat::STDDEV: popo[i]=sqrt((sumsquare[i] - sum[i]*sum[i]/nonmiss)/(nonmiss-1)); break; case JoinFieldStat::STDERR: popo[i]=sqrt((sumsquare[i] - sum[i]*sum[i]/nonmiss)/(nonmiss-1)/nonmiss); break; case JoinFieldStat::MIN: popo[i]=min[i]; break; case JoinFieldStat::MAX: popo[i]=max[i]; break; default:PLERROR("Unknown statistic in JoinVMatrix!"); } } }
OptionList & PLearn::JoinVMatrix::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 47 of file JoinVMatrix.cc.
OptionMap & PLearn::JoinVMatrix::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 47 of file JoinVMatrix.cc.
Returns the real->string mapping for column 'col'.
Reimplemented from PLearn::VMatrix.
Definition at line 237 of file JoinVMatrix.cc.
References master, slave, and PLearn::VMat::width().
{ if(col<master.width()) return master->getRealToStringMapping(col); else return slave->getRealToStringMapping(col); }
RemoteMethodMap & PLearn::JoinVMatrix::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 47 of file JoinVMatrix.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 246 of file JoinVMatrix.cc.
References master, slave, and PLearn::VMat::width().
{ if(col<master.width()) return master->getString(row,col); else return slave->getString(row,col); }
Returns the string->real mapping for column 'col'.
Reimplemented from PLearn::VMatrix.
Definition at line 228 of file JoinVMatrix.cc.
References master, slave, and PLearn::VMat::width().
{ if(col<master.width()) return master->getStringToRealMapping(col); else return slave->getStringToRealMapping(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 220 of file JoinVMatrix.cc.
References master, slave, and PLearn::VMat::width().
{ if(col<master.width()) return master->getStringVal(col,str); else return slave->getStringVal(col,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 212 of file JoinVMatrix.cc.
References master, slave, and PLearn::VMat::width().
{ if(col<master.width()) return master->getValString(col,val); else return slave->getValString(col,val); }
Reimplemented from PLearn::RowBufferedVMatrix.
Definition at line 91 of file JoinVMatrix.h.
vector<JoinFieldStat> PLearn::JoinVMatrix::fld [private] |
Definition at line 78 of file JoinVMatrix.h.
Referenced by addStatField(), and getNewRow().
VMat PLearn::JoinVMatrix::master [private] |
Definition at line 79 of file JoinVMatrix.h.
Referenced by build_(), declareOptions(), getNewRow(), getRealToStringMapping(), getString(), getStringToRealMapping(), getStringVal(), and getValString().
TVec<int> PLearn::JoinVMatrix::master_idx [private] |
Definition at line 81 of file JoinVMatrix.h.
Referenced by build_(), declareOptions(), and getNewRow().
Maptype PLearn::JoinVMatrix::mp [private] |
Definition at line 83 of file JoinVMatrix.h.
Referenced by build_(), and getNewRow().
VMat PLearn::JoinVMatrix::slave [private] |
Definition at line 79 of file JoinVMatrix.h.
Referenced by addStatField(), build_(), declareOptions(), getNewRow(), getRealToStringMapping(), getString(), getStringToRealMapping(), getStringVal(), and getValString().
TVec<int> PLearn::JoinVMatrix::slave_idx [private] |
Definition at line 82 of file JoinVMatrix.h.
Referenced by build_(), and declareOptions().
Vec PLearn::JoinVMatrix::temp [private] |
Definition at line 80 of file JoinVMatrix.h.
Referenced by build_(), and getNewRow().
Vec PLearn::JoinVMatrix::tempkey [private] |
Definition at line 80 of file JoinVMatrix.h.
Referenced by build_(), and getNewRow().