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 | Private Attributes
PLearn::AppendNeighborsVMatrix Class Reference

Appends the nearest neighbors of the input samples of a source VMatrix. More...

#include <AppendNeighborsVMatrix.h>

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

List of all members.

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 OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual AppendNeighborsVMatrixdeepCopy (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

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

Detailed Description

Appends the nearest neighbors of the input samples of a source VMatrix.

* AppendNeighborsVMatrix *

Definition at line 59 of file AppendNeighborsVMatrix.h.


Member Typedef Documentation

Reimplemented from PLearn::SourceVMatrix.

Definition at line 64 of file AppendNeighborsVMatrix.h.


Constructor & Destructor Documentation

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 */
{
}

Member Function Documentation

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.

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

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.

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

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

        }
    }
}

Here is the call graph for this function:

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.

Here is the call graph for this function:


Member Data Documentation

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

Used to store data and save memory allocations.

Definition at line 67 of file AppendNeighborsVMatrix.h.

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

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

Definition at line 67 of file AppendNeighborsVMatrix.h.

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

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

Definition at line 68 of file AppendNeighborsVMatrix.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