GClasses
GClasses::GAttributeSelector Class Reference

Detailed Description

Generates subsets of data that contain only the most relevant features for predicting the labels. The train method of this class produces a ranked ordering of the feature attributes by training a single-layer neural network, and deselecting the weakest attribute until all attributes have been deselected. The transform method uses only the highest-ranked attributes.

#include <GTransform.h>

Inheritance diagram for GClasses::GAttributeSelector:
GClasses::GIncrementalTransform GClasses::GTransform

Public Member Functions

 GAttributeSelector (size_t labelDims, size_t targetFeatures)
 
 GAttributeSelector (const GDomNode *pNode)
 
virtual ~GAttributeSelector ()
 
std::vector< size_t > & ranks ()
 Returns a list of attributes in ranked-order. Most important attributes are first. Weakest attributes are last. (The results are undefined until after train is called.) More...
 
virtual GDomNodeserialize (GDom *pDoc) const
 Marshal this object into a DOM, which can then be converted to a variety of serial formats. More...
 
void setSeed (size_t seed)
 Sets a random seed to use with this attribute selector. More...
 
GRelationsetTargetFeatures (size_t n)
 Specifies the number of features to select. (This method must be called after train.) More...
 
virtual void transform (const GVec &in, GVec &out)
 See the comment for GIncrementalTransform::transform. More...
 
virtual void untransform (const GVec &in, GVec &out)
 Throws an exception (because this transform cannot be reversed). More...
 
virtual void untransformToDistribution (const GVec &in, GPrediction *pOut)
 Throws an exception (because this transform cannot be reversed). 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 ()
 

Static Public Member Functions

static void test ()
 
- 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...
 

Protected Member Functions

virtual GRelationtrainInner (const GMatrix &data)
 See the comment for GIncrementalTransform::train. More...
 
virtual GRelationtrainInner (const GRelation &relation)
 Throws an exception (because this transform cannot be trained without data) 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

size_t m_labelDims
 
std::vector< size_t > m_ranks
 
size_t m_seed
 
size_t m_targetFeatures
 

Constructor & Destructor Documentation

GClasses::GAttributeSelector::GAttributeSelector ( size_t  labelDims,
size_t  targetFeatures 
)
inline
GClasses::GAttributeSelector::GAttributeSelector ( const GDomNode pNode)
virtual GClasses::GAttributeSelector::~GAttributeSelector ( )
inlinevirtual

Member Function Documentation

std::vector<size_t>& GClasses::GAttributeSelector::ranks ( )
inline

Returns a list of attributes in ranked-order. Most important attributes are first. Weakest attributes are last. (The results are undefined until after train is called.)

virtual GDomNode* GClasses::GAttributeSelector::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.

void GClasses::GAttributeSelector::setSeed ( size_t  seed)
inline

Sets a random seed to use with this attribute selector.

GRelation* GClasses::GAttributeSelector::setTargetFeatures ( size_t  n)

Specifies the number of features to select. (This method must be called after train.)

static void GClasses::GAttributeSelector::test ( )
static
virtual GRelation* GClasses::GAttributeSelector::trainInner ( const GMatrix data)
protectedvirtual
virtual GRelation* GClasses::GAttributeSelector::trainInner ( const GRelation relation)
protectedvirtual

Throws an exception (because this transform cannot be trained without data)

Implements GClasses::GIncrementalTransform.

virtual void GClasses::GAttributeSelector::transform ( const GVec in,
GVec out 
)
virtual
virtual void GClasses::GAttributeSelector::untransform ( const GVec in,
GVec out 
)
inlinevirtual

Throws an exception (because this transform cannot be reversed).

Implements GClasses::GIncrementalTransform.

virtual void GClasses::GAttributeSelector::untransformToDistribution ( const GVec in,
GPrediction pOut 
)
inlinevirtual

Throws an exception (because this transform cannot be reversed).

Implements GClasses::GIncrementalTransform.

Member Data Documentation

size_t GClasses::GAttributeSelector::m_labelDims
protected
std::vector<size_t> GClasses::GAttributeSelector::m_ranks
protected
size_t GClasses::GAttributeSelector::m_seed
protected
size_t GClasses::GAttributeSelector::m_targetFeatures
protected