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

#include <EncodedVMatrix.h>

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

List of all members.

Public Member Functions

 EncodedVMatrix (bool call_build_=false)
 For all constructors, the original VMFields are copied upon construction.
 EncodedVMatrix (VMat the_source, TVec< map< real, real > > encodings_, TVec< real > defaults_, TVec< bool > encode_, bool call_build_=true)
virtual string classname () const
virtual OptionListgetOptionList () const
virtual OptionMapgetOptionMap () const
virtual RemoteMethodMapgetRemoteMethodMap () const
virtual EncodedVMatrixdeepCopy (CopiesMap &copies) const
virtual void makeDeepCopyFromShallowCopy (CopiesMap &copies)
 Transform a shallow copy into a deep copy.
virtual void getNewRow (int i, const Vec &v) const
 Must be implemented in subclasses: default version returns an error.
virtual void build ()
 Simply calls inherited::build() then build_().

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 ()
static void encodeRow (const TVec< map< real, real > > &encodings, const TVec< real > &defaults, const TVec< bool > &encode, const Vec &v)

Public Attributes

TVec< map< real, real > > encodings
TVec< realdefaults
TVec< boolencode

Static Public Attributes

static StaticInitializer _static_initializer_

Static Protected Member Functions

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

Private Types

typedef SourceVMatrix inherited

Private Member Functions

void build_ ()
 This does the actual building.

Detailed Description

Definition at line 46 of file EncodedVMatrix.h.


Member Typedef Documentation

Reimplemented from PLearn::SourceVMatrix.

Definition at line 48 of file EncodedVMatrix.h.


Constructor & Destructor Documentation

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

For all constructors, the original VMFields are copied upon construction.

Definition at line 44 of file EncodedVMatrix.cc.

References build_().

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

Here is the call graph for this function:

PLearn::EncodedVMatrix::EncodedVMatrix ( VMat  the_source,
TVec< map< real, real > >  encodings_,
TVec< real defaults_,
TVec< bool encode_,
bool  call_build_ = true 
)

Definition at line 51 of file EncodedVMatrix.cc.

References build_().

    : inherited(the_source,
                the_source->length(),
                the_source->width(),
                call_build_),
      encodings(encodings_),
      defaults(defaults_),
      encode(encode_)
{
    if(call_build_)
        build_();
}

Here is the call graph for this function:


Member Function Documentation

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

Declares name and deepCopy methods.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 42 of file EncodedVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 42 of file EncodedVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 42 of file EncodedVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 42 of file EncodedVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 42 of file EncodedVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 42 of file EncodedVMatrix.cc.

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

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 145 of file EncodedVMatrix.cc.

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

Here is the call graph for this function:

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

This does the actual building.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 87 of file EncodedVMatrix.cc.

References PLearn::VMatrix::addStringMapping(), PLearn::VMatrix::copySizesFrom(), PLearn::VMatrix::declareFieldNames(), PLearn::VMatrix::deleteStringMapping(), encode, encodings, i, PLearn::TVec< T >::length(), PLearn::VMatrix::setStringMapping(), PLearn::SourceVMatrix::source, PLearn::VMatrix::updateMtime(), and PLearn::VMat::width().

Referenced by build(), and EncodedVMatrix().

{
    if(source)
    {
        updateMtime(source);
        copySizesFrom(source);
        declareFieldNames(source->fieldNames());
        for(int i= 0; i < source.width(); ++i)
        {
            if(i < encode.length() && encode[i])
            {
                deleteStringMapping(i);
                map<string,real> mm= source->getStringToRealMapping(i);
                for(map<string,real>::iterator it= mm.begin(); it != mm.end(); ++it)
                    addStringMapping(i, it->first, encodings[i][it->second]);
            }
            else
                setStringMapping(i, source->getStringToRealMapping(i));
        }
    }
    
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 42 of file EncodedVMatrix.cc.

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

Declares this class' options.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 66 of file EncodedVMatrix.cc.

References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::SourceVMatrix::declareOptions(), defaults, encode, and encodings.

{
    declareOption(ol, "encodings", &EncodedVMatrix::encodings,
                  OptionBase::buildoption,
                  "Maps used to encode fields.");

    declareOption(ol, "defaults", &EncodedVMatrix::defaults,
                  OptionBase::buildoption,
                  "Default values to use if no encoding is present for some field value.");

    declareOption(ol, "encode", &EncodedVMatrix::encode,
                  OptionBase::buildoption,
                  "True if this column should be encoded (one boolean per col.)");

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

Here is the call graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 62 of file EncodedVMatrix.h.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 42 of file EncodedVMatrix.cc.

void PLearn::EncodedVMatrix::encodeRow ( const TVec< map< real, real > > &  encodings,
const TVec< real > &  defaults,
const TVec< bool > &  encode,
const Vec v 
) [static]

Definition at line 119 of file EncodedVMatrix.cc.

References encodings, PLearn::TVec< T >::find(), j, PLearn::TVec< T >::length(), and PLERROR.

Referenced by PLearn::TargetEncodingLearner::computeOutput(), and getNewRow().

{
    int l= v.length();
    if(l != encodings.length() ||
       l != defaults.length() ||
       l != encode.length())
        PLERROR("in EncodedVMatrix::encodeRow: encodings, defaults and encode should be the same"
                " size as a row's inputsize. (%d / %d / %d / %d)", encodings.length(), defaults.length(), encode.length(), l);
    
    for(int j= 0; j < v.length() && j < encodings.length(); ++j)
        if(encode[j])
        {
            map<real, real> enc= encodings[j];
            map<real, real>::iterator it= enc.find(v[j]);
            if(it == enc.end())
                v[j]= defaults[j];
            else
                v[j]= it->second;
        }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::EncodedVMatrix::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 113 of file EncodedVMatrix.cc.

References defaults, encode, encodeRow(), encodings, PLearn::VMatrix::inputsize(), PLearn::SourceVMatrix::source, and PLearn::TVec< T >::subVec().

{
    source->getRow(i, v);
    encodeRow(encodings, defaults, encode, v.subVec(0, inputsize()));
}

Here is the call graph for this function:

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 42 of file EncodedVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 42 of file EncodedVMatrix.cc.

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

Reimplemented from PLearn::SourceVMatrix.

Definition at line 42 of file EncodedVMatrix.cc.

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

Transform a shallow copy into a deep copy.

Reimplemented from PLearn::SourceVMatrix.

Definition at line 154 of file EncodedVMatrix.cc.

References PLearn::deepCopyField(), defaults, encode, encodings, and PLearn::SourceVMatrix::makeDeepCopyFromShallowCopy().

Here is the call graph for this function:


Member Data Documentation

Reimplemented from PLearn::SourceVMatrix.

Definition at line 62 of file EncodedVMatrix.h.

Definition at line 53 of file EncodedVMatrix.h.

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

Definition at line 54 of file EncodedVMatrix.h.

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