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::CumVMatrix Class Reference

#include <CumVMatrix.h>

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

List of all members.

Public Member Functions

 CumVMatrix ()
virtual void build ()
 Simply calls inherited::build() then build_().
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual CumVMatrixdeepCopy (CopiesMap &copies) const

Static Public Member Functions

static string _classname_ ()
 Declares name and deepCopy methods.
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

TVec< string > columns_to_accumulate

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Member Functions

virtual void getNewRow (int i, const Vec &v) const
 This is the only method requiring implementation.

Static Protected Member Functions

static void declareOptions (OptionList &ol)
 Declares this class' options.

Protected Attributes

Mat accumulated_columns
Vec row
Vec previous_sourcerow
TVec< intcolumns
bool average

Private Types

typedef SourceVMatrix inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Definition at line 52 of file CumVMatrix.h.


Member Typedef Documentation

Reimplemented from PLearn::SourceVMatrix.

Definition at line 54 of file CumVMatrix.h.


Constructor & Destructor Documentation

PLearn::CumVMatrix::CumVMatrix ( )

Definition at line 50 of file CumVMatrix.cc.

    :inherited(), average(false)
    /* ### Initialise all fields to their default value */
{
    // ...

    // ### You may or may not want to call build_() to finish building the object
    // build_();
}

Member Function Documentation

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

Declares name and deepCopy methods.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file CumVMatrix.cc.

OptionList & PLearn::CumVMatrix::_getOptionList_ ( ) [static]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file CumVMatrix.cc.

RemoteMethodMap & PLearn::CumVMatrix::_getRemoteMethodMap_ ( ) [static]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file CumVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file CumVMatrix.cc.

Object * PLearn::CumVMatrix::_new_instance_for_typemap_ ( ) [static]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file CumVMatrix.cc.

StaticInitializer CumVMatrix::_static_initializer_ & PLearn::CumVMatrix::_static_initialize_ ( ) [static]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file CumVMatrix.cc.

void PLearn::CumVMatrix::build ( ) [virtual]

Simply calls inherited::build() then build_().

Reimplemented from PLearn::SourceVMatrix.

Definition at line 159 of file CumVMatrix.cc.

References PLearn::SourceVMatrix::build(), and build_().

Here is the call graph for this function:

void PLearn::CumVMatrix::build_ ( ) [private]

This does the actual building.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 118 of file CumVMatrix.cc.

References accumulated_columns, columns, columns_to_accumulate, PLearn::TMat< T >::fill(), PLearn::VMatrix::hasFieldInfos(), j, PLearn::VMat::length(), PLearn::TVec< T >::length(), PLearn::VMatrix::length_, MISSING_VALUE, PLERROR, previous_sourcerow, PLearn::TMat< T >::resize(), PLearn::TVec< T >::resize(), row, PLearn::VMatrix::setFieldInfos(), PLearn::TVec< T >::size(), PLearn::SourceVMatrix::source, PLearn::SourceVMatrix::sourcerow, PLearn::TVec< T >::subVec(), PLearn::VMatrix::updateMtime(), w, PLearn::VMat::width(), and PLearn::VMatrix::width_.

Referenced by build().

{
    int nc=columns_to_accumulate.length();
    if (source)
    {
        row.resize(source->width()+nc);
        sourcerow = row.subVec(0,source->width());
        previous_sourcerow.resize(source->width());
        columns.resize(nc);
        for (int j=0;j<nc;j++)
            if ((columns[j] = source->fieldIndex(columns_to_accumulate[j])) == -1)
                PLERROR("CumVMatrix: provided field name %s not found in source VMatrix",columns_to_accumulate[j].c_str());

        updateMtime(source);

        // copy length and width from source if not set
        if(length_<0)
            length_ = source->length();
        if(width_<0)
            width_ = source->width() + nc;

        accumulated_columns.resize(length_,nc);
        accumulated_columns.fill(MISSING_VALUE);

        // copy fieldnames from source if not set and they look good
        if(!hasFieldInfos() && source->hasFieldInfos() )
        {
            Array<VMField>& sinfo = source->getFieldInfos();
            int w=sinfo.size();
            sinfo.resize(w+nc);
            for (int j=0;j<nc;j++)
            {
                sinfo[w+j]=sinfo[columns[j]];
                sinfo[w+j].name = "cum-"+sinfo[w+j].name;
            }
            setFieldInfos(sinfo);
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

string PLearn::CumVMatrix::classname ( ) const [virtual]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file CumVMatrix.cc.

void PLearn::CumVMatrix::declareOptions ( OptionList ol) [static, protected]

Declares this class' options.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 100 of file CumVMatrix.cc.

References average, PLearn::OptionBase::buildoption, columns_to_accumulate, PLearn::declareOption(), and PLearn::SourceVMatrix::declareOptions().

{
    // ### Declare all of this object's options here
    // ### For the "flags" of each option, you should typically specify
    // ### one of OptionBase::buildoption, OptionBase::learntoption or
    // ### OptionBase::tuningoption. Another possible flag to be combined with
    // ### is OptionBase::nosave

    declareOption(ol, "columns_to_accumulate", &CumVMatrix::columns_to_accumulate, OptionBase::buildoption,
                  "Names of the columns to accumulate.");

    declareOption(ol, "average", &CumVMatrix::average, OptionBase::buildoption,
                  "whether to report the sum (default, when average=false) or the average");

    // Now call the parent class' declareOptions
    inherited::declareOptions(ol);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 109 of file CumVMatrix.h.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file CumVMatrix.cc.

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

This is the only method requiring implementation.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 65 of file CumVMatrix.cc.

References accumulated_columns, average, columns, columns_to_accumulate, i, PLearn::is_missing(), j, PLearn::TVec< T >::length(), previous_sourcerow, row, PLearn::SourceVMatrix::source, and PLearn::SourceVMatrix::sourcerow.

{
    source->getRow(i,sourcerow);
    if (is_missing(accumulated_columns(i,0)))
    {
        int k=i-1;
        while (k>=0 && is_missing(accumulated_columns(k,0))) k--;
        if (k<0)
        {
            k=0;
            source->getRow(k,previous_sourcerow);
            for (int j=0;j<columns.length();j++)
                accumulated_columns(k,j) = previous_sourcerow[columns[j]];
        }
        for (;k<i;k++)
        {
            source->getRow(k+1,previous_sourcerow);
            for (int j=0;j<columns.length();j++)
                accumulated_columns(k+1,j) = accumulated_columns(k,j) + previous_sourcerow[columns[j]];
        }
    }
    if (average)
    {
        real normalization = 1.0 / (i+1);
        for (int j=0;j<columns_to_accumulate.length();j++)
            row[sourcerow.length()+j]=normalization*accumulated_columns(i,j);
    }
    else
    {
        for (int j=0;j<columns_to_accumulate.length();j++)
            row[sourcerow.length()+j]=accumulated_columns(i,j);
    }
    v << row;
}

Here is the call graph for this function:

OptionList & PLearn::CumVMatrix::getOptionList ( ) const [virtual]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file CumVMatrix.cc.

OptionMap & PLearn::CumVMatrix::getOptionMap ( ) const [virtual]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file CumVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file CumVMatrix.cc.

void PLearn::CumVMatrix::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 165 of file CumVMatrix.cc.

References accumulated_columns, columns, columns_to_accumulate, PLearn::deepCopyField(), and PLearn::SourceVMatrix::makeDeepCopyFromShallowCopy().

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::SourceVMatrix.

Definition at line 109 of file CumVMatrix.h.

Definition at line 61 of file CumVMatrix.h.

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

Definition at line 65 of file CumVMatrix.h.

Referenced by declareOptions(), and getNewRow().

Definition at line 64 of file CumVMatrix.h.

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

Definition at line 74 of file CumVMatrix.h.

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

Definition at line 63 of file CumVMatrix.h.

Referenced by build_(), and getNewRow().

Definition at line 62 of file CumVMatrix.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