|
PLearn 0.1
|
#include <SDBVMat.h>


Public Member Functions | |
| SDBVMFieldRemapIntervals (SDBVMSource source, const string &mappings, real other_values_mapping=MISSING_VALUE, real missing_values_mapping=MISSING_VALUE, SDBVMOutputCoding oc=SDBVMNumeric, VMField::FieldType ft=VMField::DiscrGeneral) | |
| virtual real | getDiscreteValue (const SDBWithStats &sdb, const Row &row) const |
| Perform the actual remapping. | |
Static Public Member Functions | |
| static void | getIntervals (const string &mappings, bool &all_int, real &max_of_map, Vec &intervals_x, Vec &intervals_y) |
Protected Attributes | |
| Vec | intervals_x_ |
| Vec | intervals_y_ |
| real | other_values_mapping_ |
Private Types | |
| typedef SDBVMFieldDiscrete | inherited |
A field that remaps intervals on the reals onto discrete integer values. The format of the "mappings" argument is: "y_0 x_1 y_1 x_2 y_2 ... x_N y_N", where the "x_i" are cut-points for X, with for the value y_i obtained when x_i <= X < x_{i+1}, and y_0 obtained for X<x_1, and y_N obtained for X >= y_N. It is required that x_i < x_{i+1}.
typedef SDBVMFieldDiscrete PLearn::SDBVMFieldRemapIntervals::inherited [private] |
Reimplemented from PLearn::SDBVMFieldDiscrete.
| PLearn::SDBVMFieldRemapIntervals::SDBVMFieldRemapIntervals | ( | SDBVMSource | source, |
| const string & | mappings, | ||
| real | other_values_mapping = MISSING_VALUE, |
||
| real | missing_values_mapping = MISSING_VALUE, |
||
| SDBVMOutputCoding | oc = SDBVMNumeric, |
||
| VMField::FieldType | ft = VMField::DiscrGeneral |
||
| ) |
Definition at line 868 of file SDBVMat.cc.
References getIntervals(), PLearn::SDBVMOutputCoder::handleOtherAndMissing(), intervals_x_, intervals_y_, and PLearn::SDBVMFieldDiscrete::setNumClasses().
: inherited(source, 0, missing_values_mapping, oc, ft), other_values_mapping_(other_values_mapping) { real max_of_map; bool all_int; getIntervals(mappings, all_int, max_of_map, intervals_x_, intervals_y_); // Initialize base-class member setNumClasses(SDBVMOutputCoder::handleOtherAndMissing( all_int, int(max_of_map), other_values_mapping, missing_values_mapping)); }

| real PLearn::SDBVMFieldRemapIntervals::getDiscreteValue | ( | const SDBWithStats & | sdb, |
| const Row & | row | ||
| ) | const [virtual] |
Perform the actual remapping.
Implements PLearn::SDBVMFieldDiscrete.
Definition at line 886 of file SDBVMat.cc.
References PLearn::binary_search(), PLearn::SDBVMSource::getValue(), intervals_x_, intervals_y_, PLearn::FieldValue::isMissing(), PLearn::SDBVMField::missing_values_mapping_, and PLearn::SDBVMFieldSource1::source_.
{
FieldValue v = source_.getValue(sdb,row);
if(v.isMissing())
return missing_values_mapping_;
else
return intervals_y_[1+int(binary_search(intervals_x_,real(v)))];
}

| void PLearn::SDBVMFieldRemapIntervals::getIntervals | ( | const string & | mappings, |
| bool & | all_int, | ||
| real & | max_of_map, | ||
| Vec & | intervals_x, | ||
| Vec & | intervals_y | ||
| ) | [static] |
This parses the remapping string and returns a map. Whether the target values are all non-negative integers is set in all_int. The maximum target value in the map is set into max_of_map. The intervals are returned in intervals_x and intervals_y
Definition at line 820 of file SDBVMat.cc.
References i, in, PLearn::TVec< T >::length(), PLearn::max(), PLERROR, and PLearn::TVec< T >::resize().
Referenced by SDBVMFieldRemapIntervals().
{
all_int = true;
max_of_map = -FLT_MAX;
istrstream in(mappings.c_str());
real xi, yi;
intervals_x.resize(10);
intervals_y.resize(11);
int i;
for(i=0; ; ++i) {
in >> yi;
if(!in)
PLERROR("In NGSDBVMFieldRemapIntervals::getIntervals: "
"mappings should have an odd number of elements, found %d",
2*i);
intervals_y[i] = yi;
if (all_int && yi >= 0 && yi == int(yi))
max_of_map = std::max(max_of_map, yi);
else
all_int = false;
in >> xi;
if(!in)
break;
if (i>0 && intervals_x[i-1]>=xi)
PLERROR("In NGSDBVMFieldRemapIntervals::getIntervals: "
"mappings needs x_{i-1}<x_i, found x[%d]=%f, x[%d]=%f",
i-1,intervals_x[i-1],i,xi);
intervals_x[i] = xi;
if (intervals_x.length()==i+1) {
intervals_x.resize(2*i);
intervals_y.resize(2*i+1);
}
}
/*NOTE: this used to be a BUG!!! the following used to be:
intervals_x.resize(i-1);
intervals_y.resize(i);
which made both vectors 1 too short...
...no value would ever fall in the last class
*/
intervals_x.resize(i);
intervals_y.resize(i+1);
}


Vec PLearn::SDBVMFieldRemapIntervals::intervals_x_ [protected] |
Definition at line 840 of file SDBVMat.h.
Referenced by getDiscreteValue(), and SDBVMFieldRemapIntervals().
Vec PLearn::SDBVMFieldRemapIntervals::intervals_y_ [protected] |
Definition at line 841 of file SDBVMat.h.
Referenced by getDiscreteValue(), and SDBVMFieldRemapIntervals().
1.7.4