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

#include <JoinVMatrix.h>

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

List of all members.

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 OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual JoinVMatrixdeepCopy (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 PPathdeclaringFile ()
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, intMaptype
 the fields generated by the join operation (declared with addStatField)

Private Member Functions

void build_ ()
 This does the actual building.

Private Attributes

vector< JoinFieldStatfld
VMat master
VMat slave
Vec temp
Vec tempkey
TVec< intmaster_idx
TVec< intslave_idx
Maptype mp

Detailed Description

Definition at line 71 of file JoinVMatrix.h.


Member Typedef Documentation

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.


Constructor & Destructor Documentation

PLearn::JoinVMatrix::JoinVMatrix ( ) [inline]

Definition at line 87 of file JoinVMatrix.h.

{};
PLearn::JoinVMatrix::JoinVMatrix ( VMat  mas,
VMat  sla,
TVec< int mi,
TVec< int si 
)

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

Here is the call graph for this function:


Member Function Documentation

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

RowBufferedVMatrix.

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.

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Here is the call graph for this function:

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

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 91 of file JoinVMatrix.h.

:

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

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 47 of file JoinVMatrix.cc.

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

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

Here is the call graph for this function:

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.

const map< real, string > & PLearn::JoinVMatrix::getRealToStringMapping ( int  col) const [virtual]

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

Here is the call graph for this function:

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

Reimplemented from PLearn::Object.

Definition at line 47 of file JoinVMatrix.cc.

string PLearn::JoinVMatrix::getString ( int  row,
int  col 
) const [virtual]

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

Here is the call graph for this function:

const map< string, real > & PLearn::JoinVMatrix::getStringToRealMapping ( int  col) const [virtual]

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

}

Here is the call graph for this function:

real PLearn::JoinVMatrix::getStringVal ( int  col,
const string &  str 
) const [virtual]

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

Here is the call graph for this function:

string PLearn::JoinVMatrix::getValString ( int  col,
real  val 
) const [virtual]

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

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 91 of file JoinVMatrix.h.

Definition at line 78 of file JoinVMatrix.h.

Referenced by addStatField(), and getNewRow().

Definition at line 81 of file JoinVMatrix.h.

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

Definition at line 83 of file JoinVMatrix.h.

Referenced by build_(), and getNewRow().

Definition at line 82 of file JoinVMatrix.h.

Referenced by build_(), and declareOptions().

Definition at line 80 of file JoinVMatrix.h.

Referenced by build_(), and getNewRow().

Definition at line 80 of file JoinVMatrix.h.

Referenced by build_(), and getNewRow().


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