org.mymedialite.ratingprediction
Class BiasedMatrixFactorization

java.lang.Object
  extended by org.mymedialite.ratingprediction.RatingPredictor
      extended by org.mymedialite.ratingprediction.IncrementalRatingPredictor
          extended by org.mymedialite.ratingprediction.MatrixFactorization
              extended by org.mymedialite.ratingprediction.BiasedMatrixFactorization
All Implemented Interfaces:
java.lang.Cloneable, IIterativeModel, IRecommender, IIncrementalRatingPredictor, IRatingPredictor
Direct Known Subclasses:
LogisticRegressionMatrixFactorization, SocialMF

public class BiasedMatrixFactorization
extends MatrixFactorization

Matrix factorization engine with explicit user and item bias. Per default optimizes for RMSE. Set OptimizeMAE to true if you want to optimize for MAE. Literature: Ruslan Salakhutdinov, Andriy Mnih: Probabilistic Matrix Factorization. NIPS 2007. http://www.mit.edu/~rsalakhu/papers/nips07_pmf.pdf Steffen Rendle, Lars Schmidt-Thieme: Online-Updating Regularized Kernel Matrix Factorization Models for Large-Scale Recommender Systems. RecSys 2008. http://www.ismll.uni-hildesheim.de/pub/pdfs/Rendle2008-Online_Updating_Regularized_Kernel_Matrix_Factorization_Models.pdf This recommender supports incremental updates.


Field Summary
 double biasReg
          Regularization constant for the bias terms.
 boolean boldDriver
          Use bold driver heuristics for learning rate adaption.
protected  double[] itemBias
          The item biases
protected  double last_loss
          Loss for the last iteration, used by bold driver heuristics
 boolean optimizeMAE
          If set to true, optimize model for MAE instead of RMSE.
 double regI
          Regularization constant for the item factors.
 double regU
          Regularization constant for the user factors.
protected  double[] userBias
          The user biases
 
Fields inherited from class org.mymedialite.ratingprediction.MatrixFactorization
globalBias, initMean, initStDev, itemFactors, learnRate, numFactors, numIter, regularization, userFactors
 
Fields inherited from class org.mymedialite.ratingprediction.IncrementalRatingPredictor
updateItems, updateUsers
 
Fields inherited from class org.mymedialite.ratingprediction.RatingPredictor
maxItemID, maxRating, maxUserID, minRating, ratings
 
Constructor Summary
BiasedMatrixFactorization()
          Default constructor
 
Method Summary
 void addItem(int item_id)
          
 void addUser(int user_id)
          
protected  void initModel()
          Initialize the model data structure.
 void iterate()
          Run one iteration (= pass over the training data)
protected  void iterate(java.util.List<java.lang.Integer> rating_indices, boolean update_user, boolean update_item)
          Iterate once over rating data and adjust corresponding factors (stochastic gradient descent).
protected  void iterateRMSE(java.util.List<java.lang.Integer> rating_indices, boolean update_user, boolean update_item)
           
 void loadModel(java.lang.String filename)
          Get the model parameters from a file
 double predict(int user_id, int item_id)
          Predict the rating of a given user for a given item.
 void removeItem(int item_id)
          Remove an item from the recommender model, and delete all ratings of this item It is up to the recommender implementor whether there should be model updates after this action, both options are valid.
 void removeUser(int user_id)
          Remove a user from the recommender model, and delete all their ratings It is up to the recommender implementor whether there should be model updates after this action, both options are valid.
 void retrainItem(int item_id)
          Updates the latent factors of an item.
 void retrainUser(int user_id)
          Updates the latent factors on a user.
 void saveModel(java.lang.String filename)
          Save the model parameters to a file
 void setRegularization(double regularization)
          Set the regularization parameters.
 java.lang.String toString()
          Return a string representation of the recommender
 void train()
          Learn the model parameters of the recommender from the training data
 
Methods inherited from class org.mymedialite.ratingprediction.MatrixFactorization
addRating, computeLoss, getNumIter, predict, removeRating, setNumIter, updateRating
 
Methods inherited from class org.mymedialite.ratingprediction.IncrementalRatingPredictor
getUpdateItems, getUpdateUsers, setUpdateItems, setUpdateUsers
 
Methods inherited from class org.mymedialite.ratingprediction.RatingPredictor
canPredict, clone, getMaxRating, getMinRating, getRatings, setMaxRating, setMinRating, setRatings
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mymedialite.ratingprediction.IRatingPredictor
getMaxRating, getMinRating, setMaxRating, setMinRating
 
Methods inherited from interface org.mymedialite.IRecommender
canPredict
 

Field Detail

biasReg

public double biasReg
Regularization constant for the bias terms.


regU

public double regU
Regularization constant for the user factors.


regI

public double regI
Regularization constant for the item factors.


userBias

protected double[] userBias
The user biases


itemBias

protected double[] itemBias
The item biases


optimizeMAE

public boolean optimizeMAE
If set to true, optimize model for MAE instead of RMSE.


boldDriver

public boolean boldDriver
Use bold driver heuristics for learning rate adaption. Literature: Rainer Gemulla, Peter J. Haas, Erik Nijkamp, Yannis Sismanis: Large-Scale Matrix Factorization with Distributed Stochastic Gradient Descent. KDD 2011. http://www.mpi-inf.mpg.de/~rgemulla/publications/gemulla11dsgd.pdf


last_loss

protected double last_loss
Loss for the last iteration, used by bold driver heuristics

Constructor Detail

BiasedMatrixFactorization

public BiasedMatrixFactorization()
Default constructor

Method Detail

setRegularization

public void setRegularization(double regularization)
Set the regularization parameters.

Parameters:
regularization -

initModel

protected void initModel()
Description copied from class: MatrixFactorization
Initialize the model data structure.

Overrides:
initModel in class MatrixFactorization

train

public void train()
Description copied from interface: IRecommender
Learn the model parameters of the recommender from the training data

Specified by:
train in interface IRecommender
Overrides:
train in class MatrixFactorization

iterate

public void iterate()
Description copied from interface: IIterativeModel
Run one iteration (= pass over the training data)

Specified by:
iterate in interface IIterativeModel
Overrides:
iterate in class MatrixFactorization

iterate

protected void iterate(java.util.List<java.lang.Integer> rating_indices,
                       boolean update_user,
                       boolean update_item)
Description copied from class: MatrixFactorization
Iterate once over rating data and adjust corresponding factors (stochastic gradient descent).

Overrides:
iterate in class MatrixFactorization
Parameters:
rating_indices - a list of indices pointing to the ratings to iterate over
update_user - true if user factors to be updated
update_item - true if item factors to be updated

iterateRMSE

protected void iterateRMSE(java.util.List<java.lang.Integer> rating_indices,
                           boolean update_user,
                           boolean update_item)

predict

public double predict(int user_id,
                      int item_id)
Description copied from class: MatrixFactorization
Predict the rating of a given user for a given item. If the user or the item are not known to the recommender, the global average is returned. To avoid this behavior for unknown entities, use CanPredict() to check before.

Specified by:
predict in interface IRecommender
Overrides:
predict in class MatrixFactorization
Parameters:
user_id - the user ID
item_id - the item ID
Returns:
the predicted rating

saveModel

public void saveModel(java.lang.String filename)
               throws java.io.IOException
Description copied from interface: IRecommender
Save the model parameters to a file

Specified by:
saveModel in interface IRecommender
Overrides:
saveModel in class MatrixFactorization
Parameters:
filename - the file to write to
Throws:
java.io.IOException

loadModel

public void loadModel(java.lang.String filename)
               throws java.io.IOException
Description copied from interface: IRecommender
Get the model parameters from a file

Specified by:
loadModel in interface IRecommender
Overrides:
loadModel in class MatrixFactorization
Parameters:
filename - the file to read from
Throws:
java.io.IOException

addUser

public void addUser(int user_id)

Overrides:
addUser in class MatrixFactorization

addItem

public void addItem(int item_id)

Overrides:
addItem in class MatrixFactorization

retrainUser

public void retrainUser(int user_id)
Updates the latent factors on a user.

Overrides:
retrainUser in class MatrixFactorization
Parameters:
user_id - the user ID

retrainItem

public void retrainItem(int item_id)
Updates the latent factors of an item.

Overrides:
retrainItem in class MatrixFactorization
Parameters:
item_id - the item ID

removeUser

public void removeUser(int user_id)
Remove a user from the recommender model, and delete all their ratings It is up to the recommender implementor whether there should be model updates after this action, both options are valid.

Specified by:
removeUser in interface IIncrementalRatingPredictor
Overrides:
removeUser in class MatrixFactorization
Parameters:
user_id - the ID of the user to be removed

removeItem

public void removeItem(int item_id)
Remove an item from the recommender model, and delete all ratings of this item It is up to the recommender implementor whether there should be model updates after this action, both options are valid.

Specified by:
removeItem in interface IIncrementalRatingPredictor
Overrides:
removeItem in class MatrixFactorization
Parameters:
item_id - the ID of the user to be removed

toString

public java.lang.String toString()
Return a string representation of the recommender

Specified by:
toString in interface IRecommender
Overrides:
toString in class MatrixFactorization
Returns:
the class name and all hyperparameters, separated by space characters.