00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
#include "RemapLastColumnVMatrix.h"
00042
00043
namespace PLearn {
00044
using namespace std;
00045
00046
00049
PLEARN_IMPLEMENT_OBJECT(RemapLastColumnVMatrix,
"ONE LINE DESC",
"NO HELP");
00050
00051 RemapLastColumnVMatrix::RemapLastColumnVMatrix()
00052 : if_equals_val(0), then_val(0), else_val(0)
00053 {
00054 }
00055
00056 RemapLastColumnVMatrix::RemapLastColumnVMatrix(
VMat the_underlying_distr,
Mat the_mapping)
00057 :
inherited (the_underlying_distr->length(), the_underlying_distr->width()+the_mapping.width()-2),
00058 underlying_distr(the_underlying_distr), mapping(the_mapping)
00059 {
00060 }
00061
00062 RemapLastColumnVMatrix::RemapLastColumnVMatrix(
VMat the_underlying_distr,
real if_equals_value,
real then_value,
real else_value)
00063 :
inherited(the_underlying_distr->length(), the_underlying_distr->width()),
00064 underlying_distr(the_underlying_distr), if_equals_val(if_equals_value),
00065 then_val(then_value), else_val(else_value)
00066 {
00067 }
00068
00069
void
00070 RemapLastColumnVMatrix::build()
00071 {
00072 inherited::build();
00073
build_();
00074 }
00075
00076
void
00077 RemapLastColumnVMatrix::build_()
00078 {
00079 }
00080
00081
void
00082 RemapLastColumnVMatrix::declareOptions(
OptionList &ol)
00083 {
00084
declareOption(ol,
"underlying_distr", &RemapLastColumnVMatrix::underlying_distr, OptionBase::buildoption,
"");
00085
declareOption(ol,
"mapping", &RemapLastColumnVMatrix::mapping, OptionBase::buildoption,
"");
00086
declareOption(ol,
"if_equals_val", &RemapLastColumnVMatrix::if_equals_val, OptionBase::buildoption,
"");
00087
declareOption(ol,
"then_val", &RemapLastColumnVMatrix::then_val, OptionBase::buildoption,
"");
00088
declareOption(ol,
"else_val", &RemapLastColumnVMatrix::else_val, OptionBase::buildoption,
"");
00089 inherited::declareOptions(ol);
00090 }
00091
00092 void RemapLastColumnVMatrix::getNewRow(
int i,
const Vec& samplevec)
const
00093
{
00094
#ifdef BOUNDCHECK
00095
if(i<0 || i>=
length())
00096
PLERROR(
"In RemapLastColumnVMatrix::getNewRow OUT OF BOUNDS");
00097
if(samplevec.
length()!=
width())
00098
PLERROR(
"In RemapLastColumnVMatrix::getNewRow samplevec.length() must be equal to the VMat's width");
00099
#endif
00100
if(
mapping.
isEmpty())
00101 {
00102
underlying_distr->getRow(i,samplevec);
00103
real& lastelem = samplevec.
lastElement();
00104
if(lastelem==
if_equals_val)
00105 lastelem =
then_val;
00106
else
00107 lastelem =
else_val;
00108 }
00109
else
00110 {
00111
int underlying_width =
underlying_distr->
width();
00112
int replacement_width =
mapping.
width()-1;
00113
underlying_distr->getRow(i,samplevec.
subVec(0,underlying_width));
00114
real val = samplevec[underlying_width-1];
00115
int k;
00116
for(
k=0;
k<
mapping.
length();
k++)
00117 {
00118
if(
mapping(
k,0)==
val)
00119 {
00120 samplevec.subVec(underlying_width-1,replacement_width) <<
mapping(
k).subVec(1,replacement_width);
00121
break;
00122 }
00123 }
00124
if(
k>=
mapping.
length())
00125
PLERROR(
"In RemapLastColumnVMatrix::getRow there is a value in the last column that does not have any defined mapping");
00126 }
00127 }
00128
00129 }