MLPACK  1.0.8
Public Member Functions | Private Member Functions | Private Attributes | List of all members
mlpack::cf::CF Class Reference

This class implements Collaborative Filtering (CF). More...

Public Member Functions

 CF (const size_t numRecs, const size_t numUsersForSimilarity, arma::mat &data)
 Create a CF object and (optionally) set the parameters with which collaborative filtering will be run. More...
 
 CF (const size_t numRecs, arma::mat &data)
 Create a CF object and (optionally) set the parameters which CF will be run with. More...
 
 CF (arma::mat &data)
 Create a CF object and (optionally) set the parameters which CF will be run with. More...
 
const arma::sp_mat & CleanedData () const
 Get the cleaned data matrix. More...
 
const arma::mat & Data () const
 Get the data matrix. More...
 
void GetRecommendations (arma::Mat< size_t > &recommendations)
 Generates default number of recommendations for all users. More...
 
void GetRecommendations (arma::Mat< size_t > &recommendations, arma::Col< size_t > &users)
 Generates default number of recommendations for specified users. More...
 
void GetRecommendations (arma::Mat< size_t > &recommendations, arma::Col< size_t > &users, size_t num)
 Generates a fixed number of recommendations for specified users. More...
 
void GetRecommendations (arma::Mat< size_t > &recommendations, arma::Col< size_t > &users, size_t num, size_t neighbours)
 Generates a fixed number of recommendations for specified users. More...
 
const arma::mat & H () const
 Get the Item Matrix. More...
 
void NumRecs (size_t recs)
 Sets number of Recommendations. More...
 
size_t NumRecs ()
 Gets numRecs. More...
 
void NumUsersForSimilarity (size_t num)
 Sets number of user for calculating similarity. More...
 
size_t NumUsersForSimilarity ()
 Gets number of users for calculating similarity/. More...
 
const arma::mat & Rating () const
 Get the Rating Matrix. More...
 
const arma::mat & W () const
 Get the User Matrix. More...
 

Private Member Functions

void CleanData ()
 Converts the User, Item, Value Matrix to User-Item Table. More...
 
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. More...
 

Private Attributes

arma::sp_mat cleanedData
 Cleaned data matrix. More...
 
arma::mat data
 Initial data matrix. More...
 
arma::mat h
 Item matrix. More...
 
size_t numRecs
 Number of recommendations. More...
 
size_t numUsersForSimilarity
 Number of users for similarity. More...
 
arma::mat rating
 Rating matrix. More...
 
arma::mat w
 User matrix. More...
 

Detailed Description

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 recommendations; // Recommendations
size_t numRecommendations = 10;
CF<> cf(data); // Default options.
// Generate the default number of recommendations for all users.
cf.GenerateRecommendations(recommendations);
// Generate the default number of recommendations for specified users.
cf.GenerateRecommendations(recommendations, users);
// Generate 10 recommendations for specified users.
cf.GenerateRecommendations(recommendations, users, numRecommendations);

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.

Definition at line 68 of file cf.hpp.

Constructor & Destructor Documentation

mlpack::cf::CF::CF ( const size_t  numRecs,
const size_t  numUsersForSimilarity,
arma::mat &  data 
)

Create a CF object and (optionally) set the parameters with which collaborative filtering will be run.

Parameters
dataInitial (user,item,rating) matrix.
numRecsDesired number of recommendations for each user.
numUsersForSimilaritySize of the neighborhood.
mlpack::cf::CF::CF ( const size_t  numRecs,
arma::mat &  data 
)

Create a CF object and (optionally) set the parameters which CF will be run with.

Parameters
dataInitial User,Item,Rating Matrix
numRecsNumber of Recommendations for each user.
mlpack::cf::CF::CF ( arma::mat &  data)

Create a CF object and (optionally) set the parameters which CF will be run with.

Parameters
dataInitial User,Item,Rating Matrix

Member Function Documentation

void mlpack::cf::CF::CleanData ( )
private

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

const arma::sp_mat& mlpack::cf::CF::CleanedData ( ) const
inline

Get the cleaned data matrix.

Definition at line 144 of file cf.hpp.

References cleanedData.

const arma::mat& mlpack::cf::CF::Data ( ) const
inline

Get the data matrix.

Definition at line 142 of file cf.hpp.

References data.

void mlpack::cf::CF::GetRecommendations ( arma::Mat< size_t > &  recommendations)

Generates default number of recommendations for all users.

Parameters
recommendationsMatrix to save recommendations into.
void mlpack::cf::CF::GetRecommendations ( arma::Mat< size_t > &  recommendations,
arma::Col< size_t > &  users 
)

Generates default number of recommendations for specified users.

Parameters
recommendationsMatrix to save recommendations
usersUsers for which recommendations are to be generated
void mlpack::cf::CF::GetRecommendations ( arma::Mat< size_t > &  recommendations,
arma::Col< size_t > &  users,
size_t  num 
)

Generates a fixed number of recommendations for specified users.

Parameters
recommendationsMatrix to save recommendations
usersUsers for which recommendations are to be generated
numNumber of Recommendations
void mlpack::cf::CF::GetRecommendations ( arma::Mat< size_t > &  recommendations,
arma::Col< size_t > &  users,
size_t  num,
size_t  neighbours 
)

Generates a fixed number of recommendations for specified users.

Parameters
recommendationsMatrix to save recommendations
usersUsers for which recommendations are to be generated
numNumber of Recommendations
neighboursNumber of user to be considered while calculating the neighbourhood
const arma::mat& mlpack::cf::CF::H ( ) const
inline

Get the Item Matrix.

Definition at line 138 of file cf.hpp.

References h.

void mlpack::cf::CF::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
private

Helper function to insert a point into the recommendation matrices.

Parameters
queryIndexIndex of point whose recommendations we are inserting into.
posPosition in list to insert into.
neighborIndex of item being inserted as a recommendation.
valueValue of recommendation.
void mlpack::cf::CF::NumRecs ( size_t  recs)
inline

Sets number of Recommendations.

Definition at line 100 of file cf.hpp.

References mlpack::Log::Warn.

size_t mlpack::cf::CF::NumRecs ( )
inline

Gets numRecs.

Definition at line 112 of file cf.hpp.

References numRecs.

void mlpack::cf::CF::NumUsersForSimilarity ( size_t  num)
inline

Sets number of user for calculating similarity.

Definition at line 118 of file cf.hpp.

References mlpack::Log::Warn.

size_t mlpack::cf::CF::NumUsersForSimilarity ( )
inline

Gets number of users for calculating similarity/.

Definition at line 130 of file cf.hpp.

References numUsersForSimilarity.

const arma::mat& mlpack::cf::CF::Rating ( ) const
inline

Get the Rating Matrix.

Definition at line 140 of file cf.hpp.

References rating.

const arma::mat& mlpack::cf::CF::W ( ) const
inline

Get the User Matrix.

Definition at line 136 of file cf.hpp.

References w.

Member Data Documentation

arma::sp_mat mlpack::cf::CF::cleanedData
private

Cleaned data matrix.

Definition at line 199 of file cf.hpp.

Referenced by CleanedData().

arma::mat mlpack::cf::CF::data
private

Initial data matrix.

Definition at line 197 of file cf.hpp.

Referenced by Data().

arma::mat mlpack::cf::CF::h
private

Item matrix.

Definition at line 193 of file cf.hpp.

Referenced by H().

size_t mlpack::cf::CF::numRecs
private

Number of recommendations.

Definition at line 187 of file cf.hpp.

Referenced by NumRecs().

size_t mlpack::cf::CF::numUsersForSimilarity
private

Number of users for similarity.

Definition at line 189 of file cf.hpp.

Referenced by NumUsersForSimilarity().

arma::mat mlpack::cf::CF::rating
private

Rating matrix.

Definition at line 195 of file cf.hpp.

Referenced by Rating().

arma::mat mlpack::cf::CF::w
private

User matrix.

Definition at line 191 of file cf.hpp.

Referenced by W().


The documentation for this class was generated from the following file: