PLearn 0.1
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Private Types | Private Member Functions
PLearn::RemapLastColumnVMatrix Class Reference

#include <RemapLastColumnVMatrix.h>

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

List of all members.

Public Member Functions

 RemapLastColumnVMatrix (bool call_build_=false)
 default constructor (for automatic deserialization)
 RemapLastColumnVMatrix (VMat the_source, Mat the_mapping, bool call_build_=false)
 full explicit mapping.
 RemapLastColumnVMatrix (VMat the_source, real if_equals_value, real then_value=+1, real else_value=-1, bool call_build_=false)
 if-then-else mapping.
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual RemapLastColumnVMatrixdeepCopy (CopiesMap &copies) const
virtual void build ()
 Simply calls inherited::build() then build_().
virtual void getNewRow (int i, const Vec &samplevec) const
 Must be implemented in subclasses: default version returns an error.
virtual void reset_dimensions ()
 In case the dimensions of an underlying VMat has changed, recompute it.

Static Public Member Functions

static string _classname_ ()
 RemapLastColumnVMatrix.
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 ()
static void declareOptions (OptionList &ol)
 Declares this class' options.

Static Public Attributes

static StaticInitializer _static_initializer_

Protected Attributes

Mat mapping
 If this is not empty, then it represents the mapping to apply.
real if_equals_val
real then_val
real else_val

Private Types

typedef SourceVMatrix inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Definition at line 53 of file RemapLastColumnVMatrix.h.


Member Typedef Documentation

Reimplemented from PLearn::SourceVMatrix.

Definition at line 55 of file RemapLastColumnVMatrix.h.


Constructor & Destructor Documentation

PLearn::RemapLastColumnVMatrix::RemapLastColumnVMatrix ( bool  call_build_ = false)

default constructor (for automatic deserialization)

Definition at line 51 of file RemapLastColumnVMatrix.cc.

References build_().

    : inherited(call_build_), if_equals_val(0), then_val(0), else_val(0)
{
    if( call_build_ )
        build_();
}

Here is the call graph for this function:

PLearn::RemapLastColumnVMatrix::RemapLastColumnVMatrix ( VMat  the_source,
Mat  the_mapping,
bool  call_build_ = false 
)

full explicit mapping.

Warning: VMFields are NOT YET handled by this constructor

Definition at line 58 of file RemapLastColumnVMatrix.cc.

References build_().

    : inherited (the_source,
                 the_source->length(),
                 the_source->width()+the_mapping.width()-2,
                 call_build_),
      mapping(the_mapping)
{
    if( call_build_ )
        build_();
}

Here is the call graph for this function:

PLearn::RemapLastColumnVMatrix::RemapLastColumnVMatrix ( VMat  the_source,
real  if_equals_value,
real  then_value = +1,
real  else_value = -1,
bool  call_build_ = false 
)

if-then-else mapping.

Warning: VMFields are NOT YET handled by this constructor

Definition at line 71 of file RemapLastColumnVMatrix.cc.

References build_().

    : inherited(the_source,
                the_source->length(),
                the_source->width(),
                call_build_),
      if_equals_val(if_equals_value),
      then_val(then_value),
      else_val(else_value)
{
    if( call_build_ )
        build_();
}

Here is the call graph for this function:


Member Function Documentation

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

RemapLastColumnVMatrix.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 49 of file RemapLastColumnVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 49 of file RemapLastColumnVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 49 of file RemapLastColumnVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 49 of file RemapLastColumnVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 49 of file RemapLastColumnVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 49 of file RemapLastColumnVMatrix.cc.

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

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 88 of file RemapLastColumnVMatrix.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 94 of file RemapLastColumnVMatrix.cc.

References PLearn::TVec< T >::copy(), PLearn::VMatrix::declareFieldNames(), i, PLearn::VMatrix::inputsize_, PLearn::TMat< T >::isEmpty(), mapping, PLearn::TVec< T >::resize(), PLearn::SourceVMatrix::setMetaInfoFromSource(), PLearn::SourceVMatrix::source, PLearn::VMatrix::targetsize_, PLearn::tostring(), PLearn::VMatrix::updateMtime(), PLearn::VMatrix::weightsize_, PLearn::VMatrix::width(), PLearn::VMat::width(), PLearn::TMat< T >::width(), and PLearn::VMatrix::width_.

Referenced by build(), and RemapLastColumnVMatrix().

{
    int n_extra = mapping.width() - 2;
    if( mapping.isEmpty() )
        width_=source->width();
    else
        width_=source->width() + n_extra;

    updateMtime(source);

    if( !mapping.isEmpty() && n_extra > 0 )
    {
        // width() is different from source->width(),
        int n_last = source->width()-1;

        // determine sizes
        int source_is = source->inputsize();
        int source_ts = source->targetsize();
        int source_ws = source->weightsize();

        bool specified_sizes_are_inconsistent =
            inputsize_ < 0 || targetsize_ < 0 || weightsize_ <0 ||
            inputsize_ + targetsize_ + weightsize_ != width();

        if( specified_sizes_are_inconsistent )
        {
            if( source_is < 0 || source_ts < 0 || source_ws < 0 ||
                source_is + source_ts + source_ws != source->width() )
            {
                //source sizes are inconsistent, everything is input (default)
                inputsize_ = width();
                targetsize_ = 0;
                weightsize_ = 0;
            }
            else if( n_last < source_is )
            {
                // last column is input, remapped columns are considered input
                // other sizes are 0
                inputsize_ = source_is + n_extra;
                targetsize_ = 0;
                weightsize_ = 0;
            }
            else if( n_last < source_is + source_ts )
            {
                // last column is target, remapped columns are
                // considered target other sizes are set from source
                inputsize_ = source_is;
                targetsize_ = source_ts + n_extra;
                weightsize_ = 0;
            }
            else
            {
                inputsize_ = source_is;
                targetsize_ = source_ts;
                weightsize_ = source_ws + n_extra;
            }
        }
        // else don't modify specified sizes

        // set fieldname for added columns
        TVec<string> source_fieldnames = source->fieldNames();
        string last_fieldname = source_fieldnames[n_last];
        TVec<string> fieldnames( source_fieldnames.copy() );
        fieldnames.resize( width() );
        for( int i=0 ; i<=n_extra ; i++ )
        {
            fieldnames[n_last+i] = last_fieldname + "_" + tostring(i);
        }
        declareFieldNames( fieldnames );

    }
    setMetaInfoFromSource();
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 49 of file RemapLastColumnVMatrix.cc.

void PLearn::RemapLastColumnVMatrix::declareOptions ( OptionList ol) [static]
static const PPath& PLearn::RemapLastColumnVMatrix::declaringFile ( ) [inline, static]

Reimplemented from PLearn::SourceVMatrix.

Definition at line 94 of file RemapLastColumnVMatrix.h.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 49 of file RemapLastColumnVMatrix.cc.

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

Must be implemented in subclasses: default version returns an error.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 190 of file RemapLastColumnVMatrix.cc.

References else_val, PLearn::fast_exact_is_equal(), if_equals_val, PLearn::TMat< T >::isEmpty(), PLearn::TVec< T >::lastElement(), PLearn::TMat< T >::length(), PLearn::TVec< T >::length(), PLearn::VMatrix::length(), mapping, PLERROR, PLearn::SourceVMatrix::source, PLearn::TVec< T >::subVec(), then_val, PLearn::TMat< T >::width(), PLearn::VMat::width(), and PLearn::VMatrix::width().

{
#ifdef BOUNDCHECK
    if(i<0 || i>=length())
        PLERROR("In RemapLastColumnVMatrix::getNewRow OUT OF BOUNDS");
    if(samplevec.length()!=width())
        PLERROR("In RemapLastColumnVMatrix::getNewRow samplevec.length()\n"
                "must be equal to the VMat's width (%d != %d).\n",
                samplevec.length(), width());
#endif
    if(mapping.isEmpty()) // use if-then-else mapping
    {
        source->getRow(i,samplevec);
        real& lastelem = samplevec.lastElement();
        if(fast_exact_is_equal(lastelem, if_equals_val))
            lastelem = then_val;
        else
            lastelem = else_val;
    }
    else // use mapping matrix
    {
        int source_width = source->width();
        int replacement_width = mapping.width()-1;
        source->getRow(i,samplevec.subVec(0,source_width));
        real val = samplevec[source_width-1];
        int k;
        for(k=0; k<mapping.length(); k++)
        {
            if(fast_exact_is_equal(mapping(k,0), val))
            {
                samplevec.subVec(source_width-1,replacement_width)
                    << mapping(k).subVec(1,replacement_width);
                break;
            }
        }
        if(k>=mapping.length())
            PLERROR("In RemapLastColumnVMatrix::getNewRow - there is a value"
                    " in the\n"
                    "last column that does not have any defined mapping.\n");
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 49 of file RemapLastColumnVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 49 of file RemapLastColumnVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 49 of file RemapLastColumnVMatrix.cc.

virtual void PLearn::RemapLastColumnVMatrix::reset_dimensions ( ) [inline, virtual]

In case the dimensions of an underlying VMat has changed, recompute it.

Reimplemented from PLearn::VMatrix.

Definition at line 100 of file RemapLastColumnVMatrix.h.

    {
        source->reset_dimensions();

        if( mapping.isEmpty() )
            width_=source->width();
        else
            width_=source->width()+mapping.width()-2;

        length_=source->length();
    }

Member Data Documentation

Reimplemented from PLearn::SourceVMatrix.

Definition at line 94 of file RemapLastColumnVMatrix.h.

Definition at line 71 of file RemapLastColumnVMatrix.h.

Referenced by declareOptions(), and getNewRow().

These are used only if mapping is an empty Mat, in which case the value in the last column will be replaced by 'then_val' if it is equal to 'if_equals_val', otherwise it will be replaced by 'else_val'

Definition at line 69 of file RemapLastColumnVMatrix.h.

Referenced by declareOptions(), and getNewRow().

If this is not empty, then it represents the mapping to apply.

Definition at line 62 of file RemapLastColumnVMatrix.h.

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

Definition at line 70 of file RemapLastColumnVMatrix.h.

Referenced by declareOptions(), and getNewRow().


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