|
PLearn 0.1
|
#include <CumVMatrix.h>


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 OptionList & | getOptionList () const |
| virtual OptionMap & | getOptionMap () const |
| virtual RemoteMethodMap & | getRemoteMethodMap () const |
| virtual CumVMatrix * | deepCopy (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 PPath & | declaringFile () |
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< int > | columns |
| bool | average |
Private Types | |
| typedef SourceVMatrix | inherited |
Private Member Functions | |
| void | build_ () |
| This does the actual building. | |
Definition at line 52 of file CumVMatrix.h.
typedef SourceVMatrix PLearn::CumVMatrix::inherited [private] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 54 of file CumVMatrix.h.
| PLearn::CumVMatrix::CumVMatrix | ( | ) |
Definition at line 50 of file CumVMatrix.cc.
| 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.
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_().
{
inherited::build();
build_();
}

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


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

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

| 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().
{
inherited::makeDeepCopyFromShallowCopy(copies);
deepCopyField(columns_to_accumulate, copies);
deepCopyField(accumulated_columns, copies);
deepCopyField(columns, copies);
}

Reimplemented from PLearn::SourceVMatrix.
Definition at line 109 of file CumVMatrix.h.
Mat PLearn::CumVMatrix::accumulated_columns [protected] |
Definition at line 61 of file CumVMatrix.h.
Referenced by build_(), getNewRow(), and makeDeepCopyFromShallowCopy().
bool PLearn::CumVMatrix::average [protected] |
Definition at line 65 of file CumVMatrix.h.
Referenced by declareOptions(), and getNewRow().
TVec<int> PLearn::CumVMatrix::columns [protected] |
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().
Vec PLearn::CumVMatrix::previous_sourcerow [protected] |
Definition at line 63 of file CumVMatrix.h.
Referenced by build_(), and getNewRow().
Vec PLearn::CumVMatrix::row [protected] |
Definition at line 62 of file CumVMatrix.h.
Referenced by build_(), and getNewRow().
1.7.4