Class UserSimilarityMetric

  • All Implemented Interfaces:
    Partible<User>
    Direct Known Subclasses:
    AdjustedCosine, CJMSD, Correlation, CorrelationConstrained, Cosine, Jaccard, JMSD, MSD, PIP, Singularities, SpearmanRank

    public abstract class UserSimilarityMetric
    extends Object
    implements Partible<User>
    This class process the similarity measure between two users. To define your own similarity metric implementation, you must extend this class and overrides the method similarity(User user, User otherUser).

    When the execution of the similarity metric is completed, the similarity of each user with respect to another one can be retrieved using the getSimilarities(int userIndex) method.

    • Field Detail

      • datamodel

        protected DataModel datamodel
        DataModel for which de similarities must be computed
      • similarities

        protected double[][] similarities
        Matrix that contains the similarity between each pair of users
    • Constructor Detail

      • UserSimilarityMetric

        public UserSimilarityMetric()
    • Method Detail

      • setDatamodel

        public void setDatamodel​(DataModel datamodel)
        Sets the DataModel for which the similarity are going to be computed
        Parameters:
        datamodel - DataModel instance
      • getSimilarities

        public double[] getSimilarities​(int userIndex)
        Returns the similarity array of an user. Each position of the array contains the similarity of the user with the corresponding user at the same position in the array of Users of the DataModel instance.
        Parameters:
        userIndex - Index of the user
        Returns:
        Similarity of an user with other users of the DataModel instance
      • similarity

        public abstract double similarity​(User user,
                                          User otherUser)
        This method must returns the similarity between two users.

        If two users do not have a similarity value, the method must return Double.NEGATIVE_INFINITY.

        The value returned by this method should be higher the greater the similarity between users.

        Parameters:
        user - A user
        otherUser - Other user
        Returns:
        Similarity between user and otherUser
      • beforeRun

        public void beforeRun()
        Description copied from interface: Partible
        Is executed once before execute the method 'exec'. It can be used to initialize resources.
        Specified by:
        beforeRun in interface Partible<User>
      • run

        public void run​(User user)
        Description copied from interface: Partible
        Is executed once for each object in the array of objects passed as parameter in the exec method of the Parallelizer class. These executions are performed in a parallel way. Race conditions must be handle by the developer. This method is no thread safe.
        Specified by:
        run in interface Partible<User>
        Parameters:
        user - Index of the test element.
      • afterRun

        public void afterRun()
        Description copied from interface: Partible
        Is executed once after execute the method exec. It can be used to close resources.
        Specified by:
        afterRun in interface Partible<User>