GClasses
GClasses::GPCA Class Reference

Detailed Description

Principal Component Analysis. (Computes the principal components about the mean of the data when you call train. The transformed (reduced-dimensional) data will have a mean about the origin.)

#include <GTransform.h>

Inheritance diagram for GClasses::GPCA:
GClasses::GIncrementalTransform GClasses::GTransform

Public Member Functions

 GPCA (size_t targetDims)
 
 GPCA (const GDomNode *pNode)
 Load from a DOM. More...
 
virtual ~GPCA ()
 
void aboutOrigin ()
 Specify to compute the principal components about the origin (instead of computing them about the mean). More...
 
GMatrixbasis ()
 Returns the matrix of basis vectors. Row 0 is the first principal component, row 1 is the second principal component, and so forth. More...
 
GVeccentroid ()
 Returns the centroid about which the principal components were calculated. More...
 
GMatrixcomponents ()
 Returns a dataset where the first row is the centroid, and the remaining rows are the principal component vectors in order of decreasing eigenvalue. More...
 
void computeEigVals ()
 Specify to compute the eigenvalues during training. This method must be called before train is called. More...
 
GVeceigVals ()
 Returns the eigenvalues. Returns NULL if computeEigVals was not called. More...
 
GRandrand ()
 Returns a reference to the pseudo-random number generator used by this object. More...
 
virtual GDomNodeserialize (GDom *pDoc) const
 Marshal this object into a DOM, which can then be converted to a variety of serial formats. More...
 
size_t targetDims ()
 Returns the number of principal components that it will find. More...
 
virtual void transform (const GVec &in, GVec &out)
 See the comment for GIncrementalTransform::transform. Projects the specified point into fewer dimensions. More...
 
virtual void untransform (const GVec &in, GVec &out)
 Computes a (lossy) high-dimensional point that corresponds with the specified low-dimensional coordinates. 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

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

bool m_aboutOrigin
 
GVec m_eigVals
 
GMatrixm_pBasisVectors
 
GMatrixm_pCentroid
 
GRand m_rand
 
size_t m_targetDims
 

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::GPCA::GPCA ( size_t  targetDims)
GClasses::GPCA::GPCA ( const GDomNode pNode)

Load from a DOM.

virtual GClasses::GPCA::~GPCA ( )
virtual

Member Function Documentation

void GClasses::GPCA::aboutOrigin ( )
inline

Specify to compute the principal components about the origin (instead of computing them about the mean).

GMatrix* GClasses::GPCA::basis ( )
inline

Returns the matrix of basis vectors. Row 0 is the first principal component, row 1 is the second principal component, and so forth.

GVec& GClasses::GPCA::centroid ( )
inline

Returns the centroid about which the principal components were calculated.

GMatrix* GClasses::GPCA::components ( )
inline

Returns a dataset where the first row is the centroid, and the remaining rows are the principal component vectors in order of decreasing eigenvalue.

void GClasses::GPCA::computeEigVals ( )

Specify to compute the eigenvalues during training. This method must be called before train is called.

GVec& GClasses::GPCA::eigVals ( )
inline

Returns the eigenvalues. Returns NULL if computeEigVals was not called.

GRand& GClasses::GPCA::rand ( )
inline

Returns a reference to the pseudo-random number generator used by this object.

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

size_t GClasses::GPCA::targetDims ( )
inline

Returns the number of principal components that it will find.

virtual GRelation* GClasses::GPCA::trainInner ( const GMatrix data)
protectedvirtual
virtual GRelation* GClasses::GPCA::trainInner ( const GRelation relation)
protectedvirtual

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

Implements GClasses::GIncrementalTransform.

virtual void GClasses::GPCA::transform ( const GVec in,
GVec out 
)
virtual

See the comment for GIncrementalTransform::transform. Projects the specified point into fewer dimensions.

Implements GClasses::GIncrementalTransform.

virtual void GClasses::GPCA::untransform ( const GVec in,
GVec out 
)
virtual

Computes a (lossy) high-dimensional point that corresponds with the specified low-dimensional coordinates.

Implements GClasses::GIncrementalTransform.

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

Member Data Documentation

bool GClasses::GPCA::m_aboutOrigin
protected
GVec GClasses::GPCA::m_eigVals
protected
GMatrix* GClasses::GPCA::m_pBasisVectors
protected
GMatrix* GClasses::GPCA::m_pCentroid
protected
GRand GClasses::GPCA::m_rand
protected
size_t GClasses::GPCA::m_targetDims
protected