org.mymedialite.itemrec
Class ItemRecommender

java.lang.Object
  extended by org.mymedialite.itemrec.ItemRecommender
All Implemented Interfaces:
java.lang.Cloneable, IRecommender
Direct Known Subclasses:
BPRLinear, IncrementalItemRecommender, KNN, Perfect, Random, Worst, Zero

public abstract class ItemRecommender
extends java.lang.Object
implements IRecommender

Abstract item recommender class that loads the (positive-only implicit feedback) training data into memory and provides flexible access to it.


Field Summary
protected  IPosOnlyFeedback feedback
          The feedback data to be used for training
protected  int maxItemID
          The maximum item ID
protected  int maxUserID
          The maximum user ID
 
Constructor Summary
protected ItemRecommender()
           
 
Method Summary
 boolean canPredict(int user_id, int item_id)
          Check whether a useful prediction can be made for a given user-item combination.
 ItemRecommender clone()
          Create a shallow copy of the object.
 IPosOnlyFeedback getFeedback()
           
abstract  void loadModel(java.io.BufferedReader reader)
           
abstract  void loadModel(java.lang.String filename)
          Get the model parameters from a file
abstract  double predict(int userId, int itemId)
          Predict the rating or score for a given user-item combination.
abstract  void saveModel(java.io.PrintWriter writer)
           
abstract  void saveModel(java.lang.String filename)
          Save the model parameters to a file
 void setFeedback(IPosOnlyFeedback feedback)
           
 java.lang.String toString()
          Return a string representation of the recommender
abstract  void train()
          Learn the model parameters of the recommender from the training data
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

maxUserID

protected int maxUserID
The maximum user ID


maxItemID

protected int maxItemID
The maximum item ID


feedback

protected IPosOnlyFeedback feedback
The feedback data to be used for training

Constructor Detail

ItemRecommender

protected ItemRecommender()
Method Detail

getFeedback

public IPosOnlyFeedback getFeedback()

setFeedback

public void setFeedback(IPosOnlyFeedback feedback)

clone

public ItemRecommender clone()
Create a shallow copy of the object.

Overrides:
clone in class java.lang.Object

predict

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

Specified by:
predict in interface IRecommender
Parameters:
userId - the user ID
itemId - the item ID
Returns:
the predicted score/rating for the given user-item combination

canPredict

public boolean canPredict(int user_id,
                          int item_id)
Description copied from interface: IRecommender
Check whether a useful prediction can be made for a given user-item combination.

Specified by:
canPredict in interface IRecommender
Parameters:
user_id - the user ID
item_id - the item ID
Returns:
true if a useful prediction can be made, false otherwise

train

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

Specified by:
train in interface IRecommender

loadModel

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

loadModel

public abstract void loadModel(java.io.BufferedReader reader)
                        throws java.io.IOException
Throws:
java.io.IOException

saveModel

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

saveModel

public abstract void saveModel(java.io.PrintWriter writer)
                        throws java.io.IOException
Throws:
java.io.IOException

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 java.lang.Object
Returns:
the class name and all hyperparameters, separated by space characters.