prea.recommender.memory
Class ItemBased

java.lang.Object
  extended by prea.recommender.memory.MemoryBasedRecommender
      extended by prea.recommender.memory.ItemBased
All Implemented Interfaces:
Recommender

public class ItemBased
extends MemoryBasedRecommender

The class implementing item-based neighborhood method, predicting by referring to rating matrix for each query.

Since:
2012. 4. 20
Version:
1.1
Author:
Joonseok Lee

Field Summary
 SparseVector itemRateAverage
          Average of ratings for each item.
 java.lang.String itemSimilarityFileName
          The name of pre-calculated item similarity file, if it is used.
 boolean itemSimilarityPrefetch
          Indicating whether the pre-calculated item similarity file is used.
 
Fields inherited from class prea.recommender.memory.MemoryBasedRecommender
defaultValue, defaultVote, INVERSE_USER_FREQUENCY, itemCount, maxValue, MEAN_ABS_DIFF, MEAN_SQUARE_DIFF, minValue, neighborSize, PEARSON_CORR, rateMatrix, similarityMethod, SIMPLE_WEIGHTED_AVG, userCount, VECTOR_COS, WEIGHTED_SUM
 
Constructor Summary
ItemBased(int uc, int ic, int max, int min, int ns, int sim, boolean df, double dv, SparseVector ira, boolean isp, java.lang.String isfn)
          Construct an item-based model with the given data.
 
Method Summary
private  double estimation(int activeIndex, int targetIndex, int[] ref, int refCount, double[] refWeight, int method)
          Estimate a rating based on neighborhood data.
 EvaluationMetrics evaluate(SparseMatrix testMatrix)
          Evaluate the designated algorithm with the given test data.
private  SparseVector predict(int userNo, int[] testItemIndex, int k, SparseMatrix itemSim)
          Predict ratings for a given user regarding given set of items, by user-based CF algorithm.
private  SparseMatrix readItemSimData(int[] validationItemSet)
          Read the pre-calculated item similarity data file.
 
Methods inherited from class prea.recommender.memory.MemoryBasedRecommender
buildModel, similarity
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

itemRateAverage

public SparseVector itemRateAverage
Average of ratings for each item.


itemSimilarityPrefetch

public boolean itemSimilarityPrefetch
Indicating whether the pre-calculated item similarity file is used.


itemSimilarityFileName

public java.lang.String itemSimilarityFileName
The name of pre-calculated item similarity file, if it is used.

Constructor Detail

ItemBased

public ItemBased(int uc,
                 int ic,
                 int max,
                 int min,
                 int ns,
                 int sim,
                 boolean df,
                 double dv,
                 SparseVector ira,
                 boolean isp,
                 java.lang.String isfn)
Construct an item-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.
ns - The neighborhood size.
sim - The method code of similarity measure.
df - Indicator whether to use default values.
dv - Default value if used.
ira - The average of ratings for each item.
isp - Whether the pre-calculated item similarity file is used.
isfn - The name of pre-calculated item similarity file, if it is used.
Method Detail

evaluate

public EvaluationMetrics evaluate(SparseMatrix testMatrix)
Evaluate the designated algorithm with the given test data.

Parameters:
testMatrix - A rating matrix with test data.
Returns:
The result of evaluation, such as MAE, RMSE, and rank-score.

predict

private SparseVector predict(int userNo,
                             int[] testItemIndex,
                             int k,
                             SparseMatrix itemSim)
Predict ratings for a given user regarding given set of items, by user-based CF algorithm.

Parameters:
userNo - The user ID.
testItemIndex - The list of items whose ratings will be predicted.
k - The neighborhood size.
itemSim - The similarity vector between the target user and all the other users.
Returns:
The predicted ratings for each item.

estimation

private double estimation(int activeIndex,
                          int targetIndex,
                          int[] ref,
                          int refCount,
                          double[] refWeight,
                          int method)
Estimate a rating based on neighborhood data.

Parameters:
activeIndex - The active user index for user-based CF; The item index for item-based CF.
targetIndex - The target item index for user-based CF; The user index for item-based CF.
ref - The indices of neighborhood, which will be used for estimation.
refCount - The number of neighborhood, which will be used for estimation.
refWeight - The weight of each neighborhood.
method - The code of estimation method. It should be either WEIGHTED_SUM or SIMPLE_WEIGHTED_AVG.
Returns:
The estimated rating value.

readItemSimData

private SparseMatrix readItemSimData(int[] validationItemSet)
Read the pre-calculated item similarity data file. Make sure that the similarity file is compatible with the split file you are using, for a fair comparison.

Parameters:
validationItemSet - The list of items which will be used for validation.
Returns:
The item similarity matrix.