gov.sandia.cognition.learning.function.distance
Class CosineDistanceMetric

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.learning.function.distance.CosineDistanceMetric
All Implemented Interfaces:
DivergenceFunction<Vectorizable,Vectorizable>, Semimetric<Vectorizable>, CloneableSerializable, Serializable, Cloneable

public class CosineDistanceMetric
extends AbstractCloneableSerializable
implements Semimetric<Vectorizable>

The CosineDistanceMetric class implements a semimetric between two vectors based on the cosine between the vectors. Since cosine is typically used as a similarity measure, to convert it to a semimetric, one minus the cosine is computed. d(x, y) = 1.0 - cos(x, y) = 1.0 - (x * y) / (||x|| * ||y||)

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

Field Summary
static CosineDistanceMetric INSTANCE
          An instance of CosineDistanceMetric to use since this class has no internal data.
 
Constructor Summary
CosineDistanceMetric()
          Creates a new instance of CosineDistanceMetric.
 
Method Summary
 double evaluate(Vectorizable first, Vectorizable second)
          Evaluates the cosine distance between the two given vectors.
 
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
 
Methods inherited from interface gov.sandia.cognition.util.CloneableSerializable
clone
 

Field Detail

INSTANCE

public static final CosineDistanceMetric INSTANCE
An instance of CosineDistanceMetric to use since this class has no internal data.

Constructor Detail

CosineDistanceMetric

public CosineDistanceMetric()
Creates a new instance of CosineDistanceMetric.

Method Detail

evaluate

public double evaluate(Vectorizable first,
                       Vectorizable second)
Evaluates the cosine distance between the two given vectors.

Specified by:
evaluate in interface DivergenceFunction<Vectorizable,Vectorizable>
Parameters:
first - The first Vector.
second - The second Vector.
Returns:
The cosine distance between the two given vectors.