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
PLearn::RankedVMatrix Class Reference

#include <RankedVMatrix.h>

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

List of all members.

Public Member Functions

 RankedVMatrix ()
 Default constructor.
 RankedVMatrix (VMat source, PP< RankedVMatrix > reference=0)
 Convenient constructor.
TVec< intgetIndexToRank ()
 Return 'index_to_rank'.
Mat getSortedTargets ()
 Return 'sorted_targets'.
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 RankedVMatrixdeepCopy (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

PP< RankedVMatrixreference

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Member Functions

virtual void getNewRow (int i, const Vec &v) const
 Fill the vector 'v' with the content of the i-th row.

Static Protected Member Functions

static void declareOptions (OptionList &ol)
 Declares this class' options.

Protected Attributes

TVec< intindex_to_rank
 The i-th element is the rank of the target for the i-th sample in the VMat.
Mat sorted_targets
 The first column is the (sorted) target column, and the second column is the corresponding list of indices.

Private Types

typedef SourceVMatrix inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Definition at line 51 of file RankedVMatrix.h.


Member Typedef Documentation

Reimplemented from PLearn::SourceVMatrix.

Definition at line 56 of file RankedVMatrix.h.


Constructor & Destructor Documentation

PLearn::RankedVMatrix::RankedVMatrix ( )

Default constructor.

Definition at line 52 of file RankedVMatrix.cc.

{}
PLearn::RankedVMatrix::RankedVMatrix ( VMat  source,
PP< RankedVMatrix reference = 0 
)

Convenient constructor.

Definition at line 55 of file RankedVMatrix.cc.

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

    : reference(the_reference)
{
    source = the_source;
    build();
}

Here is the call graph for this function:


Member Function Documentation

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

Declares name and deepCopy methods.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 71 of file RankedVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 71 of file RankedVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 71 of file RankedVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 71 of file RankedVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 71 of file RankedVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 71 of file RankedVMatrix.cc.

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

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 88 of file RankedVMatrix.cc.

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

Referenced by RankedVMatrix().

Here is the call graph for this function:

Here is the caller graph for this function:

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

This does the actual building.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 97 of file RankedVMatrix.cc.

References PLearn::VMat::column(), PLearn::TMat< T >::column(), PLearn::VMatrix::defineSizes(), PLearn::fast_exact_is_equal(), i, index_to_rank, PLearn::TMat< T >::length(), PLearn::VMat::length(), PLERROR, reference, PLearn::TVec< T >::resize(), PLearn::TMat< T >::resize(), PLearn::SourceVMatrix::setMetaInfoFromSource(), sorted_targets, PLearn::sortRows(), PLearn::SourceVMatrix::source, PLearn::VMatrix::toMat(), PLearn::VMat::width(), and PLearn::VMatrix::width_.

Referenced by build().

{
    // ### This method should do the real building of the object,
    // ### according to set 'options', in *any* situation.
    // ### Typical situations include:
    // ###  - Initial building of an object from a few user-specified options
    // ###  - Building of a "reloaded" object: i.e. from the complete set of all serialised options.
    // ###  - Updating or "re-building" of an object after a few "tuning" options have been modified.
    // ### You should assume that the parent class' build_() has already been called.
    if (source) {
        if (source->targetsize() != 1)
            PLERROR("In RankedVMatrix::build_ - The source VMat must have a targetsize equal to 1");
        // Get sorted target column.
        sorted_targets.resize(source->length(), 2);
        sorted_targets.column(0) << source.column(source->inputsize())->toMat();
        sorted_targets.column(1) << TVec<int>(0, source->length() - 1, 1);
        sortRows(sorted_targets);
        index_to_rank.resize(source->length());
        if (reference) {
            // We define the targets based on the reference rankings.
            // First get the sorted target column of the reference.
            Mat ref_sorted_targets = reference->getSortedTargets();
            // Now find the inverse mapping from index to rank.
            int ref_index = 0;
            int the_index;
            for (int i = 0; i < sorted_targets.length(); i++) {
                while (ref_index < ref_sorted_targets.length() &&
                       sorted_targets(i,0) > ref_sorted_targets(ref_index,0))
                    ref_index++;
                if (ref_index == 0)
                    // The first target higher or equal is the 0-th one.
                    the_index = 0;
                else if (ref_index == sorted_targets.length())
                    // There is no target higher or equal.
                    the_index = sorted_targets.length() - 1;
                else if (fast_exact_is_equal(sorted_targets(i,0),
                                             ref_sorted_targets(ref_index, 0)))
                    // We have an exact match.
                    the_index = ref_index;
                else {
                    // General case: we are in-between two targets. We choose the closest
                    // one.
                    if (fabs(sorted_targets(i,0) - ref_sorted_targets(ref_index,0)) <=
                        fabs(sorted_targets(i,0) - ref_sorted_targets(ref_index - 1 ,0)))
                        the_index = ref_index;
                    else
                        the_index = ref_index - 1;
                }
                index_to_rank[(int) sorted_targets(i,1)] = the_index;
            }
        } else {
            // Store the inverse mapping from index to rank.
            for (int i = 0; i < source->length(); i++)
                index_to_rank[(int) sorted_targets(i,1)] = i;
        }
        // Set VMat info.
        width_ = source->width() - source->targetsize() + 1;
        defineSizes(source->inputsize(), 1, source->weightsize());
        setMetaInfoFromSource();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 71 of file RankedVMatrix.cc.

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

Declares this class' options.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 76 of file RankedVMatrix.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::SourceVMatrix::declareOptions(), and reference.

{
    declareOption(ol, "reference", &RankedVMatrix::reference, OptionBase::buildoption,
                  "An optional reference VMat used to define the targets.\n");

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

Here is the call graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 124 of file RankedVMatrix.h.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 71 of file RankedVMatrix.cc.

TVec<int> PLearn::RankedVMatrix::getIndexToRank ( ) [inline]

Return 'index_to_rank'.

Definition at line 112 of file RankedVMatrix.h.

References index_to_rank.

{return index_to_rank;}
void PLearn::RankedVMatrix::getNewRow ( int  i,
const Vec v 
) const [protected, virtual]

Fill the vector 'v' with the content of the i-th row.

v is assumed to be the right size.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 162 of file RankedVMatrix.cc.

References i, index_to_rank, PLearn::VMatrix::inputsize_, and PLearn::SourceVMatrix::source.

{
    source->getRow(i, v);
    // Replace the target with the rank.
    v[inputsize_] = index_to_rank[i];
}
OptionList & PLearn::RankedVMatrix::getOptionList ( ) const [virtual]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 71 of file RankedVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 71 of file RankedVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 71 of file RankedVMatrix.cc.

Mat PLearn::RankedVMatrix::getSortedTargets ( ) [inline]

Return 'sorted_targets'.

Definition at line 115 of file RankedVMatrix.h.

References sorted_targets.

{return sorted_targets;}
void PLearn::RankedVMatrix::makeDeepCopyFromShallowCopy ( CopiesMap copies) [virtual]

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 172 of file RankedVMatrix.cc.

References PLearn::deepCopyField(), index_to_rank, PLearn::SourceVMatrix::makeDeepCopyFromShallowCopy(), reference, and sorted_targets.

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::SourceVMatrix.

Definition at line 124 of file RankedVMatrix.h.

The i-th element is the rank of the target for the i-th sample in the VMat.

Definition at line 67 of file RankedVMatrix.h.

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

Definition at line 79 of file RankedVMatrix.h.

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

The first column is the (sorted) target column, and the second column is the corresponding list of indices.

Definition at line 71 of file RankedVMatrix.h.

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


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