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

#include <LocalNeighborsDifferencesVMatrix.h>

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

List of all members.

Public Member Functions

 LocalNeighborsDifferencesVMatrix ()
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
LocalNeighborsDifferencesVMatrix
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 PPathdeclaringFile ()

Public Attributes

int n_neighbors
bool concat_neighbors
bool append_indexes
bool append_neighbors

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

Private Types

typedef SourceVMatrix inherited

Private Member Functions

void build_ ()
 This does the actual building.

Private Attributes

Vec neighbor_row
 Used to store data and save memory allocations.
Vec ith_row
Vec a_row
Vec diff_k

Detailed Description

Definition at line 52 of file LocalNeighborsDifferencesVMatrix.h.


Member Typedef Documentation

Reimplemented from PLearn::SourceVMatrix.

Definition at line 57 of file LocalNeighborsDifferencesVMatrix.h.


Constructor & Destructor Documentation

PLearn::LocalNeighborsDifferencesVMatrix::LocalNeighborsDifferencesVMatrix ( )

Definition at line 52 of file LocalNeighborsDifferencesVMatrix.cc.

    :inherited(), n_neighbors(-1), concat_neighbors(false), append_indexes(false)
    /* ### Initialise all fields to their default value */
{
}

Member Function Documentation

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

Declares name and deepCopy methods.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file LocalNeighborsDifferencesVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file LocalNeighborsDifferencesVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file LocalNeighborsDifferencesVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file LocalNeighborsDifferencesVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file LocalNeighborsDifferencesVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file LocalNeighborsDifferencesVMatrix.cc.

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

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 179 of file LocalNeighborsDifferencesVMatrix.cc.

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

Referenced by PLearn::local_neighbors_differences().

Here is the call graph for this function:

Here is the caller graph for this function:

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

This does the actual building.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 145 of file LocalNeighborsDifferencesVMatrix.cc.

References a_row, append_indexes, append_neighbors, PLearn::computeNearestNeighbors(), concat_neighbors, i, PLearn::VMat::length(), PLearn::TMat< T >::length(), PLearn::VMatrix::length_, n_neighbors, neighbors, PLearn::TVec< T >::resize(), PLearn::TMat< T >::resize(), PLearn::SourceVMatrix::source, PLearn::VMatrix::updateMtime(), PLearn::VMat::width(), and PLearn::VMatrix::width_.

Referenced by build().

{
    // find the nearest neighbors, if not done already
    if (source && (neighbors.length()==0 || source->length()!=length_ || source->width()*n_neighbors!=width_))
        // will not work if source is changed but has the same dimensions
    {
        if (concat_neighbors)
        {
            width_ = source->width();
            if(append_indexes) width_ += 2;
            if(append_neighbors) width_ += source->width();
        }
        else
        {
            width_ = source->width()*n_neighbors;
            if(append_indexes) width_ += n_neighbors+1;
            if(append_neighbors) width_ += source->width()*n_neighbors;
        }

        length_ = source->length();
        neighbors.resize(source->length(),n_neighbors);
        a_row.resize(source->width());
        for (int i=0;i<source->length();i++)
        {
            source->getRow(i,a_row);
            TVec<int> neighbors_of_i = neighbors(i);
            computeNearestNeighbors(source,a_row,neighbors_of_i,i);
        }
    }

    updateMtime(source);
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file LocalNeighborsDifferencesVMatrix.cc.

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

Declares this class' options.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 126 of file LocalNeighborsDifferencesVMatrix.cc.

References append_indexes, PLearn::OptionBase::buildoption, concat_neighbors, PLearn::declareOption(), PLearn::SourceVMatrix::declareOptions(), and n_neighbors.

{
    declareOption(ol, "n_neighbors", &LocalNeighborsDifferencesVMatrix::n_neighbors, OptionBase::buildoption,
                  "Number of nearest neighbors. Determines the width of this vmatrix, which\n"
                  "is source->width() * n_neighbors.\n");
    declareOption(ol, "concat_neighbors", &LocalNeighborsDifferencesVMatrix::concat_neighbors, OptionBase::buildoption,
                  "If false, returns the concatenation of nearest neighbors(x) -x  from 1 to n_neighbors , else, returns the n_neighbor nearest neighbor(x) - x\n"
                  "(I know, it doesn't make sense. This should be corrected...)");
    declareOption(ol, "append_indexes", &LocalNeighborsDifferencesVMatrix::append_indexes, OptionBase::buildoption,
                  "Indication that the indexes of the current data point and of the k nearest neighbors\n"
                  "should be appended to the row of the VMatrix.\n");
    declareOption(ol, "append_neighbors", &LocalNeighborsDifferencesVMatrix::append_indexes, OptionBase::buildoption,
                  "Indication that the neighbor vectors of the k nearest neighbors\n"
                  "should be appended to the row of the VMatrix.\n");

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

Here is the call graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 117 of file LocalNeighborsDifferencesVMatrix.h.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file LocalNeighborsDifferencesVMatrix.cc.

void PLearn::LocalNeighborsDifferencesVMatrix::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 LocalNeighborsDifferencesVMatrix.cc.

References append_indexes, append_neighbors, concat_neighbors, diff_k, i, ith_row, n_neighbors, neighbor_row, neighbors, PLERROR, PLearn::TVec< T >::resize(), PLearn::SourceVMatrix::source, PLearn::substract(), PLearn::TVec< T >::subVec(), PLearn::TVec< T >::toMat(), PLearn::VMat::width(), and PLearn::VMatrix::width_.

{
    if (width_<0)
        PLERROR("LocalNeighborsDifferencesVMatrix::getNewRow called but build was not done yet");
    if (concat_neighbors)
    {
        // resize des varaibles
        //v.resize(source->width()); //we assume that the vector has already the good size
        neighbor_row.resize(source->width());
        ith_row.resize(source->width());
        diff_k = v;
        // recuperation de ce qu'il faut
        source->getRow(i,ith_row);
        source->getRow(neighbors(i,n_neighbors-1),neighbor_row);

        // on renvoie la valeur
        substract(neighbor_row,ith_row, diff_k);

        if(append_indexes)
        {
            v[source->width()] = i;
            v[source->width()+1] = neighbors(i,n_neighbors-1);
        }
        if(append_neighbors)
        {
            v.subVec(source->width()+(append_indexes?2:0),source->width()) << neighbor_row;
        }

    }
    else
    {
        // vue en matrice du vecteur de sortie, ca pointe sur les memes donnees.
        Mat differences = v.toMat(n_neighbors,source->width());
        neighbor_row.resize(source->width());
        ith_row.resize(source->width());
        source->getRow(i,ith_row);
        for (int k=0;k<n_neighbors;k++)
        {
            diff_k = differences(k);
            source->getRow(neighbors(i,k),neighbor_row);
            substract(neighbor_row,ith_row, diff_k);
            // normalize result
            // now it's done in ProjectionErrorVariable diff_k /= norm(diff_k);

            if(append_neighbors)
            {
                v.subVec(n_neighbors*source->width()+(append_indexes?n_neighbors+1:0)+k*source->width(),source->width()) << neighbor_row;
            }

        }

        if(append_indexes)
        {
            v[n_neighbors*source->width()] = i;
            for(int k=0; k<n_neighbors; k++)
                v[n_neighbors*source->width()+k+1] = neighbors(i,k);
        }
    }

}

Here is the call graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file LocalNeighborsDifferencesVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file LocalNeighborsDifferencesVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 63 of file LocalNeighborsDifferencesVMatrix.cc.

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 185 of file LocalNeighborsDifferencesVMatrix.cc.

References a_row, PLearn::deepCopyField(), ith_row, PLearn::SourceVMatrix::makeDeepCopyFromShallowCopy(), neighbor_row, and neighbors.

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::SourceVMatrix.

Definition at line 117 of file LocalNeighborsDifferencesVMatrix.h.

Definition at line 60 of file LocalNeighborsDifferencesVMatrix.h.

Referenced by build_(), and makeDeepCopyFromShallowCopy().

Definition at line 60 of file LocalNeighborsDifferencesVMatrix.h.

Referenced by getNewRow().

Definition at line 60 of file LocalNeighborsDifferencesVMatrix.h.

Referenced by getNewRow(), and makeDeepCopyFromShallowCopy().

Used to store data and save memory allocations.

Definition at line 60 of file LocalNeighborsDifferencesVMatrix.h.

Referenced by getNewRow(), and makeDeepCopyFromShallowCopy().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines