SYNOPSIS

Public Member Functions

CF (arma::mat &data, const size_t numUsersForSimilarity=5, const size_t rank=0)

Initialize the CF object. const arma::sp_mat & CleanedData () const

Get the cleaned data matrix. const arma::mat & Data () const

Get the data matrix. void Factorizer (const FactorizerType &f)

Sets factorizer for NMF. void GetRecommendations (const size_t numRecs, arma::Mat< size_t > &recommendations)

Generates the given number of recommendations for all users. void GetRecommendations (const size_t numRecs, arma::Mat< size_t > &recommendations, arma::Col< size_t > &users)

Generates the given number of recommendations for the specified users. const arma::mat & H () const

Get the Item Matrix. void NumUsersForSimilarity (const size_t num)

Sets number of users for calculating similarity. size_t NumUsersForSimilarity () const

Gets number of users for calculating similarity. void Rank (const size_t rankValue)

Sets rank parameter for matrix factorization. size_t Rank () const

Gets rank parameter for matrix factorization. const arma::mat & Rating () const

Get the Rating Matrix. std::string ToString () const

Returns a string representation of this object. const arma::mat & W () const

Get the User Matrix.

Private Member Functions

void CleanData ()

Converts the User, Item, Value Matrix to User-Item Table. void InsertNeighbor (const size_t queryIndex, const size_t pos, const size_t neighbor, const double value, arma::Mat< size_t > &recommendations, arma::mat &values) const

Helper function to insert a point into the recommendation matrices.

Private Attributes

arma::sp_mat cleanedData

Cleaned data matrix. arma::mat data

Initial data matrix. FactorizerType factorizer

Instantiated factorizer object. arma::mat h

Item matrix. size_t numUsersForSimilarity

Number of users for similarity. size_t rank

Rank used for matrix factorization. arma::mat rating

Rating matrix. arma::mat w

User matrix.

Detailed Description

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>>class mlpack::cf::CF< FactorizerType >

This class implements Collaborative Filtering (CF).

This implementation presently supports Alternating Least Squares (ALS) for collaborative filtering.

A simple example of how to run Collaborative Filtering is shown below.

extern arma::mat data; // (user, item, rating) table
extern arma::Col<size_t> users; // users seeking recommendations
arma::Mat<size_t> recommendations; // Recommendations

CF<> cf(data); // Default options.

// Generate 10 recommendations for all users.
cf.GetRecommendations(10, recommendations);

// Generate 10 recommendations for specified users.
cf.GetRecommendations(10, recommendations, users);

The data matrix is a (user, item, rating) table. Each column in the matrix should have three rows. The first represents the user; the second represents the item; and the third represents the rating. The user and item, while they are in a matrix that holds doubles, should hold integer (or size_t) values. The user and item indices are assumed to start at 0.

Template Parameters:

FactorizerType The type of matrix factorization to use to decompose the rating matrix (a W and H matrix). This must implement the method Apply(arma::sp_mat& data, size_t rank, arma::mat& W, arma::mat& H).

Definition at line 76 of file cf.hpp.

Constructor & Destructor Documentation

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> \fBmlpack::cf::CF\fP< FactorizerType >::\fBCF\fP (arma::mat &data, const size_tnumUsersForSimilarity = \fC5\fP, const size_trank = \fC0\fP)

Initialize the CF object. Store a reference to the data that we will be using. There are parameters that can be set; default values are provided for each of them. If the rank is left unset (or is set to 0), a simple density-based heuristic will be used to choose a rank.

Parameters:

data Initial (user, item, rating) matrix.

numUsersForSimilarity Size of the neighborhood.

rank Rank parameter for matrix factorization.

Member Function Documentation

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> void \fBmlpack::cf::CF\fP< FactorizerType >::CleanData ()\fC [private]\fP

Converts the User, Item, Value Matrix to User-Item Table.

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> const arma::sp_mat& \fBmlpack::cf::CF\fP< FactorizerType >::CleanedData () const\fC [inline]\fP

Get the cleaned data matrix.

Definition at line 138 of file cf.hpp.

References mlpack::cf::CF< FactorizerType >::cleanedData.

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> const arma::mat& \fBmlpack::cf::CF\fP< FactorizerType >::Data () const\fC [inline]\fP

Get the data matrix.

Definition at line 136 of file cf.hpp.

References mlpack::cf::CF< FactorizerType >::data.

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> void \fBmlpack::cf::CF\fP< FactorizerType >::Factorizer (const FactorizerType &f)\fC [inline]\fP

Sets factorizer for NMF.

Definition at line 124 of file cf.hpp.

References mlpack::cf::CF< FactorizerType >::factorizer.

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> void \fBmlpack::cf::CF\fP< FactorizerType >::GetRecommendations (const size_tnumRecs, arma::Mat< size_t > &recommendations)

Generates the given number of recommendations for all users.

Parameters:

numRecs Number of Recommendations

recommendations Matrix to save recommendations into.

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> void \fBmlpack::cf::CF\fP< FactorizerType >::GetRecommendations (const size_tnumRecs, arma::Mat< size_t > &recommendations, arma::Col< size_t > &users)

Generates the given number of recommendations for the specified users.

Parameters:

numRecs Number of Recommendations

recommendations Matrix to save recommendations

users Users for which recommendations are to be generated

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> const arma::mat& \fBmlpack::cf::CF\fP< FactorizerType >::H () const\fC [inline]\fP

Get the Item Matrix.

Definition at line 132 of file cf.hpp.

References mlpack::cf::CF< FactorizerType >::h.

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> void \fBmlpack::cf::CF\fP< FactorizerType >::InsertNeighbor (const size_tqueryIndex, const size_tpos, const size_tneighbor, const doublevalue, arma::Mat< size_t > &recommendations, arma::mat &values) const\fC [private]\fP

Helper function to insert a point into the recommendation matrices.

Parameters:

queryIndex Index of point whose recommendations we are inserting into.

pos Position in list to insert into.

neighbor Index of item being inserted as a recommendation.

value Value of recommendation.

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> void \fBmlpack::cf::CF\fP< FactorizerType >::NumUsersForSimilarity (const size_tnum)\fC [inline]\fP

Sets number of users for calculating similarity.

Definition at line 94 of file cf.hpp.

References mlpack::cf::CF< FactorizerType >::numUsersForSimilarity, and mlpack::Log::Warn.

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> size_t \fBmlpack::cf::CF\fP< FactorizerType >::NumUsersForSimilarity () const\fC [inline]\fP

Gets number of users for calculating similarity.

Definition at line 106 of file cf.hpp.

References mlpack::cf::CF< FactorizerType >::numUsersForSimilarity.

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> void \fBmlpack::cf::CF\fP< FactorizerType >::Rank (const size_trankValue)\fC [inline]\fP

Sets rank parameter for matrix factorization.

Definition at line 112 of file cf.hpp.

References mlpack::cf::CF< FactorizerType >::rank.

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> size_t \fBmlpack::cf::CF\fP< FactorizerType >::Rank () const\fC [inline]\fP

Gets rank parameter for matrix factorization.

Definition at line 118 of file cf.hpp.

References mlpack::cf::CF< FactorizerType >::rank.

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> const arma::mat& \fBmlpack::cf::CF\fP< FactorizerType >::Rating () const\fC [inline]\fP

Get the Rating Matrix.

Definition at line 134 of file cf.hpp.

References mlpack::cf::CF< FactorizerType >::rating.

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> std::string \fBmlpack::cf::CF\fP< FactorizerType >::ToString () const

Returns a string representation of this object.

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> const arma::mat& \fBmlpack::cf::CF\fP< FactorizerType >::W () const\fC [inline]\fP

Get the User Matrix.

Definition at line 130 of file cf.hpp.

References mlpack::cf::CF< FactorizerType >::w.

Member Data Documentation

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> arma::sp_mat \fBmlpack::cf::CF\fP< FactorizerType >::cleanedData\fC [private]\fP

Cleaned data matrix.

Definition at line 181 of file cf.hpp.

Referenced by mlpack::cf::CF< FactorizerType >::CleanedData().

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> arma::mat \fBmlpack::cf::CF\fP< FactorizerType >::data\fC [private]\fP

Initial data matrix.

Definition at line 167 of file cf.hpp.

Referenced by mlpack::cf::CF< FactorizerType >::Data().

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> FactorizerType \fBmlpack::cf::CF\fP< FactorizerType >::factorizer\fC [private]\fP

Instantiated factorizer object.

Definition at line 173 of file cf.hpp.

Referenced by mlpack::cf::CF< FactorizerType >::Factorizer().

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> arma::mat \fBmlpack::cf::CF\fP< FactorizerType >::h\fC [private]\fP

Item matrix.

Definition at line 177 of file cf.hpp.

Referenced by mlpack::cf::CF< FactorizerType >::H().

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> size_t \fBmlpack::cf::CF\fP< FactorizerType >::numUsersForSimilarity\fC [private]\fP

Number of users for similarity.

Definition at line 169 of file cf.hpp.

Referenced by mlpack::cf::CF< FactorizerType >::NumUsersForSimilarity().

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> size_t \fBmlpack::cf::CF\fP< FactorizerType >::rank\fC [private]\fP

Rank used for matrix factorization.

Definition at line 171 of file cf.hpp.

Referenced by mlpack::cf::CF< FactorizerType >::Rank().

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> arma::mat \fBmlpack::cf::CF\fP< FactorizerType >::rating\fC [private]\fP

Rating matrix.

Definition at line 179 of file cf.hpp.

Referenced by mlpack::cf::CF< FactorizerType >::Rating().

template<typename FactorizerType = amf::AMF<amf::SimpleResidueTermination, amf::RandomInitialization, amf::NMFALSUpdate>> arma::mat \fBmlpack::cf::CF\fP< FactorizerType >::w\fC [private]\fP

User matrix.

Definition at line 175 of file cf.hpp.

Referenced by mlpack::cf::CF< FactorizerType >::W().

Author

Generated automatically by Doxygen for MLPACK from the source code.