gov.sandia.cognition.text.term.vector
Class CosineSimilarityFunction

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.text.term.vector.CosineSimilarityFunction
All Implemented Interfaces:
SimilarityFunction<Vectorizable,Vectorizable>, CloneableSerializable, Serializable, Cloneable

public class CosineSimilarityFunction
extends AbstractCloneableSerializable
implements SimilarityFunction<Vectorizable,Vectorizable>

A vector cosine similarity function. The function is computed as: f(x, y) = (x * y) / (||x|| ||y||)

Since:
3.0
Author:
Justin Basilico
See Also:
Serialized Form

Constructor Summary
CosineSimilarityFunction()
          Creates a new CosineSimilarityFunction.
 
Method Summary
 CosineDistanceMetric asDivergence()
          Converts the similarity function into a divergence function.
 double evaluate(Vectorizable from, Vectorizable to)
          Evaluates the similarity between the two given objects.
static CosineSimilarityFunction getInstance()
          Gets a singleton instance of the class.
 
Methods inherited from class gov.sandia.cognition.util.AbstractCloneableSerializable
clone
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CosineSimilarityFunction

public CosineSimilarityFunction()
Creates a new CosineSimilarityFunction.

Method Detail

getInstance

public static CosineSimilarityFunction getInstance()
Gets a singleton instance of the class.

Returns:
A singleton instance of the class.

evaluate

public double evaluate(Vectorizable from,
                       Vectorizable to)
Description copied from interface: SimilarityFunction
Evaluates the similarity between the two given objects. Similarity between two objects is high if those objects are similar and low if they are not similar. Typically, this is a value that is greater than or equal to zero that is higher the more similar two objects are. If the two types are the same, then the rule f(x, y) = f(y, x) must apply.

Specified by:
evaluate in interface SimilarityFunction<Vectorizable,Vectorizable>
Parameters:
from - The object the similarity is from.
to - The object the similarity is to.
Returns:
The similarity between the two objects.

asDivergence

public CosineDistanceMetric asDivergence()
Description copied from interface: SimilarityFunction
Converts the similarity function into a divergence function. A diverge

Specified by:
asDivergence in interface SimilarityFunction<Vectorizable,Vectorizable>
Returns:
The divergence function version of this similarity function.