org.mymedialite.ratingprediction
Class FactorWiseMatrixFactorization

java.lang.Object
  extended by org.mymedialite.ratingprediction.RatingPredictor
      extended by org.mymedialite.ratingprediction.FactorWiseMatrixFactorization
All Implemented Interfaces:
java.lang.Cloneable, IIterativeModel, IRecommender, IRatingPredictor

public class FactorWiseMatrixFactorization
extends RatingPredictor
implements IIterativeModel

Matrix factorization with factor-wise learning. Similar to the approach described in Simon Funk's seminal blog post: http://sifter.org/~simon/journal/20061211.html Literature: Robert Bell, Yehuda Koren, Chris Volinsky: Modeling Relationships at Multiple Scales to Improve Accuracy of Large Recommender Systems, ACM Int. Conference on Knowledge Discovery and Data Mining (KDD'07), 2007. This recommender does NOT support incremental updates.


Field Summary
 double initMean
          Mean of the normal distribution used to initialize the factors.
 double initStDev
          Standard deviation of the normal distribution used to initialize the factors.
 int numFactors
          Number of latent factors.
 int numIter
          Number of iterations (in this case: number of latent factors).
 double sensibility
          Sensibility parameter (stopping criterion for parameter fitting).
 double shrinkage
          Shrinkage parameter.
 
Fields inherited from class org.mymedialite.ratingprediction.RatingPredictor
maxItemID, maxRating, maxUserID, minRating, ratings
 
Constructor Summary
FactorWiseMatrixFactorization()
          Default constructor.
 
Method Summary
 double computeLoss()
          Compute the current loss of the model
 int getNumIter()
          Get the number of iterations to run the training
 double getRegI()
          Regularization constant for the item bias of the underlying baseline predictor.
 double getRegU()
          Regularization constant for the user bias of the underlying baseline predictor.
 void iterate()
          Run one iteration (= pass over the training data)
 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 saveModel(java.lang.String filename)
          Save the model parameters to a file
 void setNumIter(int num_iter)
          Set the number of iterations to run the training
 void setRatings(IRatings ratings)
           
 void setRegI(double regI)
           
 void setRegU(double regU)
           
 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.RatingPredictor
canPredict, clone, getMaxRating, getMinRating, getRatings, setMaxRating, setMinRating
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

numFactors

public int numFactors
Number of latent factors.


numIter

public int numIter
Number of iterations (in this case: number of latent factors).


shrinkage

public double shrinkage
Shrinkage parameter. alpha in the Bell et al. paper


sensibility

public double sensibility
Sensibility parameter (stopping criterion for parameter fitting). epsilon in the Bell et al. paper


initMean

public double initMean
Mean of the normal distribution used to initialize the factors.


initStDev

public double initStDev
Standard deviation of the normal distribution used to initialize the factors.

Constructor Detail

FactorWiseMatrixFactorization

public FactorWiseMatrixFactorization()
Default constructor.

Method Detail

setRatings

public void setRatings(IRatings ratings)
Overrides:
setRatings in class RatingPredictor

getRegU

public double getRegU()
Regularization constant for the user bias of the underlying baseline predictor.


setRegU

public void setRegU(double regU)

getRegI

public double getRegI()
Regularization constant for the item bias of the underlying baseline predictor.


setRegI

public void setRegI(double regI)

setNumIter

public void setNumIter(int num_iter)
Description copied from interface: IIterativeModel
Set the number of iterations to run the training

Specified by:
setNumIter in interface IIterativeModel

getNumIter

public int getNumIter()
Description copied from interface: IIterativeModel
Get the number of iterations to run the training

Specified by:
getNumIter in interface IIterativeModel

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
Specified by:
train in class RatingPredictor

iterate

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

Specified by:
iterate in interface IIterativeModel

predict

public double predict(int user_id,
                      int item_id)
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 effects prediction is returned. To avoid this behavior for unknown entities, use canPredict() to check before.

Specified by:
predict in interface IRecommender
Specified by:
predict in class RatingPredictor
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
Specified by:
saveModel in class RatingPredictor
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
Specified by:
loadModel in class RatingPredictor
Parameters:
filename - the file to read from
Throws:
java.io.IOException

computeLoss

public double computeLoss()
Description copied from interface: IIterativeModel
Compute the current loss of the model

Specified by:
computeLoss in interface IIterativeModel
Returns:
the current loss; -1 if not implemented

toString

public java.lang.String toString()
Description copied from interface: IRecommender
Return a string representation of the recommender

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