mlpack::cf::CF Class Reference

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

List of all members.

Public Member Functions

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

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:
data Initial (user,item,rating) matrix.
numRecs Desired number of recommendations for each user.
numUsersForSimilarity Size 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:
data Initial User,Item,Rating Matrix
numRecs Number 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:
data Initial 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.

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:
recommendations Matrix to save recommendations
users Users for which recommendations are to be generated
num Number of Recommendations
neighbours Number of user to be considered while calculating the neighbourhood
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:
recommendations Matrix to save recommendations
users Users for which recommendations are to be generated
num Number of Recommendations
void mlpack::cf::CF::GetRecommendations ( arma::Mat< size_t > &  recommendations,
arma::Col< size_t > &  users 
)

Generates default number of recommendations for specified users.

Parameters:
recommendations Matrix to save recommendations
users Users for which recommendations are to be generated
void mlpack::cf::CF::GetRecommendations ( arma::Mat< size_t > &  recommendations  ) 

Generates default number of recommendations for all users.

Parameters:
recommendations Matrix to save recommendations into.
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:
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.
size_t mlpack::cf::CF::NumRecs (  )  [inline]

Gets numRecs.

Definition at line 112 of file cf.hpp.

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::NumUsersForSimilarity (  )  [inline]

Gets number of users for calculating similarity/.

Definition at line 130 of file cf.hpp.

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.

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.

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.

Number of users for similarity.

Definition at line 189 of file cf.hpp.

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:

Generated on 29 Sep 2016 for MLPACK by  doxygen 1.6.1