|
PLearn 0.1
|
Appends the nearest neighbors of the input samples of a source VMatrix. More...
#include <AppendNeighborsVMatrix.h>


Public Member Functions | |
| AppendNeighborsVMatrix () | |
| 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 AppendNeighborsVMatrix * | 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 | |
| int | n_neighbors |
| Number of nearest neighbors. | |
| Func | transformation |
| Transformation to apply on the nearest neighbors. | |
| bool | append_neighbor_indices |
| Indication that the nearest neighbor indices should be appended to the input part. | |
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 | |
| TMat< int > | input_parts |
| Matrix of nearest neighbor indices. | |
Private Types | |
| typedef SourceVMatrix | inherited |
Private Member Functions | |
| void | build_ () |
| This does the actual building. | |
Private Attributes | |
| Vec | input |
| Used to store data and save memory allocations. | |
| Vec | target |
| Vec | transf |
| real | weight |
Appends the nearest neighbors of the input samples of a source VMatrix.
Definition at line 59 of file AppendNeighborsVMatrix.h.
typedef SourceVMatrix PLearn::AppendNeighborsVMatrix::inherited [private] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 64 of file AppendNeighborsVMatrix.h.
| PLearn::AppendNeighborsVMatrix::AppendNeighborsVMatrix | ( | ) |
Definition at line 53 of file AppendNeighborsVMatrix.cc.
:inherited(), n_neighbors(1), append_neighbor_indices(false) /* ### Initialise all fields to their default value */ { }
| string PLearn::AppendNeighborsVMatrix::_classname_ | ( | ) | [static] |
Declares name and deepCopy methods.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 70 of file AppendNeighborsVMatrix.cc.
| OptionList & PLearn::AppendNeighborsVMatrix::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 70 of file AppendNeighborsVMatrix.cc.
| RemoteMethodMap & PLearn::AppendNeighborsVMatrix::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 70 of file AppendNeighborsVMatrix.cc.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 70 of file AppendNeighborsVMatrix.cc.
| Object * PLearn::AppendNeighborsVMatrix::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 70 of file AppendNeighborsVMatrix.cc.
| StaticInitializer AppendNeighborsVMatrix::_static_initializer_ & PLearn::AppendNeighborsVMatrix::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 70 of file AppendNeighborsVMatrix.cc.
| void PLearn::AppendNeighborsVMatrix::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::SourceVMatrix.
Definition at line 198 of file AppendNeighborsVMatrix.cc.
References PLearn::SourceVMatrix::build(), and build_().
Referenced by PLearn::append_neighbors().
{
inherited::build();
build_();
}


| void PLearn::AppendNeighborsVMatrix::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 126 of file AppendNeighborsVMatrix.cc.
References append_neighbor_indices, PLearn::computeNearestNeighbors(), PLearn::VMat::getExample(), i, input, input_parts, PLearn::VMatrix::inputsize_, PLearn::VMat::length(), PLearn::TMat< T >::length(), PLearn::VMatrix::length_, n_neighbors, PLERROR, PLearn::TVec< T >::resize(), PLearn::TMat< T >::resize(), PLearn::SourceVMatrix::source, target, PLearn::VMatrix::targetsize_, transf, transformation, PLearn::VMatrix::updateMtime(), weight, PLearn::VMatrix::weightsize_, PLearn::TMat< T >::width(), and PLearn::VMatrix::width_.
Referenced by build().
{
updateMtime(source);
// find the nearest neighbors, if not done already
if (source && (input_parts.length() != source->length() || input_parts.width() != n_neighbors+1 ))
// WARNING: will not work if source is changed but has the same dimensions
{
if(n_neighbors <=0)
PLERROR("In AppendNeighborsVMatrix::build_(): n_neighbors should be > 0");
input_parts.resize(source->length(),n_neighbors+1); // +1 because we also get current row
input.resize(source->inputsize());
target.resize(source->targetsize());
VMat neighbors_source;
if(source->targetsize() + source->weightsize() > 0)
{
GetInputVMatrix* givm = new GetInputVMatrix(source);
neighbors_source = givm;
}
else
neighbors_source = source;
for (int i=0;i<source->length();i++)
{
source->getExample(i,input,target,weight);
TVec<int> neighbors_of_i = input_parts(i);
computeNearestNeighbors(neighbors_source,input,neighbors_of_i,-1);
}
}
if(source->length()!=length_ || (transformation ? transformation->outputs.nelems() * input_parts.width() : source->inputsize() * input_parts.width())
+ (append_neighbor_indices ? input_parts.width() : 0) + source->targetsize() + source->weightsize() != width_)
{
if(transformation)
{
if(transformation->inputs.nelems() != source->inputsize())
PLERROR("Cannot use transformation with input size different from source->inputsize()");
transf.resize(transformation->outputs.nelems());
width_ = transformation->outputs.nelems() * input_parts.width()
+ (append_neighbor_indices ? input_parts.width() : 0)
+ source->targetsize() + source->weightsize();
length_ = source->length();
if(inputsize_ < 0)
inputsize_ = transformation->outputs.nelems() * input_parts.width()
+ (append_neighbor_indices ? input_parts.width() : 0);
if(targetsize_ < 0) targetsize_ = source->targetsize();
if(weightsize_ < 0) weightsize_ = source->weightsize();
}
else
{
width_ = source->inputsize() * input_parts.width()
+ (append_neighbor_indices ? input_parts.width() : 0)
+ source->targetsize() + source->weightsize();
length_ = source->length();
if(inputsize_ < 0)
inputsize_ = source->inputsize() * input_parts.width()
+ (append_neighbor_indices ? input_parts.width() : 0);
if(targetsize_ < 0) targetsize_ = source->targetsize();
if(weightsize_ < 0) weightsize_ = source->weightsize();
}
if(width_ != inputsize_ + targetsize_ + weightsize_)
PLERROR("In AppendNeighborsVMatrix::build_(): width_ != inputsize_ + targetsize_ + weightsize_");
}
}


| string PLearn::AppendNeighborsVMatrix::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 70 of file AppendNeighborsVMatrix.cc.
| void PLearn::AppendNeighborsVMatrix::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 108 of file AppendNeighborsVMatrix.cc.
References append_neighbor_indices, PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::SourceVMatrix::declareOptions(), n_neighbors, and transformation.
{
declareOption(ol, "n_neighbors", &AppendNeighborsVMatrix::n_neighbors, OptionBase::buildoption,
"Number of nearest neighbors. Determines the width of this vmatrix, which\n"
"is source->width() * n_neighbors.\n");
declareOption(ol, "transformation", &AppendNeighborsVMatrix::transformation, OptionBase::buildoption,
"Transformation to apply on the nearest neighbors\n");
declareOption(ol, "append_neighbor_indices", &AppendNeighborsVMatrix::append_neighbor_indices, OptionBase::buildoption,
"Indication that the nearest neighbor indices should\n"
"appended to the input part. The index of the current\n"
"sample is also appended.\n");
// Now call the parent class' declareOptions
inherited::declareOptions(ol);
}

| static const PPath& PLearn::AppendNeighborsVMatrix::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 127 of file AppendNeighborsVMatrix.h.
{
| AppendNeighborsVMatrix * PLearn::AppendNeighborsVMatrix::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 70 of file AppendNeighborsVMatrix.cc.
This is the only method requiring implementation.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 72 of file AppendNeighborsVMatrix.cc.
References append_neighbor_indices, PLearn::VMat::getExample(), input, input_parts, PLearn::VMatrix::inputsize_, j, PLearn::TVec< T >::length(), PLERROR, PLearn::SourceVMatrix::source, PLearn::TVec< T >::subVec(), target, transf, transformation, weight, PLearn::VMatrix::weightsize(), PLearn::TMat< T >::width(), and PLearn::VMatrix::width_.
{
if (width_<0)
PLERROR("AppendNeighborsVMatrix::getNewRow called but build was not done yet");
for(int j=0; j<input_parts.width(); j++)
{
source->getExample(input_parts(i,j),input,target,weight);
if(transformation)
{
transformation->fprop(input,transf);
v.subVec(j*transf.length(),transf.length()) << transf;
if(j==0)
{
if(append_neighbor_indices)
v.subVec(input_parts.width()*transf.length(),input_parts.width()) << input_parts(i);
v.subVec(inputsize_,source->targetsize()) << target;
if(weightsize() > 0) v[width_-1] = weight;
}
}
else
{
v.subVec(j*source->inputsize(),source->inputsize()) << input;
if(j==0)
{
if(append_neighbor_indices)
v.subVec(input_parts.width()*source->inputsize(),input_parts.width()) << input_parts(i);
v.subVec(inputsize_,source->targetsize()) << target;
if(weightsize() > 0) v[width_-1] = weight;
}
}
}
}

| OptionList & PLearn::AppendNeighborsVMatrix::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 70 of file AppendNeighborsVMatrix.cc.
| OptionMap & PLearn::AppendNeighborsVMatrix::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 70 of file AppendNeighborsVMatrix.cc.
| RemoteMethodMap & PLearn::AppendNeighborsVMatrix::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 70 of file AppendNeighborsVMatrix.cc.
| void PLearn::AppendNeighborsVMatrix::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 204 of file AppendNeighborsVMatrix.cc.
References PLearn::deepCopyField(), input, input_parts, PLearn::SourceVMatrix::makeDeepCopyFromShallowCopy(), target, transf, and transformation.
{
inherited::makeDeepCopyFromShallowCopy(copies);
deepCopyField(input, copies);
deepCopyField(target, copies);
deepCopyField(input_parts, copies);
deepCopyField(transf, copies);
deepCopyField(transformation, copies);
}

Reimplemented from PLearn::SourceVMatrix.
Definition at line 127 of file AppendNeighborsVMatrix.h.
Indication that the nearest neighbor indices should be appended to the input part.
Definition at line 92 of file AppendNeighborsVMatrix.h.
Referenced by PLearn::append_neighbors(), build_(), declareOptions(), and getNewRow().
Vec PLearn::AppendNeighborsVMatrix::input [mutable, private] |
Used to store data and save memory allocations.
Definition at line 67 of file AppendNeighborsVMatrix.h.
Referenced by build_(), getNewRow(), and makeDeepCopyFromShallowCopy().
TMat<int> PLearn::AppendNeighborsVMatrix::input_parts [protected] |
Matrix of nearest neighbor indices.
Definition at line 74 of file AppendNeighborsVMatrix.h.
Referenced by build_(), getNewRow(), and makeDeepCopyFromShallowCopy().
Number of nearest neighbors.
Definition at line 87 of file AppendNeighborsVMatrix.h.
Referenced by PLearn::append_neighbors(), build_(), and declareOptions().
Vec PLearn::AppendNeighborsVMatrix::target [mutable, private] |
Definition at line 67 of file AppendNeighborsVMatrix.h.
Referenced by build_(), getNewRow(), and makeDeepCopyFromShallowCopy().
Vec PLearn::AppendNeighborsVMatrix::transf [mutable, private] |
Definition at line 67 of file AppendNeighborsVMatrix.h.
Referenced by build_(), getNewRow(), and makeDeepCopyFromShallowCopy().
Transformation to apply on the nearest neighbors.
Definition at line 89 of file AppendNeighborsVMatrix.h.
Referenced by PLearn::append_neighbors(), build_(), declareOptions(), getNewRow(), and makeDeepCopyFromShallowCopy().
real PLearn::AppendNeighborsVMatrix::weight [mutable, private] |
Definition at line 68 of file AppendNeighborsVMatrix.h.
Referenced by build_(), and getNewRow().
1.7.4