jcolibri.extensions.recommendation.collaborative
Class MatrixCaseBase

java.lang.Object
  extended by jcolibri.extensions.recommendation.collaborative.MatrixCaseBase
All Implemented Interfaces:
CBRCaseBase
Direct Known Subclasses:
PearsonMatrixCaseBase

public abstract class MatrixCaseBase
extends java.lang.Object
implements CBRCaseBase

Specific implementation of CBRCaseBase to allow collaborative recommendations. These kind of recommendations are based in the past experieces of other users.
This case base manages cases composed by a description, a solution and a result. The description usually contains the information about the user that made the recommendation, the solution contains the information about the recommended item, and the result stores the rating value for the item (the value that the user assigns to an item after evaluating it).
This way, this case base implementation stores cases as a table:

Item1Item2Item3Item4Item5...ItemM
User1rating12rating14
User2rating21rating23rating2N
User3rating33rating34rating3N
...
UserNratingN2ratingN5ratingNN
The values of the users column and the items row are the ids of the description and solution parts of the case. These ids must be integer values. The ratings are obtained from an attribute of the result part.
Note that these cases base allows having different cases with the same description (because each user can make several recommendations).

Collaborative recommenders can be separated into three steps:

  1. Weight all users with respect to similarity with the active user.
  2. Select a subset of users as a set of predictors.
  3. Normalize ratings and compute a prediction from a weighted combination of selected neighbors' ratings.
There are several ways to compute first step. And it must be implemented by subclassing this class as in PearsonMatrixCaseBase. The subclasses must implement the abstract methods defined here that return the similarity among neighbors. The similarity among users is stored through SimilarityTuple objects.

To allow an efficient comparison, ratings must be sorted by neighbors. In the above table this means that cases are organized by rows. And that is done internally in this class through the organizeByDescriptionId() method. Then, the ratings of each user can be accessed through the getRatingTuples() method. A RatingTuple object stores the id of the item and its rating (id of the solution and id of the result).

There are also 2 internal classes (CommonRatingTuple and CommonRatingsIterator) that allow to obtain efficiently the common ratings of two users. This will be used by subclasses when computing the neighbors similarity. The code of these classes is an adaptation of the one developed by Jerome Kelleher and Derek Bridge for the Collaborative Movie Recommender project at University College Cork (Ireland).

Recommender 12 shows how to use these classes.

Version:
1.0
Author:
Juan A. Recio-Garcia, Developed at University College Cork (Ireland) in collaboration with Derek Bridge.
See Also:
PearsonMatrixCaseBase, MoviesRecommender

Nested Class Summary
 class MatrixCaseBase.RatingTuple
          Stores a rating for an item.
 class MatrixCaseBase.SimilarTuple
          Stores the similarity among neighbors.
 
Constructor Summary
MatrixCaseBase(Attribute value)
          Constructor.
 
Method Summary
 void close()
          Closes the case base
protected abstract  void computeSimilarities()
          Computes the similarity of neighbors (each neighbor is defined by the description)
 void forgetCases(java.util.Collection<CBRCase> cases)
          Forgets cases.
 java.util.Collection<CBRCase> getCases()
          Returns the stored cases
 java.util.Collection<CBRCase> getCases(CaseBaseFilter filter)
          Returns selected cases.
 CaseComponent getDescription(java.lang.Integer id)
          Utility method to obtain the description object given its id.
 java.util.Set<java.lang.Integer> getDescriptions()
          Utility method to obtain all the descriptions stored in this case base
 java.util.Collection<MatrixCaseBase.RatingTuple> getRatingTuples(int descriptionId)
          Returns the ratings that a user has done.
abstract  double getSimil(java.lang.Integer id1, java.lang.Integer id2)
          Returns the similarity of two neighbors.
abstract  java.util.Collection<MatrixCaseBase.SimilarTuple> getSimilar(java.lang.Integer id)
          Returns the list of similar neighbors for a given one
 CaseComponent getSolution(java.lang.Integer id)
          Utility method to obtain the solution object given its id.
 java.util.Set<java.lang.Integer> getSolutions()
          Utility method to obtain all the solutions stored in this case base
 void init(Connector connector)
          Initializes the case base.
 void learnCases(java.util.Collection<CBRCase> cases)
          Adds new cases to the case base, reorganizing the cases base and re-computing neighbors similarities.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MatrixCaseBase

public MatrixCaseBase(Attribute value)
Constructor. The value parameter defines the attribute of the result that stores the ratings.

Parameters:
value -
Method Detail

computeSimilarities

protected abstract void computeSimilarities()
Computes the similarity of neighbors (each neighbor is defined by the description)


getSimil

public abstract double getSimil(java.lang.Integer id1,
                                java.lang.Integer id2)
Returns the similarity of two neighbors.

Parameters:
id1 - of the first neighbor
id2 - of the second neighbor.
Returns:
a double between 0 and 1

getSimilar

public abstract java.util.Collection<MatrixCaseBase.SimilarTuple> getSimilar(java.lang.Integer id)
Returns the list of similar neighbors for a given one

Parameters:
id - of the neighbor
Returns:
a list of SimilarTuple (other neighbor id + similarity value).

init

public void init(Connector connector)
Initializes the case base. Organizes ratings by the description id of the cases and calls the computeSimilarities() abstract method.

Specified by:
init in interface CBRCaseBase

getDescription

public CaseComponent getDescription(java.lang.Integer id)
Utility method to obtain the description object given its id.

Parameters:
id - of the description object
Returns:
the description object

getDescriptions

public java.util.Set<java.lang.Integer> getDescriptions()
Utility method to obtain all the descriptions stored in this case base

Returns:
a set of ids.

getSolution

public CaseComponent getSolution(java.lang.Integer id)
Utility method to obtain the solution object given its id.

Parameters:
id - of the solution object
Returns:
the solution object

getSolutions

public java.util.Set<java.lang.Integer> getSolutions()
Utility method to obtain all the solutions stored in this case base

Returns:
a set of ids.

getRatingTuples

public java.util.Collection<MatrixCaseBase.RatingTuple> getRatingTuples(int descriptionId)
Returns the ratings that a user has done.

Parameters:
descriptionId - of the user
Returns:
collection of rating tuples (solution id + rating value)

close

public void close()
Closes the case base

Specified by:
close in interface CBRCaseBase

forgetCases

public void forgetCases(java.util.Collection<CBRCase> cases)
Forgets cases. It does nothing in this implementation

Specified by:
forgetCases in interface CBRCaseBase
Parameters:
cases - to be removed

getCases

public java.util.Collection<CBRCase> getCases()
Returns the stored cases

Specified by:
getCases in interface CBRCaseBase
Returns:
all the cases available on this case base

getCases

public java.util.Collection<CBRCase> getCases(CaseBaseFilter filter)
Returns selected cases. It does nothing in this implementation.

Specified by:
getCases in interface CBRCaseBase
Parameters:
filter - a case base filter
Returns:
a collection of cases

learnCases

public void learnCases(java.util.Collection<CBRCase> cases)
Adds new cases to the case base, reorganizing the cases base and re-computing neighbors similarities.

Specified by:
learnCases in interface CBRCaseBase
Parameters:
cases - to be added

GAIA - Group for Artificial Intelligence Applications
http://gaia.fdi.ucm.es