org.mymedialite.itemrec
Class MF

java.lang.Object
  extended by org.mymedialite.itemrec.ItemRecommender
      extended by org.mymedialite.itemrec.IncrementalItemRecommender
          extended by org.mymedialite.itemrec.MF
All Implemented Interfaces:
java.lang.Cloneable, IIterativeModel, IRecommender, IIncrementalItemRecommender
Direct Known Subclasses:
BPRMF, WRMF

public abstract class MF
extends IncrementalItemRecommender
implements IIterativeModel

Abstract class for Matrix Factorization based item predictors.


Field Summary
 double initMean
          Mean of the normal distribution used to initialize the latent factors
 double initStDev
          Standard deviation of the normal distribution used to initialize the latent factors
protected  Matrix<java.lang.Double> itemFactors
          Latent item factor matrix
 int numFactors
          Number of latent factors per user/item
 int numIter
          Number of iterations over the training data
protected  Matrix<java.lang.Double> userFactors
          Latent user factor matrix
 
Fields inherited from class org.mymedialite.itemrec.ItemRecommender
feedback, maxItemID, maxUserID
 
Constructor Summary
MF()
           
 
Method Summary
abstract  double computeLoss()
          Computes the fit (optimization criterion) on the training data
 Matrix<java.lang.Double> getItemFactors()
          Get the latent item factor matrix
 int getNumIter()
          { @inheritDoc }
 Matrix<java.lang.Double> getUserFactors()
          Get the latent user factor matrix
protected  void initModel()
           
abstract  void iterate()
          Iterate once over the data
 void loadModel(java.io.BufferedReader reader)
          { @inheritDoc }
 void loadModel(java.lang.String filename)
          { @inheritDoc }
 double predict(int user_id, int item_id)
          Predict the weight for a given user-item combination.
 void saveModel(java.io.PrintWriter writer)
          { @inheritDoc }
 void saveModel(java.lang.String filename)
          { @inheritDoc }
 void setNumIter(int num_iter)
          { @inheritDoc }
 void train()
          { @inheritDoc }
 
Methods inherited from class org.mymedialite.itemrec.IncrementalItemRecommender
addFeedback, addItem, addUser, removeFeedback, removeItem, removeUser
 
Methods inherited from class org.mymedialite.itemrec.ItemRecommender
canPredict, clone, getFeedback, setFeedback, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mymedialite.IRecommender
canPredict, toString
 

Field Detail

userFactors

protected Matrix<java.lang.Double> userFactors
Latent user factor matrix


itemFactors

protected Matrix<java.lang.Double> itemFactors
Latent item factor matrix


initMean

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


initStDev

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


numFactors

public int numFactors
Number of latent factors per user/item


numIter

public int numIter
Number of iterations over the training data

Constructor Detail

MF

public MF()
Method Detail

getUserFactors

public Matrix<java.lang.Double> getUserFactors()
Get the latent user factor matrix


getItemFactors

public Matrix<java.lang.Double> getItemFactors()
Get the latent item factor matrix


getNumIter

public int getNumIter()
{ @inheritDoc }

Specified by:
getNumIter in interface IIterativeModel

setNumIter

public void setNumIter(int num_iter)
{ @inheritDoc }

Specified by:
setNumIter in interface IIterativeModel

initModel

protected void initModel()

train

public void train()
{ @inheritDoc }

Specified by:
train in interface IRecommender
Specified by:
train in class ItemRecommender

iterate

public abstract void iterate()
Iterate once over the data

Specified by:
iterate in interface IIterativeModel

computeLoss

public abstract double computeLoss()
Computes the fit (optimization criterion) on the training data

Specified by:
computeLoss in interface IIterativeModel
Returns:
a double representing the fit, lower is better

predict

public double predict(int user_id,
                      int item_id)
Predict the weight for a given user-item combination. If the user or the item are not known to the recommender, zero 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 ItemRecommender
Parameters:
user_id - the user ID
item_id - the item ID
Returns:
the predicted weight

saveModel

public void saveModel(java.lang.String filename)
               throws java.io.IOException
{ @inheritDoc }

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

saveModel

public void saveModel(java.io.PrintWriter writer)
{ @inheritDoc }

Specified by:
saveModel in class ItemRecommender

loadModel

public void loadModel(java.lang.String filename)
               throws java.io.IOException
{ @inheritDoc }

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

loadModel

public void loadModel(java.io.BufferedReader reader)
               throws java.io.IOException
{ @inheritDoc }

Specified by:
loadModel in class ItemRecommender
Throws:
java.io.IOException