org.mymedialite.ratingprediction
Class EntityAverage

java.lang.Object
  extended by org.mymedialite.ratingprediction.RatingPredictor
      extended by org.mymedialite.ratingprediction.IncrementalRatingPredictor
          extended by org.mymedialite.ratingprediction.EntityAverage
All Implemented Interfaces:
java.lang.Cloneable, IRecommender, IIncrementalRatingPredictor, IRatingPredictor
Direct Known Subclasses:
ItemAverage, UserAverage

public abstract class EntityAverage
extends IncrementalRatingPredictor

Abstract class that uses an average (by entity) rating value for predictions. This engine does NOT support online updates.


Field Summary
protected  DoubleList entity_averages
          The average rating for each entity
protected  double global_average
          The global average rating (default prediction if there is no data about an entity)
 
Fields inherited from class org.mymedialite.ratingprediction.IncrementalRatingPredictor
updateItems, updateUsers
 
Fields inherited from class org.mymedialite.ratingprediction.RatingPredictor
maxItemID, maxRating, maxUserID, minRating, ratings
 
Constructor Summary
EntityAverage()
           
 
Method Summary
 double get(int index)
          Return the average rating for a given entity
 void loadModel(java.lang.String filename)
          Get the model parameters from a file
protected  void retrain(int entity_id, IntList indices, IntList entity_ids)
          Retrain the recommender according to the given entity type.
 void saveModel(java.lang.String filename)
          Save the model parameters to a file
protected  void train(IntList entity_ids, int max_entity_id)
          Train the recommender according to the given entity type
 
Methods inherited from class org.mymedialite.ratingprediction.IncrementalRatingPredictor
addItem, addRating, addUser, getUpdateItems, getUpdateUsers, removeItem, removeRating, removeUser, setUpdateItems, setUpdateUsers, updateRating
 
Methods inherited from class org.mymedialite.ratingprediction.RatingPredictor
canPredict, clone, getMaxRating, getMinRating, getRatings, predict, setMaxRating, setMinRating, setRatings, toString, train
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mymedialite.ratingprediction.IRatingPredictor
getMaxRating, getMinRating, setMaxRating, setMinRating
 
Methods inherited from interface org.mymedialite.IRecommender
canPredict, predict, toString, train
 

Field Detail

entity_averages

protected DoubleList entity_averages
The average rating for each entity


global_average

protected double global_average
The global average rating (default prediction if there is no data about an entity)

Constructor Detail

EntityAverage

public EntityAverage()
Method Detail

get

public double get(int index)
Return the average rating for a given entity

Parameters:
index - the entity index

train

protected void train(IntList entity_ids,
                     int max_entity_id)
Train the recommender according to the given entity type

Parameters:
entity_ids - a list of the relevant entity IDs in the training data
max_entity_id - the maximum entity ID

retrain

protected void retrain(int entity_id,
                       IntList indices,
                       IntList entity_ids)
Retrain the recommender according to the given entity type.

Parameters:
entity_id - the ID of the entity to update
indices - list of indices to use for retraining
entity_ids - list of all entity IDs in the training data (per 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