org.mymedialite.itemrec
Class BPRLinear

java.lang.Object
  extended by org.mymedialite.itemrec.ItemRecommender
      extended by org.mymedialite.itemrec.BPRLinear
All Implemented Interfaces:
java.lang.Cloneable, IItemAttributeAwareRecommender, IIterativeModel, IRecommender

public class BPRLinear
extends ItemRecommender
implements IItemAttributeAwareRecommender, IIterativeModel

Linear model optimized for BPR. Literature: Zeno Gantner, Lucas Drumond, Christoph Freudenthaler, Steffen Rendle, Lars Schmidt-Thieme: Learning Attribute-to-Feature Mappings for Cold-Start Recommendations. ICDM 2011. http://www.ismll.uni-hildesheim.de/pub/pdfs/Gantner_et_al2010Mapping.pdf This recommender does NOT support incremental updates.


Field Summary
 int fastSamplingMemoryLimit
          Fast sampling memory limit, in MiB.
 double initMean
          mean of the Gaussian distribution used to initialize the features.
 double initStdev
          standard deviation of the normal distribution used to initialize the features.
protected  int iterationLength
          One iteration = iterationLength * number of entries in the training matrix.
 double learnRate
          Learning rate alpha.
 int numIter
          Number of iterations over the training data.
 double regularization
          Regularization parameter.
 
Fields inherited from class org.mymedialite.itemrec.ItemRecommender
feedback, maxItemID, maxUserID
 
Constructor Summary
BPRLinear()
           
 
Method Summary
 double computeLoss()
          Compute the current loss of the model
 SparseBooleanMatrix getItemAttributes()
          Getter for binary item attributes
 int getNumIter()
          Get the number of iterations to run the training
 void iterate()
          Perform one iteration of stochastic gradient ascent over the training data.
 void loadModel(java.io.BufferedReader reader)
           
 void loadModel(java.lang.String filename)
          Get the model parameters from a file
 int numItemAttributes()
          Getter for number of binary item attributes
 double predict(int user_id, int item_id)
          Predict the rating or score for a given user-item combination.
protected  void sampleItemPair(org.mymedialite.itemrec.BPRLinear.SampleTriple t)
          Sample a pair of items, given a user.
protected  void sampleTriple(org.mymedialite.itemrec.BPRLinear.SampleTriple t)
          Sample a triple for BPR learning.
protected  int sampleUser()
          Sample a user that has viewed at least one and not all items.
 void saveModel(java.io.PrintWriter writer)
           
 void saveModel(java.lang.String filename)
          Save the model parameters to a file
 void setItemAttributes(SparseBooleanMatrix itemAttributes)
          Setter for binary item attributes
 void setNumIter(int numIter)
          Set the number of iterations to run the training
 java.lang.String toString()
          Return a string representation of the recommender
 void train()
          Learn the model parameters of the recommender from the training data
protected  void updateFeatures(org.mymedialite.itemrec.BPRLinear.SampleTriple t)
          Modified feature update method that exploits attribute sparsity.
 
Methods inherited from class org.mymedialite.itemrec.ItemRecommender
canPredict, clone, getFeedback, setFeedback
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mymedialite.IRecommender
canPredict
 

Field Detail

iterationLength

protected int iterationLength
One iteration = iterationLength * number of entries in the training matrix.


numIter

public int numIter
Number of iterations over the training data.


fastSamplingMemoryLimit

public int fastSamplingMemoryLimit
Fast sampling memory limit, in MiB.


initMean

public double initMean
mean of the Gaussian distribution used to initialize the features.


initStdev

public double initStdev
standard deviation of the normal distribution used to initialize the features.


learnRate

public double learnRate
Learning rate alpha.


regularization

public double regularization
Regularization parameter.

Constructor Detail

BPRLinear

public BPRLinear()
Method Detail

getItemAttributes

public SparseBooleanMatrix getItemAttributes()
Description copied from interface: IItemAttributeAwareRecommender
Getter for binary item attributes

Specified by:
getItemAttributes in interface IItemAttributeAwareRecommender

setItemAttributes

public void setItemAttributes(SparseBooleanMatrix itemAttributes)
Description copied from interface: IItemAttributeAwareRecommender
Setter for binary item attributes

Specified by:
setItemAttributes in interface IItemAttributeAwareRecommender

numItemAttributes

public int numItemAttributes()
Description copied from interface: IItemAttributeAwareRecommender
Getter for number of binary item attributes

Specified by:
numItemAttributes in interface IItemAttributeAwareRecommender

setNumIter

public void setNumIter(int numIter)
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 ItemRecommender

iterate

public void iterate()
Perform one iteration of stochastic gradient ascent over the training data. One iteration is * number of entries in the training matrix.

Specified by:
iterate in interface IIterativeModel

sampleItemPair

protected void sampleItemPair(org.mymedialite.itemrec.BPRLinear.SampleTriple t)
Sample a pair of items, given a user.

Parameters:
t - a SampleTriple specifying a user ID

sampleUser

protected int sampleUser()
Sample a user that has viewed at least one and not all items.

Returns:
the user ID

sampleTriple

protected void sampleTriple(org.mymedialite.itemrec.BPRLinear.SampleTriple t)
Sample a triple for BPR learning.

Parameters:
t - the SampleTriple to configure

updateFeatures

protected void updateFeatures(org.mymedialite.itemrec.BPRLinear.SampleTriple t)
Modified feature update method that exploits attribute sparsity.

Parameters:
t - a SampleTriple specifying the user ID and the first and second item IDs

predict

public double predict(int user_id,
                      int item_id)
Description copied from interface: IRecommender
Predict the rating or score for a given user-item combination.

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 score/rating for the given user-item combination

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 ItemRecommender
Parameters:
filename - the file to write to
Throws:
java.io.IOException

saveModel

public void saveModel(java.io.PrintWriter writer)
Specified by:
saveModel in class ItemRecommender

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 ItemRecommender
Parameters:
filename - the file to read from
Throws:
java.io.IOException

loadModel

public void loadModel(java.io.BufferedReader reader)
               throws java.io.IOException
Specified by:
loadModel in class ItemRecommender
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 ItemRecommender
Returns:
the class name and all hyperparameters, separated by space characters.