prea.recommender.memory
Class MemoryBasedRecommender

java.lang.Object
  extended by prea.recommender.memory.MemoryBasedRecommender
All Implemented Interfaces:
Recommender
Direct Known Subclasses:
ItemBased, UserBased

public abstract class MemoryBasedRecommender
extends java.lang.Object
implements Recommender

The class implementing two memory-based (neighborhood-based) methods, predicting by referring to rating matrix for each query. Contains user-based and item-based, with some variations on them.

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

Field Summary
 double defaultValue
          The default voting value, if used.
 boolean defaultVote
          Indicating whether to use default vote value.
static int INVERSE_USER_FREQUENCY
          Similarity Measure Code for Inverse User Frequency
 int itemCount
          The number of items.
 int maxValue
          Maximum value of rating, existing in the dataset.
static int MEAN_ABS_DIFF
          Similarity Measure Code for Mean Absolute Difference (MAD)
static int MEAN_SQUARE_DIFF
          Similarity Measure Code for Mean Squared Difference (MSD)
 int minValue
          Minimum value of rating, existing in the dataset.
 int neighborSize
          The number of neighbors, used for estimation.
static int PEARSON_CORR
          Similarity Measure Code for Pearson Correlation
 SparseMatrix rateMatrix
          Rating matrix for each user (row) and item (column)
 int similarityMethod
          The method code for similarity measure.
static int SIMPLE_WEIGHTED_AVG
          Estimation Method Code for Simple Weighted Average
 int userCount
          The number of users.
static int VECTOR_COS
          Similarity Measure Code for Vector Cosine
static int WEIGHTED_SUM
          Estimation Method Code for Weighted Sum
 
Constructor Summary
MemoryBasedRecommender(int uc, int ic, int max, int min, int ns, int sim, boolean df, double dv)
          Construct a memory-based model with the given data.
 
Method Summary
 void buildModel(SparseMatrix rm)
          Build a model with given training set.
 double similarity(boolean rowOriented, SparseVector i1, SparseVector i2, double i1Avg, double i2Avg, int method)
          Calculate similarity between two given vectors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface prea.recommender.Recommender
evaluate
 

Field Detail

PEARSON_CORR

public static final int PEARSON_CORR
Similarity Measure Code for Pearson Correlation

See Also:
Constant Field Values

VECTOR_COS

public static final int VECTOR_COS
Similarity Measure Code for Vector Cosine

See Also:
Constant Field Values

MEAN_SQUARE_DIFF

public static final int MEAN_SQUARE_DIFF
Similarity Measure Code for Mean Squared Difference (MSD)

See Also:
Constant Field Values

MEAN_ABS_DIFF

public static final int MEAN_ABS_DIFF
Similarity Measure Code for Mean Absolute Difference (MAD)

See Also:
Constant Field Values

INVERSE_USER_FREQUENCY

public static final int INVERSE_USER_FREQUENCY
Similarity Measure Code for Inverse User Frequency

See Also:
Constant Field Values

WEIGHTED_SUM

public static final int WEIGHTED_SUM
Estimation Method Code for Weighted Sum

See Also:
Constant Field Values

SIMPLE_WEIGHTED_AVG

public static final int SIMPLE_WEIGHTED_AVG
Estimation Method Code for Simple Weighted Average

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.


neighborSize

public int neighborSize
The number of neighbors, used for estimation.


similarityMethod

public int similarityMethod
The method code for similarity measure.


defaultVote

public boolean defaultVote
Indicating whether to use default vote value.


defaultValue

public double defaultValue
The default voting value, if used.

Constructor Detail

MemoryBasedRecommender

public MemoryBasedRecommender(int uc,
                              int ic,
                              int max,
                              int min,
                              int ns,
                              int sim,
                              boolean df,
                              double dv)
Construct a memory-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.
Method Detail

buildModel

public void buildModel(SparseMatrix rm)
Build a model with given training set.

Specified by:
buildModel in interface Recommender
Parameters:
rm - Training data set.

similarity

public double similarity(boolean rowOriented,
                         SparseVector i1,
                         SparseVector i2,
                         double i1Avg,
                         double i2Avg,
                         int method)
Calculate similarity between two given vectors.

Parameters:
rowOriented - Use true if user-based, false if item-based.
i1 - The first vector to calculate similarity.
i2 - The second vector to calculate similarity.
i1Avg - The average of elements in the first vector.
i2Avg - The average of elements in the second vector.
method - The code of similarity measure to be used. It can be one of the following: PEARSON_CORR, VECTOR_COS, MEAN_SQUARE_DIFF, MEAN_ABS_DIFF, or INVERSE_USER_FREQUENCY.
Returns:
The similarity value between two vectors i1 and i2.