PLearn 0.1
Public Member Functions | Static Public Member Functions | Protected Attributes | Private Types
PLearn::SDBVMFieldRemapStrings Class Reference

#include <SDBVMat.h>

Inheritance diagram for PLearn::SDBVMFieldRemapStrings:
Inheritance graph
[legend]
Collaboration diagram for PLearn::SDBVMFieldRemapStrings:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 SDBVMFieldRemapStrings (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.
 SDBVMFieldRemapStrings (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 StringMap getStringMapping (const string &mappings)
 This parses the remapping string and returns a map.

Protected Attributes

StringMap string_mapping_
real other_values_mapping_

Private Types

typedef SDBVMFieldDiscrete inherited
typedef map< string, realStringMap

Detailed Description

A field that remaps a finite set of strings onto discrete integers. The format of "mappings" is a string of the form: "string_0 value_0 string_1 value_1 ... string_N value_N" where the string_i cannot contain spaces, and the space is the delimiter between strings and values. If none of the "string_X" is seen then the "other_values_mapping" value is obtained. If the SDB contains a MISSING_VALUE then the "missing_values_mapping" is given.

Definition at line 768 of file SDBVMat.h.


Member Typedef Documentation

Reimplemented from PLearn::SDBVMFieldDiscrete.

Definition at line 770 of file SDBVMat.h.

typedef map<string,real> PLearn::SDBVMFieldRemapStrings::StringMap [private]

Definition at line 771 of file SDBVMat.h.


Constructor & Destructor Documentation

PLearn::SDBVMFieldRemapStrings::SDBVMFieldRemapStrings ( 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 761 of file SDBVMat.cc.

References PLearn::SDBVMOutputCoder::getNumClasses(), PLearn::SDBVMFieldDiscrete::setNumClasses(), and string_mapping_.

    : inherited(source, 0, missing_values_mapping, oc, ft),
      string_mapping_(getStringMapping(mappings)),
      other_values_mapping_(other_values_mapping)
{
    // Set the base-class num_classes_
    setNumClasses(SDBVMOutputCoder::getNumClasses(
                      string_mapping_, other_values_mapping, missing_values_mapping));
}

Here is the call graph for this function:

PLearn::SDBVMFieldRemapStrings::SDBVMFieldRemapStrings ( 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 776 of file SDBVMat.cc.

References PLearn::SDBVMOutputCoder::getNumClasses(), PLearn::SDBVMFieldDiscrete::setNumClasses(), string_mapping_, and PLearn::FieldStat::symbolid.

    : 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)
        string_mapping_[it->first] = it->second;
    
    // Set the base-class num_classes_
    setNumClasses(SDBVMOutputCoder::getNumClasses(
                      string_mapping_, other_values_mapping, missing_values_mapping));
}

Here is the call graph for this function:


Member Function Documentation

real PLearn::SDBVMFieldRemapStrings::getDiscreteValue ( const SDBWithStats sdb,
const Row row 
) const [virtual]

Perform the actual remapping.

Implements PLearn::SDBVMFieldDiscrete.

Definition at line 795 of file SDBVMat.cc.

References PLearn::SDBVMSource::getValue(), PLearn::FieldValue::isMissing(), PLearn::SDBVMField::missing_values_mapping_, other_values_mapping_, PLearn::SDBVMFieldSource1::source_, PLearn::space_to_underscore(), and string_mapping_.

{
    real realval;
    FieldValue v = source_.getValue(sdb,row);
    if(v.isMissing())
        /*NOTE: this used to be a BUG!!! the following used to be
          realval = missing_values_mapping_;
          but realval was overriden with other_values_mapping_
          a few lines later... and never returned
        */
        return missing_values_mapping_;
    string s = space_to_underscore(string(v));
    StringMap::const_iterator found = string_mapping_.find(s);
    if (found != string_mapping_.end())
        realval = found->second;
    else
        realval = other_values_mapping_;
    return realval;
}

Here is the call graph for this function:

SDBVMFieldRemapStrings::StringMap PLearn::SDBVMFieldRemapStrings::getStringMapping ( 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 742 of file SDBVMat.cc.

References in.

{
    StringMap string_mapping;
    
    if(!mappings.empty()) {
        istrstream in(mappings.c_str());
        string stringkey;
        real value;

        for(;;) {
            in >> stringkey >> value;
            if (!in)
                break;
            string_mapping[stringkey] = value;
        }
    }
    return string_mapping;
}

Member Data Documentation

Definition at line 804 of file SDBVMat.h.

Referenced by getDiscreteValue().

Definition at line 803 of file SDBVMat.h.

Referenced by getDiscreteValue(), and SDBVMFieldRemapStrings().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines