GClasses
GClasses::GNeuralDecomposition Class Reference

#include <GNeuralDecomposition.h>

Inheritance diagram for GClasses::GNeuralDecomposition:
GClasses::GIncrementalLearner GClasses::GSupervisedLearner GClasses::GTransducer

Public Member Functions

 GNeuralDecomposition ()
 
 GNeuralDecomposition (const GDomNode *pNode)
 
virtual ~GNeuralDecomposition ()
 
bool autoFilter () const
 
virtual void clear ()
 Discards all training for the purpose of freeing memory. If you call this method, you must train before making any predictions. No settings or options are discarded, so you should be able to train again without specifying any other parameters and still get a comparable model. More...
 
void clearFrozen ()
 
size_t epochs () const
 
virtual GMatrixextrapolate (double start=1.0, double length=1.0, double step=0.0002, bool outputFeatures=false)
 
virtual GMatrixextrapolate (const GMatrix &features)
 
double featureBias () const
 
double featureScale () const
 
bool filterLogarithm () const
 
void freeze ()
 
double learningRate () const
 
GNeuralNetnn () const
 
double outputBias () const
 
double outputScale () const
 
virtual void predict (const GVec &in, GVec &out)
 Evaluate pIn to compute a prediction for pOut. The model must be trained (by calling train) before the first time that this method is called. pIn and pOut should point to arrays of doubles of the same size as the number of columns in the training matrices that were passed to the train method. More...
 
virtual void predictDistribution (const GVec &in, GPrediction *pOut)
 Evaluate pIn and compute a prediction for pOut. pOut is expected to point to an array of GPrediction objects which have already been allocated. There should be labelDims() elements in this array. The distributions will be more accurate if the model is calibrated before the first time that this method is called. More...
 
double regularization () const
 
void restoreFrozen ()
 
virtual GDomNodeserialize (GDom *pDoc) const
 Marshal this object into a DOM that can be converted to a variety of formats. (Implementations of this method should use baseDomNode.) More...
 
void setAutoFilter (bool auto_Filter)
 
void setEpochs (size_t newepochs)
 
void setFeatureBias (double newfeatureBias)
 
void setFeatureScale (double newfeatureScale)
 
void setFilterLogarithm (bool filter_Logarithm)
 
void setLearningRate (double newlearningRate)
 
void setLinearUnits (size_t linearUnits)
 
void setLockPairs (bool lockPairs)
 
void setOutputBias (double newoutputBias)
 
void setOutputScale (double newoutputScale)
 
void setRegularization (double newregularization)
 
void setSigmoidUnits (size_t sigmoidUnits)
 
void setSinusoidUnits (size_t sinusoidUnits)
 
void setSoftplusUnits (size_t softplusUnits)
 
virtual void trainIncremental (const GVec &in, const GVec &pOut)
 Pass a single input row and the corresponding label to incrementally train this model. More...
 
virtual void trainOnSeries (const GMatrix &series)
 
virtual void trainSparse (GSparseMatrix &features, GMatrix &labels)
 Train using a sparse feature matrix. (A Typical implementation of this method will first call beginIncrementalLearning, then it will iterate over all of the feature rows, and for each row it will convert the sparse row to a dense row, call trainIncremental using the dense row, then discard the dense row and proceed to the next row.) More...
 
- Public Member Functions inherited from GClasses::GIncrementalLearner
 GIncrementalLearner ()
 General-purpose constructor. More...
 
 GIncrementalLearner (const GDomNode *pNode)
 Deserialization constructor. More...
 
virtual ~GIncrementalLearner ()
 Destructor. More...
 
void beginIncrementalLearning (const GRelation &featureRel, const GRelation &labelRel)
 You must call this method before you call trainIncremental. More...
 
void beginIncrementalLearning (const GMatrix &features, const GMatrix &labels)
 A version of beginIncrementalLearning that supports data-dependent filters. More...
 
virtual bool canTrainIncrementally ()
 Returns true. More...
 
virtual bool isFilter ()
 Only the GFilter class should return true to this method. More...
 
- Public Member Functions inherited from GClasses::GSupervisedLearner
 GSupervisedLearner ()
 General-purpose constructor. More...
 
 GSupervisedLearner (const GDomNode *pNode)
 Deserialization constructor. More...
 
virtual ~GSupervisedLearner ()
 Destructor. More...
 
void basicTest (double minAccuracy1, double minAccuracy2, double deviation=1e-6, bool printAccuracy=false, double warnRange=0.035)
 This is a helper method used by the unit tests of several model learners. More...
 
virtual bool canGeneralize ()
 Returns true because fully supervised learners have an internal model that allows them to generalize previously unseen rows. More...
 
void confusion (GMatrix &features, GMatrix &labels, std::vector< GMatrix * > &stats)
 Generates a confusion matrix containing the total counts of the number of times each value was expected and predicted. (Rows represent target values, and columns represent predicted values.) stats should be an empty vector. This method will resize stats to the number of dimensions in the label vector. The caller is responsible to delete all of the matrices that it puts in this vector. For continuous labels, the value will be NULL. More...
 
void precisionRecall (double *pOutPrecision, size_t nPrecisionSize, GMatrix &features, GMatrix &labels, size_t label, size_t nReps)
 label specifies which output to measure. (It should be 0 if there is only one label dimension.) The measurement will be performed "nReps" times and results averaged together nPrecisionSize specifies the number of points at which the function is sampled pOutPrecision should be an array big enough to hold nPrecisionSize elements for every possible label value. (If the attribute is continuous, it should just be big enough to hold nPrecisionSize elements.) If bLocal is true, it computes the local precision instead of the global precision. More...
 
const GRelationrelFeatures ()
 Returns a reference to the feature relation (meta-data about the input attributes). More...
 
const GRelationrelLabels ()
 Returns a reference to the label relation (meta-data about the output attributes). More...
 
double sumSquaredError (const GMatrix &features, const GMatrix &labels, double *pOutSAE=NULL)
 Computes the sum-squared-error for predicting the labels from the features. For categorical labels, Hamming distance is used. More...
 
void train (const GMatrix &features, const GMatrix &labels)
 Call this method to train the model. More...
 
virtual double trainAndTest (const GMatrix &trainFeatures, const GMatrix &trainLabels, const GMatrix &testFeatures, const GMatrix &testLabels, double *pOutSAE=NULL)
 Trains and tests this learner. Returns sum-squared-error. More...
 
- Public Member Functions inherited from GClasses::GTransducer
 GTransducer ()
 General-purpose constructor. More...
 
 GTransducer (const GTransducer &that)
 Copy-constructor. Throws an exception to prevent models from being copied by value. More...
 
virtual ~GTransducer ()
 
virtual bool canImplicitlyHandleContinuousFeatures ()
 Returns true iff this algorithm can implicitly handle continuous features. If it cannot, then the GDiscretize transform will be used to convert continuous features to nominal values before passing them to it. More...
 
virtual bool canImplicitlyHandleContinuousLabels ()
 Returns true iff this algorithm can implicitly handle continuous labels (a.k.a. regression). If it cannot, then the GDiscretize transform will be used during training to convert nominal labels to continuous values, and to convert nominal predictions back to continuous labels. More...
 
virtual bool canImplicitlyHandleMissingFeatures ()
 Returns true iff this algorithm supports missing feature values. If it cannot, then an imputation filter will be used to predict missing values before any feature-vectors are passed to the algorithm. More...
 
virtual bool canImplicitlyHandleNominalFeatures ()
 Returns true iff this algorithm can implicitly handle nominal features. If it cannot, then the GNominalToCat transform will be used to convert nominal features to continuous values before passing them to it. More...
 
virtual bool canImplicitlyHandleNominalLabels ()
 Returns true iff this algorithm can implicitly handle nominal labels (a.k.a. classification). If it cannot, then the GNominalToCat transform will be used during training to convert nominal labels to continuous values, and to convert categorical predictions back to nominal labels. More...
 
double crossValidate (const GMatrix &features, const GMatrix &labels, size_t nFolds, double *pOutSAE=NULL, RepValidateCallback pCB=NULL, size_t nRep=0, void *pThis=NULL)
 Perform n-fold cross validation on pData. Returns sum-squared error. Uses trainAndTest for each fold. pCB is an optional callback method for reporting intermediate stats. It can be NULL if you don't want intermediate reporting. nRep is just the rep number that will be passed to the callback. pThis is just a pointer that will be passed to the callback for you to use however you want. It doesn't affect this method. if pOutSAE is not NULL, the sum absolute error will be placed there. More...
 
GTransduceroperator= (const GTransducer &other)
 Throws an exception to prevent models from being copied by value. More...
 
GRandrand ()
 Returns a reference to the random number generator associated with this object. For example, you could use it to change the random seed, to make this algorithm behave differently. This might be important, for example, in an ensemble of learners. More...
 
double repValidate (const GMatrix &features, const GMatrix &labels, size_t reps, size_t nFolds, double *pOutSAE=NULL, RepValidateCallback pCB=NULL, void *pThis=NULL)
 Perform cross validation "nReps" times and return the average score. pCB is an optional callback method for reporting intermediate stats It can be NULL if you don't want intermediate reporting. pThis is just a pointer that will be passed to the callback for you to use however you want. It doesn't affect this method. if pOutSAE is not NULL, the sum absolute error will be placed there. More...
 
virtual bool supportedFeatureRange (double *pOutMin, double *pOutMax)
 Returns true if this algorithm supports any feature value, or if it does not implicitly handle continuous features. If a limited range of continuous values is supported, returns false and sets pOutMin and pOutMax to specify the range. More...
 
virtual bool supportedLabelRange (double *pOutMin, double *pOutMax)
 Returns true if this algorithm supports any label value, or if it does not implicitly handle continuous labels. If a limited range of continuous values is supported, returns false and sets pOutMin and pOutMax to specify the range. More...
 
std::unique_ptr< GMatrixtransduce (const GMatrix &features1, const GMatrix &labels1, const GMatrix &features2)
 Predicts a set of labels to correspond with features2, such that these labels will be consistent with the patterns exhibited by features1 and labels1. More...
 
void transductiveConfusionMatrix (const GMatrix &trainFeatures, const GMatrix &trainLabels, const GMatrix &testFeatures, const GMatrix &testLabels, std::vector< GMatrix * > &stats)
 Makes a confusion matrix for a transduction algorithm. More...
 

Static Public Member Functions

static void test ()
 
- Static Public Member Functions inherited from GClasses::GSupervisedLearner
static void test ()
 Runs some unit tests related to supervised learning. Throws an exception if any problems are found. More...
 

Protected Member Functions

virtual void beginIncrementalLearningInner (const GRelation &featureRel, const GRelation &labelRel)
 Prepare the model for incremental learning. More...
 
virtual void trainInner (const GMatrix &features, const GMatrix &labels)
 This is the implementation of the model's training algorithm. (This method is called by train). More...
 
- Protected Member Functions inherited from GClasses::GIncrementalLearner
virtual void beginIncrementalLearningInner (const GMatrix &features, const GMatrix &labels)
 
- Protected Member Functions inherited from GClasses::GSupervisedLearner
GDomNodebaseDomNode (GDom *pDoc, const char *szClassName) const
 Child classes should use this in their implementation of serialize. More...
 
size_t precisionRecallContinuous (GPrediction *pOutput, double *pFunc, GMatrix &trainFeatures, GMatrix &trainLabels, GMatrix &testFeatures, GMatrix &testLabels, size_t label)
 This is a helper method used by precisionRecall. More...
 
size_t precisionRecallNominal (GPrediction *pOutput, double *pFunc, GMatrix &trainFeatures, GMatrix &trainLabels, GMatrix &testFeatures, GMatrix &testLabels, size_t label, int value)
 This is a helper method used by precisionRecall. More...
 
void setupFilters (const GMatrix &features, const GMatrix &labels)
 This method determines which data filters (normalize, discretize, and/or nominal-to-cat) are needed and trains them. More...
 
virtual std::unique_ptr< GMatrixtransduceInner (const GMatrix &features1, const GMatrix &labels1, const GMatrix &features2)
 See GTransducer::transduce. More...
 

Additional Inherited Members

- Static Protected Member Functions inherited from GClasses::GSupervisedLearner
static void addInterpolatedFunction (double *pOut, size_t nOutVals, double *pIn, size_t nInVals)
 Adds the function pIn to pOut after interpolating pIn to be the same size as pOut. (This is a helper-function used by precisionRecall.) More...
 
- Protected Attributes inherited from GClasses::GSupervisedLearner
GRelationm_pRelFeatures
 
GRelationm_pRelLabels
 
- Protected Attributes inherited from GClasses::GTransducer
GRand m_rand
 

Constructor & Destructor Documentation

GClasses::GNeuralDecomposition::GNeuralDecomposition ( )
GClasses::GNeuralDecomposition::GNeuralDecomposition ( const GDomNode pNode)
virtual GClasses::GNeuralDecomposition::~GNeuralDecomposition ( )
virtual

Member Function Documentation

bool GClasses::GNeuralDecomposition::autoFilter ( ) const
inline
virtual void GClasses::GNeuralDecomposition::beginIncrementalLearningInner ( const GRelation featureRel,
const GRelation labelRel 
)
protectedvirtual

Prepare the model for incremental learning.

Implements GClasses::GIncrementalLearner.

virtual void GClasses::GNeuralDecomposition::clear ( )
inlinevirtual

Discards all training for the purpose of freeing memory. If you call this method, you must train before making any predictions. No settings or options are discarded, so you should be able to train again without specifying any other parameters and still get a comparable model.

Implements GClasses::GSupervisedLearner.

void GClasses::GNeuralDecomposition::clearFrozen ( )
size_t GClasses::GNeuralDecomposition::epochs ( ) const
inline
virtual GMatrix* GClasses::GNeuralDecomposition::extrapolate ( double  start = 1.0,
double  length = 1.0,
double  step = 0.0002,
bool  outputFeatures = false 
)
virtual
virtual GMatrix* GClasses::GNeuralDecomposition::extrapolate ( const GMatrix features)
virtual
double GClasses::GNeuralDecomposition::featureBias ( ) const
inline
double GClasses::GNeuralDecomposition::featureScale ( ) const
inline
bool GClasses::GNeuralDecomposition::filterLogarithm ( ) const
inline
void GClasses::GNeuralDecomposition::freeze ( )
double GClasses::GNeuralDecomposition::learningRate ( ) const
inline
GNeuralNet& GClasses::GNeuralDecomposition::nn ( ) const
inline
double GClasses::GNeuralDecomposition::outputBias ( ) const
inline
double GClasses::GNeuralDecomposition::outputScale ( ) const
inline
virtual void GClasses::GNeuralDecomposition::predict ( const GVec in,
GVec out 
)
virtual

Evaluate pIn to compute a prediction for pOut. The model must be trained (by calling train) before the first time that this method is called. pIn and pOut should point to arrays of doubles of the same size as the number of columns in the training matrices that were passed to the train method.

Implements GClasses::GSupervisedLearner.

virtual void GClasses::GNeuralDecomposition::predictDistribution ( const GVec in,
GPrediction pOut 
)
virtual

Evaluate pIn and compute a prediction for pOut. pOut is expected to point to an array of GPrediction objects which have already been allocated. There should be labelDims() elements in this array. The distributions will be more accurate if the model is calibrated before the first time that this method is called.

Implements GClasses::GSupervisedLearner.

double GClasses::GNeuralDecomposition::regularization ( ) const
inline
void GClasses::GNeuralDecomposition::restoreFrozen ( )
virtual GDomNode* GClasses::GNeuralDecomposition::serialize ( GDom pDoc) const
virtual

Marshal this object into a DOM that can be converted to a variety of formats. (Implementations of this method should use baseDomNode.)

Implements GClasses::GSupervisedLearner.

void GClasses::GNeuralDecomposition::setAutoFilter ( bool  auto_Filter)
inline
void GClasses::GNeuralDecomposition::setEpochs ( size_t  newepochs)
inline
void GClasses::GNeuralDecomposition::setFeatureBias ( double  newfeatureBias)
inline
void GClasses::GNeuralDecomposition::setFeatureScale ( double  newfeatureScale)
inline
void GClasses::GNeuralDecomposition::setFilterLogarithm ( bool  filter_Logarithm)
inline
void GClasses::GNeuralDecomposition::setLearningRate ( double  newlearningRate)
inline
void GClasses::GNeuralDecomposition::setLinearUnits ( size_t  linearUnits)
inline
void GClasses::GNeuralDecomposition::setLockPairs ( bool  lockPairs)
inline
void GClasses::GNeuralDecomposition::setOutputBias ( double  newoutputBias)
inline
void GClasses::GNeuralDecomposition::setOutputScale ( double  newoutputScale)
inline
void GClasses::GNeuralDecomposition::setRegularization ( double  newregularization)
inline
void GClasses::GNeuralDecomposition::setSigmoidUnits ( size_t  sigmoidUnits)
inline
void GClasses::GNeuralDecomposition::setSinusoidUnits ( size_t  sinusoidUnits)
inline
void GClasses::GNeuralDecomposition::setSoftplusUnits ( size_t  softplusUnits)
inline
static void GClasses::GNeuralDecomposition::test ( )
static
virtual void GClasses::GNeuralDecomposition::trainIncremental ( const GVec in,
const GVec out 
)
virtual

Pass a single input row and the corresponding label to incrementally train this model.

Implements GClasses::GIncrementalLearner.

virtual void GClasses::GNeuralDecomposition::trainInner ( const GMatrix features,
const GMatrix labels 
)
protectedvirtual

This is the implementation of the model's training algorithm. (This method is called by train).

Implements GClasses::GSupervisedLearner.

virtual void GClasses::GNeuralDecomposition::trainOnSeries ( const GMatrix series)
virtual
virtual void GClasses::GNeuralDecomposition::trainSparse ( GSparseMatrix features,
GMatrix labels 
)
virtual

Train using a sparse feature matrix. (A Typical implementation of this method will first call beginIncrementalLearning, then it will iterate over all of the feature rows, and for each row it will convert the sparse row to a dense row, call trainIncremental using the dense row, then discard the dense row and proceed to the next row.)

Implements GClasses::GIncrementalLearner.