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

This VMat is a generalization of OneHotVMatrix where many columns (given by the Vec index) are mapped, instead of just the last one. More...

#include <GeneralizedOneHotVMatrix.h>

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

List of all members.

Public Member Functions

 GeneralizedOneHotVMatrix (bool call_build_=false)
 default constructor (for automatic deserialization)
 GeneralizedOneHotVMatrix (VMat the_source, Vec the_index, Vec the_nclasses, Vec the_cold_value, Vec the_hot_value, bool call_build_=false)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual GeneralizedOneHotVMatrixdeepCopy (CopiesMap &copies) const
virtual void build ()
 Simply calls inherited::build() then build_().
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transforms a shallow copy into a deep copy.
virtual void reset_dimensions ()
 In case the dimensions of an underlying VMat has changed, recompute it.

Static Public Member Functions

static string _classname_ ()
 GeneralizedOneHotVMatrix.
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 Public Attributes

static StaticInitializer _static_initializer_

Protected Member Functions

virtual void getNewRow (int i, const Vec &samplevec) const
 Must be implemented in subclasses: default version returns an error.

Static Protected Member Functions

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

Protected Attributes

Vec index
 Columns to map to one-hot vector representation.
Vec nclasses
 Size of the one-hot vector for each columns to map.
Vec cold_value
 Cold values for all columns to map.
Vec hot_value
 Hot values for all columns to map.

Private Types

typedef SourceVMatrix inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

This VMat is a generalization of OneHotVMatrix where many columns (given by the Vec index) are mapped, instead of just the last one.

Definition at line 57 of file GeneralizedOneHotVMatrix.h.


Member Typedef Documentation

Reimplemented from PLearn::SourceVMatrix.

Definition at line 59 of file GeneralizedOneHotVMatrix.h.


Constructor & Destructor Documentation

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

default constructor (for automatic deserialization)

Definition at line 54 of file GeneralizedOneHotVMatrix.cc.

References build_().

    : inherited(call_build_)
{
    if( call_build_ )
        build_();
}

Here is the call graph for this function:

PLearn::GeneralizedOneHotVMatrix::GeneralizedOneHotVMatrix ( VMat  the_source,
Vec  the_index,
Vec  the_nclasses,
Vec  the_cold_value,
Vec  the_hot_value,
bool  call_build_ = false 
)

Definition at line 61 of file GeneralizedOneHotVMatrix.cc.

References build_(), cold_value, hot_value, index, PLearn::TVec< T >::length(), PLearn::VMat::length(), PLearn::max(), PLearn::min(), nclasses, PLERROR, and PLearn::SourceVMatrix::source.

    : inherited(the_source,
                the_source->length(),
                the_source->width()
                    + (int)sum(the_nclasses)-the_nclasses.length(),
                call_build_),
      index(the_index), nclasses(the_nclasses),
      cold_value(the_cold_value), hot_value(the_hot_value)
{
    if (min(index)<0 || max(index)>source->length()-1)
        PLERROR("In GeneralizedOneHotVMatrix: all values of index must be in"
                " range [0,%d]",
                source->length()-1);

    if (index.length()!=nclasses.length() ||
        cold_value.length()!=hot_value.length() ||
        index.length()!=hot_value.length())
        PLERROR("In GeneralizedOneHotVMatrix: index, nclasses, cold_value\n"
                "and hot_value must have same length.\n");

    if (call_build_)
        build_();
}

Here is the call graph for this function:


Member Function Documentation

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

GeneralizedOneHotVMatrix.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 52 of file GeneralizedOneHotVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 52 of file GeneralizedOneHotVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 52 of file GeneralizedOneHotVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 52 of file GeneralizedOneHotVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 52 of file GeneralizedOneHotVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 52 of file GeneralizedOneHotVMatrix.cc.

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

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 90 of file GeneralizedOneHotVMatrix.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 96 of file GeneralizedOneHotVMatrix.cc.

References PLearn::VMatrix::declareFieldNames(), index, j, PLearn::TVec< T >::length(), PLearn::VMat::length(), PLearn::VMatrix::length_, nclasses, PLearn::SourceVMatrix::setMetaInfoFromSource(), PLearn::SourceVMatrix::source, PLearn::sum(), PLearn::tostring(), PLearn::vec_find(), PLearn::VMatrix::width(), PLearn::VMat::width(), and PLearn::VMatrix::width_.

Referenced by build(), and GeneralizedOneHotVMatrix().

{
    length_ = source->length();
    width_ = source->width() + (int)sum(nclasses) - nclasses.length();

    TVec<string> fieldnames = source->fieldNames();
    TVec<string> extended_fieldnames( width() );
    int efn_pos = 0;
    for( int j=0 ; j<fieldnames.length() ; j++ )
    {
        const int index_pos = vec_find(index, (real)j);
        if( index_pos == -1 )
            extended_fieldnames[efn_pos++] = fieldnames[j];
        else
        {
            const int nb_class = (int)nclasses[index_pos];
            string name = fieldnames[j];
            for( int k=0 ; k<nb_class ; k++ )
                extended_fieldnames[efn_pos++] = name + "_" + tostring(k);

        }
    }
    declareFieldNames( extended_fieldnames );
    setMetaInfoFromSource();
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 52 of file GeneralizedOneHotVMatrix.cc.

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

Declares this class' options.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 122 of file GeneralizedOneHotVMatrix.cc.

References PLearn::OptionBase::buildoption, cold_value, PLearn::declareOption(), PLearn::SourceVMatrix::declareOptions(), hot_value, index, PLearn::OptionBase::learntoption, nclasses, PLearn::OptionBase::nosave, and PLearn::SourceVMatrix::source.

{
    declareOption(ol, "distr", &GeneralizedOneHotVMatrix::source,
                  (OptionBase::learntoption | OptionBase::nosave),
                  "DEPRECATED - use 'source' instead.");
    declareOption(ol, "index", &GeneralizedOneHotVMatrix::index,
                  OptionBase::buildoption, "Columns to map to one-hot vector representation.");
    declareOption(ol, "nclasses", &GeneralizedOneHotVMatrix::nclasses,
                  OptionBase::buildoption, "Size of the one-hot vector for each columns to map.");
    declareOption(ol, "cold_value", &GeneralizedOneHotVMatrix::cold_value,
                  OptionBase::buildoption, "Cold values for all columns to map.");
    declareOption(ol, "hot_value", &GeneralizedOneHotVMatrix::hot_value,
                  OptionBase::buildoption, "Hot values for all columns to map.");
    inherited::declareOptions(ol);
}

Here is the call graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 85 of file GeneralizedOneHotVMatrix.h.

:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 52 of file GeneralizedOneHotVMatrix.cc.

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

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 138 of file GeneralizedOneHotVMatrix.cc.

References cold_value, PLearn::TVec< T >::fill(), PLearn::fill_one_hot(), hot_value, index, PLearn::is_missing(), j, PLearn::TVec< T >::length(), PLearn::VMatrix::length(), nclasses, PLERROR, PLearn::SourceVMatrix::source, PLearn::TVec< T >::subVec(), PLearn::vec_find(), PLearn::VMat::width(), and PLearn::VMatrix::width().

{
#ifdef BOUNDCHECK
    if(i<0 || i>=length())
        PLERROR("In OneHotVMatrix::getNewRow OUT OF BOUNDS");
    if(v.length()!=width())
        PLERROR("In GeneralizedOneHotVMatrix::getNewRow v.length() must be\n"
                "equal to the VMat's width.\n");
#endif

    Vec input(source->width());
    source->getRow(i, input);
    int v_pos = 0;
    for (int j=0; j<input.length(); j++) {
        const int index_pos = vec_find(index, (real)j);
        if (index_pos == -1)
            v[v_pos++] = input[j];
        else {
            const int nb_class = (int)nclasses[index_pos];
            Vec target = v.subVec(v_pos, nb_class);
            const real cold = cold_value[index_pos];
            const real hot = hot_value[index_pos];
            const real classnum = source->get(i,j); // Maybe not a desired behavior
            if(is_missing(classnum)) target.fill(cold);
            else fill_one_hot(target, (int) classnum, cold, hot);
            v_pos += nb_class;
        }
    }
}

Here is the call graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 52 of file GeneralizedOneHotVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 52 of file GeneralizedOneHotVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 52 of file GeneralizedOneHotVMatrix.cc.

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

Transforms a shallow copy into a deep copy.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 171 of file GeneralizedOneHotVMatrix.cc.

References cold_value, PLearn::deepCopyField(), hot_value, index, PLearn::SourceVMatrix::makeDeepCopyFromShallowCopy(), and nclasses.

{
    inherited::makeDeepCopyFromShallowCopy(copies);

    // ### Call deepCopyField on all "pointer-like" fields.
    // ### that you wish to be deepCopied rather than.
    // ### shallow-copied.
    // ### ex:
    // deepCopyField(trainvec, copies);

    deepCopyField(index, copies);
    deepCopyField(nclasses, copies);
    deepCopyField(cold_value, copies);
    deepCopyField(hot_value, copies);
}

Here is the call graph for this function:

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

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

Reimplemented from PLearn::VMatrix.

Definition at line 99 of file GeneralizedOneHotVMatrix.h.

References PLearn::sum().

    {
        source->reset_dimensions();
        width_ = source->width() + (int)sum(nclasses) - nclasses.length();
        length_ = source->length();
    }

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::SourceVMatrix.

Definition at line 85 of file GeneralizedOneHotVMatrix.h.

Cold values for all columns to map.

Definition at line 68 of file GeneralizedOneHotVMatrix.h.

Referenced by declareOptions(), GeneralizedOneHotVMatrix(), getNewRow(), and makeDeepCopyFromShallowCopy().

Hot values for all columns to map.

Definition at line 70 of file GeneralizedOneHotVMatrix.h.

Referenced by declareOptions(), GeneralizedOneHotVMatrix(), getNewRow(), and makeDeepCopyFromShallowCopy().

Columns to map to one-hot vector representation.

Definition at line 64 of file GeneralizedOneHotVMatrix.h.

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

Size of the one-hot vector for each columns to map.

Definition at line 66 of file GeneralizedOneHotVMatrix.h.

Referenced by build_(), declareOptions(), GeneralizedOneHotVMatrix(), 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