GClasses
GClasses::GNominalToCat Class Reference

Detailed Description

This is sort-of the opposite of discretize. It converts each nominal attribute to a categorical distribution by representing each value using the corresponding row of the identity matrix. For example, if a certain nominal attribute has 4 possible values, then a value of 3 would be encoded as the vector 0 0 1 0. When predictions are converted back to nominal values, the mode of the categorical distribution is used as the predicted value. (This is similar to Weka's NominalToBinaryFilter.)

#include <GTransform.h>

Inheritance diagram for GClasses::GNominalToCat:
GClasses::GIncrementalTransform GClasses::GTransform

Public Member Functions

 GNominalToCat (size_t valueCap=12, double lo=0.0, double hi=1.0)
 
 GNominalToCat (const GDomNode *pNode)
 Load from a DOM. More...
 
virtual ~GNominalToCat ()
 
void preserveUnknowns ()
 Specify to preserve unknown values. That is, an unknown nominal value will be converted to a distribution of all unknown real values. More...
 
void reverseAttrMap (std::vector< size_t > &rmap)
 Makes a mapping from the post-transform attribute indexes to the pre-transform attribute indexes. More...
 
virtual GDomNodeserialize (GDom *pDoc) const
 Marshal this object into a DOM, which can then be converted to a variety of serial formats. More...
 
virtual void transform (const GVec &in, GVec &out)
 See the comment for GIncrementalTransform::transform. More...
 
virtual void untransform (const GVec &in, GVec &out)
 See the comment for GIncrementalTransform::untransform. More...
 
virtual void untransformToDistribution (const GVec &in, GPrediction *pOut)
 See the comment for GIncrementalTransform::untransformToDistribution. More...
 
- Public Member Functions inherited from GClasses::GIncrementalTransform
 GIncrementalTransform ()
 
 GIncrementalTransform (const GDomNode *pNode)
 
virtual ~GIncrementalTransform ()
 
const GRelationafter () const
 Returns a relation object describing the data after it is transformed. More...
 
const GRelationbefore () const
 Returns a relation object describing the data before it is transformed. More...
 
GVecinnerBuf ()
 Returns a buffer of sufficient size to store an inner (transformed) vector. The caller should not to delete the buffer. The same buffer will be returned each time. More...
 
virtual GMatrixreduce (const GMatrix &in)
 This calls train, then calls transformBatch, and returns the result. More...
 
void setAfter (GRelation *pRel)
 Sets the after relation. Takes ownership of pRel. More...
 
void setBefore (GRelation *pRel)
 Sets the before relation. Takes ownership of pRel. More...
 
void train (const GMatrix &data)
 Trains the transform on the data in pData. (This method may be a no-op for transformations that always behave in the same manner.) More...
 
void train (const GRelation &pRelation)
 "Trains" the transform without any data. More...
 
virtual GMatrixtransformBatch (const GMatrix &in)
 This assumes that train has already been called, and transforms all the rows in in returning the resulting matrix. The caller is responsible for deleting the new matrix. More...
 
virtual std::unique_ptr< GMatrixuntransformBatch (const GMatrix &in)
 This assumes train was previously called, and untransforms all the rows in pIn and returns the results. More...
 
- Public Member Functions inherited from GClasses::GTransform
 GTransform ()
 
 GTransform (const GDomNode *pNode)
 
virtual ~GTransform ()
 

Protected Member Functions

GRelationinit ()
 
virtual GRelationtrainInner (const GMatrix &data)
 See the comment for GIncrementalTransform::train. More...
 
virtual GRelationtrainInner (const GRelation &relation)
 See the comment for GIncrementalTransform::train. More...
 
- Protected Member Functions inherited from GClasses::GIncrementalTransform
virtual GDomNodebaseDomNode (GDom *pDoc, const char *szClassName) const
 Child classes should use this in their implementation of serialize. More...
 

Protected Attributes

double m_hi
 
double m_lo
 
GRandm_pRand
 
bool m_preserveUnknowns
 
std::vector< size_t > m_ranks
 
size_t m_valueCap
 

Additional Inherited Members

- Static Public Member Functions inherited from GClasses::GIncrementalTransform
static void test ()
 Performs unit tests for this class. Throws an exception if there is a failure. More...
 

Constructor & Destructor Documentation

GClasses::GNominalToCat::GNominalToCat ( size_t  valueCap = 12,
double  lo = 0.0,
double  hi = 1.0 
)
GClasses::GNominalToCat::GNominalToCat ( const GDomNode pNode)

Load from a DOM.

virtual GClasses::GNominalToCat::~GNominalToCat ( )
virtual

Member Function Documentation

GRelation* GClasses::GNominalToCat::init ( )
protected
void GClasses::GNominalToCat::preserveUnknowns ( )
inline

Specify to preserve unknown values. That is, an unknown nominal value will be converted to a distribution of all unknown real values.

void GClasses::GNominalToCat::reverseAttrMap ( std::vector< size_t > &  rmap)

Makes a mapping from the post-transform attribute indexes to the pre-transform attribute indexes.

virtual GDomNode* GClasses::GNominalToCat::serialize ( GDom pDoc) const
virtual

Marshal this object into a DOM, which can then be converted to a variety of serial formats.

Implements GClasses::GIncrementalTransform.

virtual GRelation* GClasses::GNominalToCat::trainInner ( const GMatrix data)
protectedvirtual
virtual GRelation* GClasses::GNominalToCat::trainInner ( const GRelation relation)
protectedvirtual
virtual void GClasses::GNominalToCat::transform ( const GVec in,
GVec out 
)
virtual
virtual void GClasses::GNominalToCat::untransform ( const GVec in,
GVec out 
)
virtual
virtual void GClasses::GNominalToCat::untransformToDistribution ( const GVec in,
GPrediction pOut 
)
virtual

Member Data Documentation

double GClasses::GNominalToCat::m_hi
protected
double GClasses::GNominalToCat::m_lo
protected
GRand* GClasses::GNominalToCat::m_pRand
protected
bool GClasses::GNominalToCat::m_preserveUnknowns
protected
std::vector<size_t> GClasses::GNominalToCat::m_ranks
protected
size_t GClasses::GNominalToCat::m_valueCap
protected