Class ItemSimilarityMetric

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

    public abstract class ItemSimilarityMetric
    extends Object
    implements Partible<Item>
    This class process the similarity measure between two items. To define your own similarity metric implementation, you must extend this class and overrides the method similarity(Item item, Item otherItem).

    When the execution of the similarity metric is completed, the similarity of each item with respect to another one can be retrieved using the getSimilarities(int itemIndex) 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 items
    • Constructor Detail

      • ItemSimilarityMetric

        public ItemSimilarityMetric()
    • 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 itemIndex)
        Returns the similarity array of an item. Each position of the array contains the similarity of the item with the corresponding item at the same position in the array of Items of the DataModel instance.
        Parameters:
        itemIndex - Index of the item
        Returns:
        Similarity of an item with other items of the DataModel instance
      • similarity

        public abstract double similarity​(Item item,
                                          Item otherItem)
        This method must returns the similarity between two items.

        If two items 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 items.

        Parameters:
        item - An item
        otherItem - Other item
        Returns:
        Similarity between item and otherItem
      • 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<Item>
      • run

        public void run​(Item item)
        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<Item>
        Parameters:
        item - 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<Item>