GClasses
GClasses::GNonlinearPCA Class Reference

This class implements the Unsupervised Backpropagation algorithm, as described in Gashler, Michael S. and Smith, Michael R. and Morris, Richard and Martinez, Tony. Missing Value Imputation With Unsupervised Backpropagation. Computational Intelligence, Wiley Online Library. 2014. This algorithm is very similar to an earlier algorithm called NonlinearPCA, except with the addition of a three-pass training approach that yields better accuracy. If you call noThreePass() before you call train(), then this class implements NonlinearPCA, as published in Scholz, M. Kaplan, F. Guy, C. L. Kopka, J. Selbig, J., Non-linear PCA: a missing data approach, In Bioinformatics, Vol. 21, Number 20, pp. 3887-3895, Oxford University Press, 2005. More...

#include <GRecommender.h>

Inheritance diagram for GClasses::GNonlinearPCA:
GClasses::GCollaborativeFilter GClasses::GHybridNonlinearPCA

Public Member Functions

 GNonlinearPCA (size_t intrinsicDims)
 General-purpose constructor. More...
 
 GNonlinearPCA (GDomNode *pNode, GLearnerLoader &ll)
 Deserialization constructor. More...
 
virtual ~GNonlinearPCA ()
 Destructor. More...
 
void clampItemElement (size_t item, size_t attr, double val)
 Specify that a certain attribute of a certain item profile has a fixed value. (Values for attr are from 0 to m_pModel->outputLayer().inputs()-1. No mechanism is provided to clamp the item bias.) More...
 
void clampItems (const GMatrix &data, size_t offset=0)
 Assumes that column 0 of data is an item ID, and all other columns specify profile values to clamp beginning at the specifed profile offset. More...
 
void clampUserElement (size_t user, size_t attr, double val)
 Specify that a certain attribute of a certain user profile has a fixed value. (Values for attr are from 0 to m_intrinsicDims-2. No mechanism is provided to clamp the input bias.) More...
 
void clampUsers (const GMatrix &data, size_t offset=0)
 Assumes that column 0 of data is a user ID, and all other columns specify profile values to clamp beginning at the specifed profile offset. More...
 
virtual void impute (double *pVec, size_t dims)
 See the comment for GCollaborativeFilter::impute. More...
 
GNeuralNetmodel ()
 Returns a pointer to the neural net that is used to model the recommendation space. You may want to use this method to add layers to the network. (At least one layer is necessary). You may also use it to set the learning rate, or change activation functions before the model is trained. More...
 
void noInputBias ()
 Specify to use no bias value with the inputs. More...
 
void noThreePass ()
 Specify not to use three-pass training. (It will just use one pass instead.) More...
 
virtual double predict (size_t user, size_t item)
 See the comment for GCollaborativeFilter::predict. More...
 
virtual GDomNodeserialize (GDom *pDoc) const
 See the comment for GCollaborativeFilter::serialize. More...
 
void setDecayRate (double d)
 Set the rate to decay the learning rate. More...
 
void setMinIters (size_t i)
 Sset the min number of iterations to train. More...
 
void setRegularizer (double d)
 Set the regularization value. More...
 
virtual void train (GMatrix &data)
 See the comment for GCollaborativeFilter::train. More...
 
GMatrixusers ()
 Returns a pointer to the matrix of user preference vectors. More...
 
- Public Member Functions inherited from GClasses::GCollaborativeFilter
 GCollaborativeFilter ()
 
 GCollaborativeFilter (GDomNode *pNode, GLearnerLoader &ll)
 
virtual ~GCollaborativeFilter ()
 
void basicTest (double minMSE)
 Performs a basic unit test on this collaborative filter. More...
 
double crossValidate (GMatrix &data, size_t folds, double *pOutMAE=NULL)
 This randomly assigns each rating to one of the folds. Then, for each fold, it calls train with a dataset that contains everything except for the ratings in that fold. It predicts values for the items in the fold, and returns the mean-squared difference between the predictions and the actual ratings. If pOutMAE is non-NULL, it will be set to the mean-absolute error. More...
 
GMatrixprecisionRecall (GMatrix &data, bool ideal=false)
 This divides the data into two equal-size parts. It trains on one part, and then measures the precision/recall using the other part. It returns a three-column data set with recall scores in column 0 and corresponding precision scores in column 1. The false-positive rate is in column 2. (So, if you want a precision-recall plot, just drop column 2. If you want an ROC curve, drop column 1 and swap the remaining two columns.) This method assumes the ratings range from 0 to 1, so be sure to scale the ratings to fit that range before calling this method. If ideal is true, then it will ignore your model and report the ideal results as if your model always predicted the correct rating. (This is useful because it shows the best possible results.) More...
 
GRandrand ()
 Returns a reference to the pseudo-random number generator associated with this object. More...
 
double trainAndTest (GMatrix &train, GMatrix &test, double *pOutMAE=NULL)
 This trains on the training set, and then tests on the test set. Returns the mean-squared difference between actual and target predictions. More...
 
void trainDenseMatrix (const GMatrix &data, const GMatrix *pLabels=NULL)
 Train from an m-by-n dense matrix, where m is the number of users and n is the number of items. All attributes must be continuous. Missing values are indicated with UNKNOWN_REAL_VALUE. If pLabels is non-NULL, then the labels will be appended as additional items. More...
 

Static Public Member Functions

static void test ()
 Performs unit tests. Throws if a failure occurs. Returns if successful. More...
 
- Static Public Member Functions inherited from GClasses::GCollaborativeFilter
static double areaUnderCurve (GMatrix &data)
 Pass in the data returned by the precisionRecall function (unmodified), and this will compute the area under the ROC curve. More...
 

Protected Member Functions

void clampItemsInternal (size_t i)
 
void clampUsersInternal (size_t i)
 
double validate (GNeuralNet *pNN, GMatrix &data)
 Returns the sum-squared error for the specified set of ratings. More...
 
- Protected Member Functions inherited from GClasses::GCollaborativeFilter
GDomNodebaseDomNode (GDom *pDoc, const char *szClassName) const
 Child classes should use this in their implementation of serialize. More...
 

Protected Attributes

double m_decayRate
 
size_t m_intrinsicDims
 
size_t m_items
 
size_t m_minIters
 
GMatrixm_pItemMask
 
double * m_pMaxs
 
double * m_pMins
 
GNeuralNetm_pModel
 
GMatrixm_pUserMask
 
GMatrixm_pUsers
 
double m_regularizer
 
bool m_useInputBias
 
bool m_useThreePass
 
- Protected Attributes inherited from GClasses::GCollaborativeFilter
GRand m_rand
 

Detailed Description

This class implements the Unsupervised Backpropagation algorithm, as described in Gashler, Michael S. and Smith, Michael R. and Morris, Richard and Martinez, Tony. Missing Value Imputation With Unsupervised Backpropagation. Computational Intelligence, Wiley Online Library. 2014. This algorithm is very similar to an earlier algorithm called NonlinearPCA, except with the addition of a three-pass training approach that yields better accuracy. If you call noThreePass() before you call train(), then this class implements NonlinearPCA, as published in Scholz, M. Kaplan, F. Guy, C. L. Kopka, J. Selbig, J., Non-linear PCA: a missing data approach, In Bioinformatics, Vol. 21, Number 20, pp. 3887-3895, Oxford University Press, 2005.

Constructor & Destructor Documentation

GClasses::GNonlinearPCA::GNonlinearPCA ( size_t  intrinsicDims)

General-purpose constructor.

GClasses::GNonlinearPCA::GNonlinearPCA ( GDomNode pNode,
GLearnerLoader ll 
)

Deserialization constructor.

virtual GClasses::GNonlinearPCA::~GNonlinearPCA ( )
virtual

Destructor.

Member Function Documentation

void GClasses::GNonlinearPCA::clampItemElement ( size_t  item,
size_t  attr,
double  val 
)

Specify that a certain attribute of a certain item profile has a fixed value. (Values for attr are from 0 to m_pModel->outputLayer().inputs()-1. No mechanism is provided to clamp the item bias.)

void GClasses::GNonlinearPCA::clampItems ( const GMatrix data,
size_t  offset = 0 
)

Assumes that column 0 of data is an item ID, and all other columns specify profile values to clamp beginning at the specifed profile offset.

void GClasses::GNonlinearPCA::clampItemsInternal ( size_t  i)
protected
void GClasses::GNonlinearPCA::clampUserElement ( size_t  user,
size_t  attr,
double  val 
)

Specify that a certain attribute of a certain user profile has a fixed value. (Values for attr are from 0 to m_intrinsicDims-2. No mechanism is provided to clamp the input bias.)

void GClasses::GNonlinearPCA::clampUsers ( const GMatrix data,
size_t  offset = 0 
)

Assumes that column 0 of data is a user ID, and all other columns specify profile values to clamp beginning at the specifed profile offset.

void GClasses::GNonlinearPCA::clampUsersInternal ( size_t  i)
protected
virtual void GClasses::GNonlinearPCA::impute ( double *  pVec,
size_t  dims 
)
virtual
GNeuralNet* GClasses::GNonlinearPCA::model ( )
inline

Returns a pointer to the neural net that is used to model the recommendation space. You may want to use this method to add layers to the network. (At least one layer is necessary). You may also use it to set the learning rate, or change activation functions before the model is trained.

void GClasses::GNonlinearPCA::noInputBias ( )
inline

Specify to use no bias value with the inputs.

void GClasses::GNonlinearPCA::noThreePass ( )
inline

Specify not to use three-pass training. (It will just use one pass instead.)

virtual double GClasses::GNonlinearPCA::predict ( size_t  user,
size_t  item 
)
virtual
virtual GDomNode* GClasses::GNonlinearPCA::serialize ( GDom pDoc) const
virtual
void GClasses::GNonlinearPCA::setDecayRate ( double  d)
inline

Set the rate to decay the learning rate.

void GClasses::GNonlinearPCA::setMinIters ( size_t  i)
inline

Sset the min number of iterations to train.

void GClasses::GNonlinearPCA::setRegularizer ( double  d)
inline

Set the regularization value.

static void GClasses::GNonlinearPCA::test ( )
static

Performs unit tests. Throws if a failure occurs. Returns if successful.

virtual void GClasses::GNonlinearPCA::train ( GMatrix data)
virtual
GMatrix* GClasses::GNonlinearPCA::users ( )
inline

Returns a pointer to the matrix of user preference vectors.

double GClasses::GNonlinearPCA::validate ( GNeuralNet pNN,
GMatrix data 
)
protected

Returns the sum-squared error for the specified set of ratings.

Member Data Documentation

double GClasses::GNonlinearPCA::m_decayRate
protected
size_t GClasses::GNonlinearPCA::m_intrinsicDims
protected
size_t GClasses::GNonlinearPCA::m_items
protected
size_t GClasses::GNonlinearPCA::m_minIters
protected
GMatrix* GClasses::GNonlinearPCA::m_pItemMask
protected
double* GClasses::GNonlinearPCA::m_pMaxs
protected
double* GClasses::GNonlinearPCA::m_pMins
protected
GNeuralNet* GClasses::GNonlinearPCA::m_pModel
protected
GMatrix* GClasses::GNonlinearPCA::m_pUserMask
protected
GMatrix* GClasses::GNonlinearPCA::m_pUsers
protected
double GClasses::GNonlinearPCA::m_regularizer
protected
bool GClasses::GNonlinearPCA::m_useInputBias
protected
bool GClasses::GNonlinearPCA::m_useThreePass
protected