|
PLearn 0.1
|
#include <RemapLastColumnVMatrix.h>


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 OptionList & | getOptionList () const |
| virtual OptionMap & | getOptionMap () const |
| virtual RemoteMethodMap & | getRemoteMethodMap () const |
| virtual RemapLastColumnVMatrix * | deepCopy (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 PPath & | declaringFile () |
| 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. | |
Definition at line 53 of file RemapLastColumnVMatrix.h.
typedef SourceVMatrix PLearn::RemapLastColumnVMatrix::inherited [private] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 55 of file RemapLastColumnVMatrix.h.
| 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_(); }

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

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

| string PLearn::RemapLastColumnVMatrix::_classname_ | ( | ) | [static] |
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.
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_().
{
inherited::build();
build_();
}

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


| 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] |
Declares this class' options.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 168 of file RemapLastColumnVMatrix.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::SourceVMatrix::declareOptions(), else_val, if_equals_val, mapping, PLearn::SourceVMatrix::source, and then_val.
{
declareOption(ol, "underlying_distr",
&RemapLastColumnVMatrix::source,
OptionBase::buildoption,
"DEPRECATED - Use 'source' instead.");
declareOption(ol, "mapping", &RemapLastColumnVMatrix::mapping,
OptionBase::buildoption, "");
declareOption(ol, "if_equals_val", &RemapLastColumnVMatrix::if_equals_val,
OptionBase::buildoption, "");
declareOption(ol, "then_val", &RemapLastColumnVMatrix::then_val,
OptionBase::buildoption, "");
declareOption(ol, "else_val", &RemapLastColumnVMatrix::else_val,
OptionBase::buildoption, "");
inherited::declareOptions(ol);
}

| static const PPath& PLearn::RemapLastColumnVMatrix::declaringFile | ( | ) | [inline, static] |
| RemapLastColumnVMatrix * PLearn::RemapLastColumnVMatrix::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::SourceVMatrix.
Definition at line 49 of file RemapLastColumnVMatrix.cc.
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");
}
}

| 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.
Reimplemented from PLearn::SourceVMatrix.
Definition at line 94 of file RemapLastColumnVMatrix.h.
real PLearn::RemapLastColumnVMatrix::else_val [protected] |
Definition at line 71 of file RemapLastColumnVMatrix.h.
Referenced by declareOptions(), and getNewRow().
real PLearn::RemapLastColumnVMatrix::if_equals_val [protected] |
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().
Mat PLearn::RemapLastColumnVMatrix::mapping [protected] |
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().
real PLearn::RemapLastColumnVMatrix::then_val [protected] |
Definition at line 70 of file RemapLastColumnVMatrix.h.
Referenced by declareOptions(), and getNewRow().
1.7.4