@Shareable public class CosineVectorSimilarity extends Object implements VectorSimilarity, Serializable
Cosine similarity for vectors.
Constructor and Description |
---|
CosineVectorSimilarity()
Construct an undamped cosine similarity function.
|
CosineVectorSimilarity(double damping)
Construct a new cosine similarity function.
|
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 CosineVectorSimilarity()
Construct an undamped cosine similarity function.
@Inject public CosineVectorSimilarity(@SimilarityDamping double damping)
Construct a new cosine similarity function.
damping
- The Bayesian damping term (added to denominator), to bias the similarity towards 0 for low-cooccurance vectors.public double similarity(SparseVector vec1, SparseVector vec2)
VectorSimilarity
Compute the similarity between two vectors.
similarity
in interface VectorSimilarity
vec1
- The left vector to compare.vec2
- The right vector to compare.public boolean isSparse()
VectorSimilarity
Query whether this similarity function is sparse (returns 0 for vectors with disjoint key sets).
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
Query whether this similarity function is symmetric. Symmetric similarity functions return the same result when called on (A,B) and (B,A).
isSymmetric
in interface VectorSimilarity
true
if the function is symmetric.