@Shareable public class PearsonCorrelation extends Object implements VectorSimilarity, Serializable
This class implements the Pearson correlation similarity function over sparse vectors. Only the items occurring in both vectors are considered when computing the variance.
See Desrosiers, C. and Karypis, G., A Comprehensive Survey of Neighborhood-based Recommendation Methods. In Ricci, F., Rokach, L., Shapira, B., and Kantor, P. (eds.), RecommenderEngine Systems Handbook, Springer. 2010, pp. 107-144.
Constructor and Description |
---|
PearsonCorrelation() |
PearsonCorrelation(double s) |
Modifier and Type | Method and Description |
---|---|
boolean |
isSparse()
Query whether this similarity function is sparse (returns 0 for vectors with
disjoint key sets).
|
boolean |
isSymmetric()
Query whether this similarity function is symmetric.
|
double |
similarity(SparseVector vec1,
SparseVector vec2)
Compute the similarity between two vectors.
|
String |
toString() |
public PearsonCorrelation()
@Inject public PearsonCorrelation(@SimilarityDamping double s)
public double similarity(SparseVector vec1, SparseVector vec2)
VectorSimilarity
similarity
in interface VectorSimilarity
vec1
- The left vector to compare.vec2
- The right vector to compare.public boolean isSparse()
VectorSimilarity
isSparse
in interface VectorSimilarity
true
iff VectorSimilarity.similarity(SparseVector, SparseVector)
will always return
true when applied to two vectors with no keys in common.public boolean isSymmetric()
VectorSimilarity
isSymmetric
in interface VectorSimilarity
true
if the function is symmetric.