|
PLearn 0.1
|
#include <MovingAverageVMatrix.h>


Public Member Functions | |
| MovingAverageVMatrix () | |
| virtual void | getNewRow (int i, Vec &v) const |
| This is the only method requiring implementation. | |
| 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 MovingAverageVMatrix * | 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_average |
| TVec< int > | window_sizes |
| bool | centered_windows |
Static Public Attributes | |
| static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
| static void | declareOptions (OptionList &ol) |
| Declares this class' options. | |
Protected Attributes | |
| Mat | sums |
| Mat | ma |
| TMat< int > | nnonmissing |
| Vec | row |
| Vec | previous_sourcerow |
| TVec< int > | columns |
| int | max_window_size |
Private Types | |
| typedef SourceVMatrix | inherited |
Private Member Functions | |
| void | build_ () |
| This does the actual building. | |
Definition at line 52 of file MovingAverageVMatrix.h.
typedef SourceVMatrix PLearn::MovingAverageVMatrix::inherited [private] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 54 of file MovingAverageVMatrix.h.
| PLearn::MovingAverageVMatrix::MovingAverageVMatrix | ( | ) |
Definition at line 51 of file MovingAverageVMatrix.cc.
:inherited(), centered_windows(true) /* ### Initialise all fields to their default value */ { // ... // ### You may or may not want to call build_() to finish building the object // build_(); }
| string PLearn::MovingAverageVMatrix::_classname_ | ( | ) | [static] |
Declares name and deepCopy methods.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 65 of file MovingAverageVMatrix.cc.
| OptionList & PLearn::MovingAverageVMatrix::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 65 of file MovingAverageVMatrix.cc.
| RemoteMethodMap & PLearn::MovingAverageVMatrix::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 65 of file MovingAverageVMatrix.cc.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 65 of file MovingAverageVMatrix.cc.
| Object * PLearn::MovingAverageVMatrix::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 65 of file MovingAverageVMatrix.cc.
| StaticInitializer MovingAverageVMatrix::_static_initializer_ & PLearn::MovingAverageVMatrix::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 65 of file MovingAverageVMatrix.cc.
| void PLearn::MovingAverageVMatrix::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::SourceVMatrix.
Definition at line 204 of file MovingAverageVMatrix.cc.
References PLearn::SourceVMatrix::build(), and build_().
{
inherited::build();
build_();
}

| void PLearn::MovingAverageVMatrix::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 151 of file MovingAverageVMatrix.cc.
References PLearn::TMat< T >::clear(), columns, columns_to_average, PLearn::TMat< T >::fill(), PLearn::VMatrix::hasFieldInfos(), j, PLearn::VMat::length(), PLearn::TVec< T >::length(), PLearn::VMatrix::length_, ma, max_window_size, MISSING_VALUE, nnonmissing, 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(), sums, PLearn::tostring(), PLearn::VMatrix::updateMtime(), w, PLearn::VMat::width(), PLearn::VMatrix::width_, and window_sizes.
Referenced by build().
{
int nc=columns_to_average.length();
if (source)
{
row.resize(source->width()+nc);
sourcerow = row.subVec(0,source->width());
previous_sourcerow.resize(source->width());
columns.resize(nc);
max_window_size=0;
if (window_sizes.length()!=nc)
PLERROR("MovingAverageVMatrix: the window_sizes option should have the same length as the columns_to_average option (got %d and %d)",
window_sizes.length(),nc);
for (int j=0;j<nc;j++)
{
if ((columns[j] = source->fieldIndex(columns_to_average[j])) == -1)
PLERROR("MovingAverageVMatrix: provided field name %s not found in source VMatrix",columns_to_average[j].c_str());
if (window_sizes[j]>max_window_size)
max_window_size=window_sizes[j];
}
updateMtime(source);
// copy length and width from source if not set
if(length_<0)
length_ = source->length();
if(width_<0)
width_ = source->width() + nc;
sums.resize(length_,nc);
sums.fill(MISSING_VALUE);
nnonmissing.resize(length_,nc);
nnonmissing.clear();
ma.resize(length_,nc);
ma.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 = "ma"+tostring(window_sizes[j])+"-"+sinfo[w+j].name;
}
setFieldInfos(sinfo);
}
}
}


| string PLearn::MovingAverageVMatrix::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 65 of file MovingAverageVMatrix.cc.
| void PLearn::MovingAverageVMatrix::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 130 of file MovingAverageVMatrix.cc.
References PLearn::OptionBase::buildoption, centered_windows, columns_to_average, PLearn::declareOption(), PLearn::SourceVMatrix::declareOptions(), and window_sizes.
{
// ### 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_average", &MovingAverageVMatrix::columns_to_average, OptionBase::buildoption,
"Names of the columns to average.");
declareOption(ol, "window_sizes", &MovingAverageVMatrix::window_sizes, OptionBase::buildoption,
"Sizes (in number of rows) of the moving average windows for each column to average.");
declareOption(ol, "centered_windows", &MovingAverageVMatrix::centered_windows, OptionBase::buildoption,
"Wether or not to center the window around the current example or to average only over previous examples");
// Now call the parent class' declareOptions
inherited::declareOptions(ol);
}

| static const PPath& PLearn::MovingAverageVMatrix::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 113 of file MovingAverageVMatrix.h.
| MovingAverageVMatrix * PLearn::MovingAverageVMatrix::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 65 of file MovingAverageVMatrix.cc.
This is the only method requiring implementation.
Definition at line 67 of file MovingAverageVMatrix.cc.
References centered_windows, columns, columns_to_average, i, PLearn::is_missing(), j, PLearn::TVec< T >::length(), PLearn::VMatrix::length(), ma, max_window_size, PLearn::min(), MISSING_VALUE, n, nnonmissing, previous_sourcerow, row, PLearn::SourceVMatrix::source, PLearn::SourceVMatrix::sourcerow, sums, and window_sizes.
{
source->getRow(i,sourcerow);
int max_target = centered_windows?min(i+max_window_size/2,length()-1):i;
if (is_missing(sums(max_target,0)))
{
int k=max_target-1;
while (k>=0 && is_missing(sums(k,0))) k--;
if (k<0)
{
k=0;
source->getRow(k,previous_sourcerow);
for (int j=0;j<columns.length();j++)
{
real new_value = previous_sourcerow[columns[j]];
if (is_missing(new_value))
{
sums(k,j) = 0;
ma(k,j) = MISSING_VALUE;
}
else
{
sums(k,j) = new_value;
nnonmissing(k,j) = 1;
ma(k,j) = new_value;
}
}
}
for (;k<max_target;k++)
{
source->getRow(k+1,previous_sourcerow);
for (int j=0;j<columns.length();j++)
{
real new_value = previous_sourcerow[columns[j]];
if (!is_missing(new_value))
{
sums(k+1,j) = sums(k,j) + new_value;
nnonmissing(k+1,j) = nnonmissing(k,j) + 1;
}
else sums(k+1,j) = sums(k,j);
int delta = k+1-window_sizes[j];
int n_at_window_start = (delta>=0)?nnonmissing(delta,j):0;
int n = nnonmissing(k+1,j) - n_at_window_start;
if (n>0)
{
if (delta>=0)
ma(k+1,j) = (sums(k+1,j) - sums(delta,j))/n;
else
ma(k+1,j) = sums(k+1,j)/n;
}
else
ma(k+1,j) = MISSING_VALUE;
}
}
}
for (int j=0;j<columns_to_average.length();j++)
{
int target = centered_windows?min(i+window_sizes[j]/2,length()-1):i;
row[sourcerow.length()+j]=ma(target,j);
}
v << row;
}

| OptionList & PLearn::MovingAverageVMatrix::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 65 of file MovingAverageVMatrix.cc.
| OptionMap & PLearn::MovingAverageVMatrix::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 65 of file MovingAverageVMatrix.cc.
| RemoteMethodMap & PLearn::MovingAverageVMatrix::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 65 of file MovingAverageVMatrix.cc.
| void PLearn::MovingAverageVMatrix::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 210 of file MovingAverageVMatrix.cc.
References columns, columns_to_average, PLearn::deepCopyField(), PLearn::SourceVMatrix::makeDeepCopyFromShallowCopy(), sums, and window_sizes.
{
inherited::makeDeepCopyFromShallowCopy(copies);
deepCopyField(columns, copies);
deepCopyField(columns_to_average, copies);
deepCopyField(sums, copies);
deepCopyField(window_sizes, copies);
}

Reimplemented from PLearn::SourceVMatrix.
Definition at line 113 of file MovingAverageVMatrix.h.
Definition at line 78 of file MovingAverageVMatrix.h.
Referenced by declareOptions(), and getNewRow().
TVec<int> PLearn::MovingAverageVMatrix::columns [protected] |
Definition at line 66 of file MovingAverageVMatrix.h.
Referenced by build_(), getNewRow(), and makeDeepCopyFromShallowCopy().
Definition at line 76 of file MovingAverageVMatrix.h.
Referenced by build_(), declareOptions(), getNewRow(), and makeDeepCopyFromShallowCopy().
Mat PLearn::MovingAverageVMatrix::ma [protected] |
Definition at line 62 of file MovingAverageVMatrix.h.
Referenced by build_(), and getNewRow().
int PLearn::MovingAverageVMatrix::max_window_size [protected] |
Definition at line 67 of file MovingAverageVMatrix.h.
Referenced by build_(), and getNewRow().
TMat<int> PLearn::MovingAverageVMatrix::nnonmissing [protected] |
Definition at line 63 of file MovingAverageVMatrix.h.
Referenced by build_(), and getNewRow().
Vec PLearn::MovingAverageVMatrix::previous_sourcerow [protected] |
Definition at line 65 of file MovingAverageVMatrix.h.
Referenced by build_(), and getNewRow().
Vec PLearn::MovingAverageVMatrix::row [protected] |
Definition at line 64 of file MovingAverageVMatrix.h.
Referenced by build_(), and getNewRow().
Mat PLearn::MovingAverageVMatrix::sums [protected] |
Definition at line 61 of file MovingAverageVMatrix.h.
Referenced by build_(), getNewRow(), and makeDeepCopyFromShallowCopy().
Definition at line 77 of file MovingAverageVMatrix.h.
Referenced by build_(), declareOptions(), getNewRow(), and makeDeepCopyFromShallowCopy().
1.7.4