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

#include <ConcatColumnsVMatrix.h>

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

List of all members.

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 OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual ConcatColumnsVMatrixdeepCopy (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< DictionarygetDictionary (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 PPathdeclaringFile ()

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< VMatsources

Private Types

typedef RowBufferedVMatrix inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Definition at line 54 of file ConcatColumnsVMatrix.h.


Member Typedef Documentation

Reimplemented from PLearn::RowBufferedVMatrix.

Definition at line 56 of file ConcatColumnsVMatrix.h.


Constructor & Destructor Documentation

PLearn::ConcatColumnsVMatrix::ConcatColumnsVMatrix ( TVec< VMat the_sources = TVec<VMat>())

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

Here is the call graph for this function:

PLearn::ConcatColumnsVMatrix::ConcatColumnsVMatrix ( VMat  d1,
VMat  d2 
)

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

Here is the call graph for this function:


Member Function Documentation

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

ConcatColumnsVMatrix.

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.

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

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

Here is the call graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

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.

real PLearn::ConcatColumnsVMatrix::dot ( int  i,
const Vec v 
) const [virtual]

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

Here is the call graph for this function:

real PLearn::ConcatColumnsVMatrix::dot ( int  i1,
int  i2,
int  inputsize 
) const [virtual]

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

Here is the call graph for this function:

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

Here is the call graph for this function:

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

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

Here is the call graph for this function:

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.

string PLearn::ConcatColumnsVMatrix::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 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);
}

Here is the call graph for this function:

const map< string, real > & PLearn::ConcatColumnsVMatrix::getStringMapping ( int  col) const

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

Here is the call graph for this function:

real PLearn::ConcatColumnsVMatrix::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 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);
}

Here is the call graph for this function:

string PLearn::ConcatColumnsVMatrix::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 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);
}

Here is the call graph for this function:

void PLearn::ConcatColumnsVMatrix::getValues ( int  row,
int  col,
Vec values 
) const [virtual]

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

Here is the call graph for this function:

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

Here is the call graph for this function:

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.

Here is the call graph for this function:

void PLearn::ConcatColumnsVMatrix::put ( int  i,
int  j,
real  value 
) [virtual]

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

Here is the call graph for this function:

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

Member Data Documentation

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


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