org.grouplens.lenskit.vectors.similarity

## Class MutualInformationVectorSimilarity

• java.lang.Object
• org.grouplens.lenskit.vectors.similarity.MutualInformationVectorSimilarity
• All Implemented Interfaces:
Serializable, VectorSimilarity

public class MutualInformationVectorSimilarity
extends Object
implements VectorSimilarity, Serializable

Similarity function that assumes the two vectors are paired samples from 2 correlated random variables. Using this we estimate the mutual information between the two variables.

Note, this uses the naive estimator of mutual information, which can be heavily biased when the two vectors have little overlap.

Serialized Form
• ### Constructor Summary

Constructors
Constructor and Description
MutualInformationVectorSimilarity(Quantizer quantizer)
Construct a new mutual information similarity.
• ### Method Summary

All Methods
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 similarity using mutual information.
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### MutualInformationVectorSimilarity

@Inject
public MutualInformationVectorSimilarity(Quantizer quantizer)

Construct a new mutual information similarity.

Parameters:
quantizer - A quantizer to allow discrete mutual information to be computed.
• ### Method Detail

• #### similarity

public double similarity(SparseVector vec1,
SparseVector vec2)

Compute similarity using mutual information.

Note, this similarity function measures the absolute correlation between two vectors. Because of this it ranges from [0,inf), not [-1,1] as specified by superclass. Caution should be used when using this vector similarity function that your implementation will accept values in this range.

Specified by:
similarity in interface VectorSimilarity
Parameters:
vec1 - The first vector.
vec2 - The second vector.
Returns:
The similarity between the two vectors, based on mutual information.
VectorSimilarity.similarity(SparseVector, SparseVector)
• #### isSparse

public boolean isSparse()
Description copied from interface: VectorSimilarity

Query whether this similarity function is sparse (returns 0 for vectors with disjoint key sets).

Specified by:
isSparse in interface VectorSimilarity
Returns:
true iff VectorSimilarity.similarity(SparseVector, SparseVector) will always return true when applied to two vectors with no keys in common.
• #### isSymmetric

public boolean isSymmetric()
Description copied from interface: VectorSimilarity

Query whether this similarity function is symmetric. Symmetric similarity functions return the same result when called on (A,B) and (B,A).

Specified by:
isSymmetric in interface VectorSimilarity
Returns:
true if the function is symmetric.