Class ItemSimilarityMetric
- java.lang.Object
-
- es.upm.etsisi.cf4j.recommender.knn.itemSimilarityMetric.ItemSimilarityMetric
-
- 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 Summary
Fields Modifier and Type Field Description protected DataModel
datamodel
DataModel for which de similarities must be computedprotected double[][]
similarities
Matrix that contains the similarity between each pair of items
-
Constructor Summary
Constructors Constructor Description ItemSimilarityMetric()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
afterRun()
Is executed once after execute the method exec.void
beforeRun()
Is executed once before execute the method 'exec'.double[]
getSimilarities(int itemIndex)
Returns the similarity array of an item.void
run(Item item)
Is executed once for each object in the array of objects passed as parameter in the exec method of the Parallelizer class.void
setDatamodel(DataModel datamodel)
Sets the DataModel for which the similarity are going to be computedabstract double
similarity(Item item, Item otherItem)
This method must returns the similarity between two items.String
toString()
-
-
-
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
-
-
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 itemotherItem
- 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.
-
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.
-
afterRun
public void afterRun()
Description copied from interface:Partible
Is executed once after execute the method exec. It can be used to close resources.
-
-