|
PLearn 0.1
|
#include <EncodedVMatrix.h>


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 OptionList & | getOptionList () const |
| virtual OptionMap & | getOptionMap () const |
| virtual RemoteMethodMap & | getRemoteMethodMap () const |
| virtual EncodedVMatrix * | deepCopy (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 PPath & | declaringFile () |
| 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< real > | defaults |
| TVec< bool > | encode |
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. | |
Definition at line 46 of file EncodedVMatrix.h.
typedef SourceVMatrix PLearn::EncodedVMatrix::inherited [private] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 48 of file EncodedVMatrix.h.
| 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_().

| 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.
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_().
{
inherited::build();
build_();
}

| 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));
}
}
}


| 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);
}

| static const PPath& PLearn::EncodedVMatrix::declaringFile | ( | ) | [inline, static] |
| 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;
}
}


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().

| 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().
{
inherited::makeDeepCopyFromShallowCopy(copies);
deepCopyField(encodings, copies);
deepCopyField(defaults, copies);
deepCopyField(encode, copies);
}

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().
Definition at line 52 of file EncodedVMatrix.h.
Referenced by build_(), declareOptions(), encodeRow(), getNewRow(), and makeDeepCopyFromShallowCopy().
1.7.4