Recommender

Similarity

The similarity matrix is used to construct the distance between user and user or item and item in the data set.
The example is shown as follows.

rec.similarity.class=cos
rec.recommender.similarities=user

rec.similarity.class is the distance measure function. rec.recommender.similarities is the distance of a specified user-user pair or a item-item pair. For the Social recommendation algorithms, users can also specify the distance of a social-social pair.

In the Java program, the corresponding sample program is shown as follows.

After generating the RecommenderSimilarity object, users need to call the buildSimilarityMatrix method to build the similarity matrix.

The table below is the distance measure functions and corresponding abbreviations in LibRec.

Similarity

shortname

BinaryCosineSimilarity

bcos

CosineSimilarity

cos

CPCSimilarity

cpc

MSESimilarity

msesim

MSDSimilarity

msd

PCCSimilarity

pcc

KRCCSimilarity

krcc

DiceCoefficientSimilarity

dice

JaccardSimilarity

jaccard

ExJaccardSimilarity

exjaccard

Algorithms

When users use the configuration and command line to run programs, the recommendation algorithm is specified by rec.recommender.class. The configuration is shown as follows.

rec.recommender.class=shortname #e.g. aobpr

Please refer to [Algorithm list.md](./Algorithm list) for the abbreviations of different algorithms.

In the Java implementation, after making instances of the Configuration object, the DataModel object, and the Similarity matrix object, these three instances are passed in as constructor parameters to generate the RecommenderContext object. Users can make the corresponding instance of the recommendation algorithm, that is to say, no need to set the rec.recommedner.class configuration. The example code is shown as follows.

Each recommendation algorithm has its own configurations according to different algorithm categories. Current recommendation algorithms implemented in LibRec are matrix-decomposition-based, factor-factorization-based, probability-graph-model-based, and tensor-based. The following part gives different configurations based on different algorithms. In general, taking the matrix factorization for example, making recommendations by inheriting the interface of matrix factorization algorithms not only needs to set the configuration of matrix factorization, but also needs to set other configurations. For example, the BPMF also needs to configure rec.recommender.user.mu and other configurations.

The implementation of the recommendation algorithms based on the above algorithms, which only needs to inherit the corresponding abstract classes. Different algorithms are listed in the following table. All the recommendation algorithm configurations are listed in Algorithm List.

TensorRecommender

The algorithms that directly inherit the Tensor Recommender class are shown as follows.

directory path

short name

algorithm

content

convmf

ConvMFRecommender

content

efm

EFMRecommender

content

hft

HFTRecommender

content

tfidf

TFIDFRecommender

content

topicmfat

TopicMFATRecommender

content

topicmfmt

TopicMFMTRecommender

context.rating

cptf

CPTFRecommender

Implement your own algorithm

Implementing users' own algorithms in LibRec needs to inherit the corresponding abstract class according to the algorithm's category. And users need to implement the abstract methods, or re-write the methods in the abstract class.
In order to inherit the AbstractRecommender class, for example, the implementation of an algorithm is shown as follows.

1. Re-write the setup method (optional)
The main task of the setup method is to initialize the member variables. For example, reading arguments from the configuration file. If the algorithm does not need to set extra configurations, the program does not need to re-write the methods.
It should be noted that, in the rewrite of the setup method, users need to call the original abstract class in the setup method. That is, to put super.setup() in the first line of the implementation, to ensure that the basic parameters of the algorithm is initialized.
2. Implement the trainModel Method
The trainModel method accomplish the task of training the model. For example, using gradient descent to optimize the cost function of the model.
3. Implement the Predict Method
The task of the Predict method is to use the trained model to make predictions.
For example, for rating prediction algorithms, the predict method is used to predict each rating in the test set. Particularly, for a given userIndex and itemIndex, using the model to predict the rating score of userIndex-itemIndex pair.

Please refer to the exact implementation in the recommender directory.