prea.recommender.etc
Class RankBased

java.lang.Object
  extended by prea.recommender.etc.RankBased
All Implemented Interfaces:
Recommender

public class RankBased
extends java.lang.Object
implements Recommender

This is a class implementing rank-based collaborative filtering. Technical detail of the algorithm can be found in M. Sun and G. Lebanon and P. Kidwell, Estimating Probabilities in Recommendation Systems, Proceedings of the fourteenth international conference on Artificial Intelligence and Statistics, 2011.

Since:
2012. 4. 20
Version:
1.1
Author:
Mingxuan Sun

Field Summary
static int ASYMM_LOSS
          Asymmetric loss function
 int itemCount
          The number of items.
 double kernelWidth
          Kernel bandwidth.
private  int lossType
          The type of loss function.
 int maxValue
          Maximum value of rating, existing in the dataset.
static int MEAN_LOSS
          Mean loss function
 int minValue
          Minimum value of rating, existing in the dataset.
 int[][] numTieCount
          The number of tie structure for each user with size m testing users by l raing levels.
 int[][] prbMatricesIndTrain
          Parsed index for each user, 2d array with m testing users by the number of rated items.
 double[][][] prbMatricesVal
          Parsed prb for each user, 3d array with l rating levels by m testing users by the number of rated items.
 SparseMatrix[] predictedArray
          The probability array of each rating for testing items and users.
 SparseMatrix rateMatrix
          Rating matrix for each user (row) and item (column)
 int userCount
          The number of users.
 
Constructor Summary
RankBased(int uc, int ic, double max, double min, double kw, int lt)
          Construct a rank-based model with the given data.
 
Method Summary
 void buildModel(SparseMatrix rm)
          Predict the probabilities using the rank-based algorithm with the given test data.
private  void constructProbability()
          Construct the probability (average rank) structure for each user's ranking.
private  void constructTie()
          Construct the tie structure for each user's ranking.
private  void distanceOneToAllTest(int userId, int testId, SparseVector[] dist, int k, int[] indexK)
          Compute the distance between the testing user with the testing item of every possible ratings and all the other training users with training items.
private  void distanceOneToAllTrain(int userId, double[] dist, int k, int[] indexK)
          Compute the distance between the testing user and all the other training users with training items.
 EvaluationMetrics evaluate(SparseMatrix testMatrix)
          Evaluate the rank-based CF algorithm with the given probabilites and loss function.
private  void getEstimation(SparseMatrix testMatrix)
          Estimate ratings for (user, item) pairs in test data matrix.
private  double predict(int userId, int itemId)
          Compute the rating for a given user and a test item, which minimizes the given loss.
private  void rankBasedPerUser(int userId, int testItemId, double ker, int k, int[] index, double[] distL0, SparseVector[] distL, SparseMatrix[] predictedArray)
          Predict ratings for a given user and a given test item, by rank-based CF algorithm.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MEAN_LOSS

public static final int MEAN_LOSS
Mean loss function

See Also:
Constant Field Values

ASYMM_LOSS

public static final int ASYMM_LOSS
Asymmetric loss function

See Also:
Constant Field Values

rateMatrix

public SparseMatrix rateMatrix
Rating matrix for each user (row) and item (column)


userCount

public int userCount
The number of users.


itemCount

public int itemCount
The number of items.


maxValue

public int maxValue
Maximum value of rating, existing in the dataset.


minValue

public int minValue
Minimum value of rating, existing in the dataset.


kernelWidth

public double kernelWidth
Kernel bandwidth.


prbMatricesVal

public double[][][] prbMatricesVal
Parsed prb for each user, 3d array with l rating levels by m testing users by the number of rated items.


prbMatricesIndTrain

public int[][] prbMatricesIndTrain
Parsed index for each user, 2d array with m testing users by the number of rated items.


numTieCount

public int[][] numTieCount
The number of tie structure for each user with size m testing users by l raing levels.


predictedArray

public SparseMatrix[] predictedArray
The probability array of each rating for testing items and users.


lossType

private int lossType
The type of loss function.

Constructor Detail

RankBased

public RankBased(int uc,
                 int ic,
                 double max,
                 double min,
                 double kw,
                 int lt)
Construct a rank-based model with the given data.

Parameters:
uc - The number of users in the dataset.
ic - The number of items in the dataset.
max - The maximum rating value in the dataset.
min - The minimum rating value in the dataset.
kw - The kernel width for density estimation
lt - Loss function used for prediction. It should be either MEAN_LOSS or ASYMM_LOSS.
Method Detail

buildModel

public void buildModel(SparseMatrix rm)
Predict the probabilities using the rank-based algorithm with the given test data. The probability of each test item for each user will be filled in predictedArray.

Specified by:
buildModel in interface Recommender
Parameters:
rm - The rating matrix with train data.

constructProbability

private void constructProbability()
Construct the probability (average rank) structure for each user's ranking.


constructTie

private void constructTie()
Construct the tie structure for each user's ranking.


distanceOneToAllTrain

private void distanceOneToAllTrain(int userId,
                                   double[] dist,
                                   int k,
                                   int[] indexK)
Compute the distance between the testing user and all the other training users with training items.

Parameters:
userId - The user ID.
dist - The distance which will be computed.
k - The neighborhood size.
indexK - The index of nearest neighbor which will be computed.

distanceOneToAllTest

private void distanceOneToAllTest(int userId,
                                  int testId,
                                  SparseVector[] dist,
                                  int k,
                                  int[] indexK)
Compute the distance between the testing user with the testing item of every possible ratings and all the other training users with training items.

Parameters:
userId - The user ID.
testId - The testing item ID.
dist - The distance which will be computed.
k - The neighborhood size.
indexK - The index of nearest neighbor.

rankBasedPerUser

private void rankBasedPerUser(int userId,
                              int testItemId,
                              double ker,
                              int k,
                              int[] index,
                              double[] distL0,
                              SparseVector[] distL,
                              SparseMatrix[] predictedArray)
Predict ratings for a given user and a given test item, by rank-based CF algorithm.

Parameters:
userId - The user ID.
testItemId - The id of item whose ratings will be predicted.
ker - The kernelwidth.
k - The number of nearest training users.
index - The index of near k users.
distL0 - The distance between the test user and all the other k training users.
distL - The distance between the test user with testing item of each possible ratings and all the other k training users.
predictedArray - The array will be filled in with the probabilities of each rating for the user u and the item.

evaluate

public EvaluationMetrics evaluate(SparseMatrix testMatrix)
Evaluate the rank-based CF algorithm with the given probabilites and loss function.

Specified by:
evaluate in interface Recommender
Parameters:
testMatrix - The rating matrix with test data.
Returns:
The result of evaluation, such as MAE, RMSE, and rank-score.

getEstimation

private void getEstimation(SparseMatrix testMatrix)
Estimate ratings for (user, item) pairs in test data matrix.

Parameters:
testMatrix - The rating matrix with test data.

predict

private double predict(int userId,
                       int itemId)
Compute the rating for a given user and a test item, which minimizes the given loss.

Parameters:
userId - The target user.
itemId - The target test item.
Returns:
The predicted rating.