PLearn 0.1
|
#include <SDBVMat.h>
Public Member Functions | |
SDBVMFieldRemapReals (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) | |
This constructor accepts an explicitly-specified mappings string. | |
SDBVMFieldRemapReals (SDBVMSource source, const FieldStat &field_stat, 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 RealMap | getRealMapping (const string &mappings) |
This parses the remapping string and returns a map. | |
Protected Attributes | |
RealMap | real_mapping_ |
real | other_values_mapping_ |
Private Types | |
typedef SDBVMFieldDiscrete | inherited |
typedef map< real, real > | RealMap |
A field that remaps a finite set of real values onto discrete integer values in the range 0 -- n-1. The mapping provided in the constructor has the format: "originalvalue1 newvalue1 original2 newvalue2 ... " meaning that when the SDB field takes value originalvalueX then the VMatrix corresponding column will have the value newvalueX. If none of the "original values" is seen then the "other_values_mapping" value is obtained. If the SDB contains a MISSING_VALUE then the "missing_values_mapping" is given.
typedef SDBVMFieldDiscrete PLearn::SDBVMFieldRemapReals::inherited [private] |
Reimplemented from PLearn::SDBVMFieldDiscrete.
typedef map<real,real> PLearn::SDBVMFieldRemapReals::RealMap [private] |
PLearn::SDBVMFieldRemapReals::SDBVMFieldRemapReals | ( | 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 |
||
) |
This constructor accepts an explicitly-specified mappings string.
Definition at line 688 of file SDBVMat.cc.
References PLearn::SDBVMOutputCoder::getNumClasses(), real_mapping_, and PLearn::SDBVMFieldDiscrete::setNumClasses().
: inherited(source, 0, missing_values_mapping, oc, ft), real_mapping_(getRealMapping(mappings)), other_values_mapping_(other_values_mapping) { // Set the base-class num_classes_ setNumClasses(SDBVMOutputCoder::getNumClasses( real_mapping_, other_values_mapping, missing_values_mapping)); }
PLearn::SDBVMFieldRemapReals::SDBVMFieldRemapReals | ( | SDBVMSource | source, |
const FieldStat & | field_stat, | ||
real | other_values_mapping = MISSING_VALUE , |
||
real | missing_values_mapping = MISSING_VALUE , |
||
SDBVMOutputCoding | oc = SDBVMNumeric , |
||
VMField::FieldType | ft = VMField::DiscrGeneral |
||
) |
This constructor accepts mappings coming from a FieldStat. Note that the "hasmissing" field of the FieldStat is not automatically taken into account, and you must provide a missing_values_mapping here by yourself. The mapping is not modified in any way by the presence of missing values.
Definition at line 703 of file SDBVMat.cc.
References PLearn::SDBVMOutputCoder::getNumClasses(), real_mapping_, PLearn::SDBVMFieldDiscrete::setNumClasses(), PLearn::FieldStat::symbolid, and PLearn::todouble().
: inherited(source, 0, missing_values_mapping, oc, ft), other_values_mapping_(other_values_mapping) { map<string,int>::iterator it = field_stat.symbolid.begin(), end = field_stat.symbolid.end(); for( ; it != end; ++it) real_mapping_[real(todouble(it->first))] = it->second; // Set the base-class num_classes_ setNumClasses(SDBVMOutputCoder::getNumClasses( real_mapping_, other_values_mapping, missing_values_mapping)); }
real PLearn::SDBVMFieldRemapReals::getDiscreteValue | ( | const SDBWithStats & | sdb, |
const Row & | row | ||
) | const [virtual] |
Perform the actual remapping.
Implements PLearn::SDBVMFieldDiscrete.
Definition at line 722 of file SDBVMat.cc.
References PLearn::SDBVMSource::getValue(), PLearn::FieldValue::isMissing(), PLearn::SDBVMField::missing_values_mapping_, other_values_mapping_, real_mapping_, and PLearn::SDBVMFieldSource1::source_.
{ FieldValue v = source_.getValue(sdb,row); if(v.isMissing()) return missing_values_mapping_; real realval = real(v); RealMap::const_iterator found = real_mapping_.find(realval); if (found != real_mapping_.end()) realval = found->second; else realval = other_values_mapping_; return realval; }
SDBVMFieldRemapReals::RealMap PLearn::SDBVMFieldRemapReals::getRealMapping | ( | const string & | mappings | ) | [static] |
This parses the remapping string and returns a map.
The maximum target value in the map is set into the last (reference) argument.
Definition at line 670 of file SDBVMat.cc.
References in.
Definition at line 755 of file SDBVMat.h.
Referenced by getDiscreteValue().
RealMap PLearn::SDBVMFieldRemapReals::real_mapping_ [protected] |
Definition at line 754 of file SDBVMat.h.
Referenced by getDiscreteValue(), and SDBVMFieldRemapReals().