|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.mymedialite.itemrec.ItemRecommender
org.mymedialite.itemrec.IncrementalItemRecommender
org.mymedialite.itemrec.MF
org.mymedialite.itemrec.BPRMF
public class BPRMF
Matrix factorization model for item prediction (ranking) optimized using BPR. BPR reduces ranking to pairwise classification. Literature: Steffen Rendle, Christoph Freudenthaler, Zeno Gantner, Lars Schmidt-Thieme: BPR: Bayesian Personalized Ranking from Implicit Feedback. UAI 2009. http://www.ismll.uni-hildesheim.de/pub/pdfs/Rendle_et_al2009-Bayesian_Personalized_Ranking.pdf Different sampling strategies are configurable by setting the uniformUserSampling and withReplacement accordingly. To get the strategy from the original paper, set uniformUserSampling=false and withReplacement=false. withReplacement=true (default) gives you usually a slightly faster convergence, and uniformUserSampling=true (default) (approximately) optimizes the average AUC over all users. This recommender supports incremental updates.
Field Summary | |
---|---|
double |
biasReg
Regularization parameter for the bias term |
boolean |
boldDriver
Use bold driver heuristics for learning rate adaption. |
protected boolean |
fastSampling
Fast, but memory-intensive sampling |
int |
fastSamplingMemoryLimit
Fast sampling memory limit, in MiB TODO find out why fast sampling does not improve performance |
protected double[] |
itemBias
Item bias terms |
double |
learnRate
Learning rate alpha |
protected Random |
random
Random number generator |
double |
regI
Regularization parameter for positive item factors |
double |
regJ
Regularization parameter for negative item factors |
double |
regU
Regularization parameter for user factors |
boolean |
uniformUserSampling
Sample uniformly from users |
protected boolean |
updateJ
If set (default), update factors for negative sampled items during learning |
protected java.util.ArrayList<int[]> |
userNegItems
Support data structure for fast sampling |
protected java.util.ArrayList<int[]> |
userPosItems
Support data structure for fast sampling |
boolean |
withReplacement
Sample positive observations with (true) or without (false) replacement |
Fields inherited from class org.mymedialite.itemrec.MF |
---|
initMean, initStDev, itemFactors, numFactors, numIter, userFactors |
Fields inherited from class org.mymedialite.itemrec.ItemRecommender |
---|
feedback, maxItemID, maxUserID |
Constructor Summary | |
---|---|
BPRMF()
Default constructor. |
Method Summary | |
---|---|
void |
addFeedback(int user_id,
int item_id)
add a new positive feedback event |
void |
addItem(int item_id)
|
void |
addUser(int user_id)
|
protected void |
checkSampling()
|
double |
computeFit()
Compute the fit (AUC on training data) |
double |
computeLoss()
Compute approximate loss. |
protected void |
createFastSamplingData(int u)
|
protected void |
initModel()
|
void |
iterate()
Perform one iteration of stochastic gradient ascent over the training 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 |
removeFeedback(int user_id,
int item_id)
remove all positive feedback events with that user-item combination |
void |
removeItem(int item_id)
remove all feedback for one item |
void |
removeUser(int user_id)
remove all feedback by one user |
protected void |
retrainItem(int item_id)
Retrain the latent factors of a given item |
protected void |
retrainUser(int user_id)
Retrain the latent factors of a given user |
protected void |
sampleItemPair(org.mymedialite.itemrec.BPRMF.SampleTriple triple)
Sample a pair of items, given a user |
protected boolean |
sampleOtherItem(org.mymedialite.itemrec.BPRMF.SampleTriple triple)
Sample another item, given the first one and the user |
protected org.mymedialite.itemrec.BPRMF.SampleTriple |
sampleTriple()
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)
{ @inheritDoc } |
void |
saveModel(java.lang.String filename)
{ @inheritDoc } |
java.lang.String |
toString()
Return a string representation of the recommender |
void |
train()
{ @inheritDoc } |
protected void |
updateFactors(org.mymedialite.itemrec.BPRMF.SampleTriple t,
boolean updateU,
boolean updateI,
boolean updateJ)
Update features according to the stochastic gradient descent update rule. |
Methods inherited from class org.mymedialite.itemrec.MF |
---|
getItemFactors, getNumIter, getUserFactors, setNumIter |
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 |
---|
protected boolean fastSampling
protected double[] itemBias
public int fastSamplingMemoryLimit
public boolean withReplacement
public boolean uniformUserSampling
public double biasReg
public double learnRate
public double regU
public double regI
public double regJ
protected boolean updateJ
protected java.util.ArrayList<int[]> userPosItems
protected java.util.ArrayList<int[]> userNegItems
public boolean boldDriver
protected Random random
Constructor Detail |
---|
public BPRMF()
Method Detail |
---|
protected void initModel()
initModel
in class MF
public void train()
train
in interface IRecommender
train
in class MF
public void iterate()
iterate
in interface IIterativeModel
iterate
in class MF
protected boolean sampleOtherItem(org.mymedialite.itemrec.BPRMF.SampleTriple triple)
triple
- a SampleTriple consisting of a user ID and two item IDs
protected void sampleItemPair(org.mymedialite.itemrec.BPRMF.SampleTriple triple)
triple
- a SampleTriple consisting of a user ID and two item IDsprotected int sampleUser()
protected org.mymedialite.itemrec.BPRMF.SampleTriple sampleTriple()
protected void updateFactors(org.mymedialite.itemrec.BPRMF.SampleTriple t, boolean updateU, boolean updateI, boolean updateJ)
t
- a SampleTriple specifying the user ID and the first and second itemIDsupdateU
- if true, update the user featuresupdateI
- if true, update the features of the first itemupdateJ
- if true, update the features of the second itempublic void addFeedback(int user_id, int item_id)
addFeedback
in interface IIncrementalItemRecommender
addFeedback
in class IncrementalItemRecommender
user_id
- the user IDitem_id
- the item IDpublic void removeFeedback(int user_id, int item_id)
removeFeedback
in interface IIncrementalItemRecommender
removeFeedback
in class IncrementalItemRecommender
user_id
- the user IDitem_id
- the item IDpublic void addUser(int user_id)
addUser
in class IncrementalItemRecommender
public void addItem(int item_id)
addItem
in class IncrementalItemRecommender
public void removeUser(int user_id)
removeUser
in interface IIncrementalItemRecommender
removeUser
in class IncrementalItemRecommender
user_id
- the user IDpublic void removeItem(int item_id)
removeItem
in interface IIncrementalItemRecommender
removeItem
in class IncrementalItemRecommender
item_id
- the item IDprotected void retrainUser(int user_id)
user_id
- the user IDprotected void retrainItem(int item_id)
item_id
- the item IDpublic double computeLoss()
computeLoss
in interface IIterativeModel
computeLoss
in class MF
public double computeFit()
protected void createFastSamplingData(int u)
protected void checkSampling()
public double predict(int user_id, int item_id)
MF
predict
in interface IRecommender
predict
in class MF
user_id
- the user IDitem_id
- the item ID
public void saveModel(java.lang.String filename) throws java.io.IOException
MF
saveModel
in interface IRecommender
saveModel
in class MF
filename
- the file to write to
java.io.IOException
public void saveModel(java.io.PrintWriter writer)
MF
saveModel
in class MF
public void loadModel(java.lang.String filename) throws java.io.IOException
loadModel
in interface IRecommender
loadModel
in class MF
filename
- the file to read from
java.io.IOException
public void loadModel(java.io.BufferedReader reader) throws java.io.IOException
loadModel
in class MF
java.io.IOException
public java.lang.String toString()
IRecommender
toString
in interface IRecommender
toString
in class ItemRecommender
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |