Class CosineDistance<T>

java.lang.Object
com.oracle.coherence.ai.distance.AbstractDistance<T>
com.oracle.coherence.ai.distance.CosineDistance<T>
All Implemented Interfaces:
DistanceAlgorithm<T>, ExternalizableLite, PortableObject, Serializable

public class CosineDistance<T> extends AbstractDistance<T>
A DistanceAlgorithm that performs a cosine similarity calculation between two vectors.

Cosine similarity measures the similarity between two vectors of an inner product space. It is measured by the cosine of the angle between two vectors and determines whether two vectors are pointing in roughly the same direction. It is often used to measure document similarity in text analysis.

See Also:
  • Constructor Details

    • CosineDistance

      public CosineDistance()
  • Method Details

    • distance

      protected double distance(BitSet v1, BitSet v2)
      Description copied from class: AbstractDistance
      Calculate the distance between two bit vectors.
      Specified by:
      distance in class AbstractDistance<T>
      Parameters:
      v1 - the first bit vector
      v2 - the second bit vector
      Returns:
      the distance between the two bit vectors
    • distance

      protected double distance(byte[] v1, byte[] v2)
      Description copied from class: AbstractDistance
      Calculate the distance between two Int8 (byte) vectors.
      Specified by:
      distance in class AbstractDistance<T>
      Parameters:
      v1 - the first Int8 vector
      v2 - the second Int8 vector
      Returns:
      the distance between the two Int8 vectors
    • distance

      protected double distance(float[] v1, float[] v2)
      Description copied from class: AbstractDistance
      Calculate the distance between two Float32 (float) vectors.
      Specified by:
      distance in class AbstractDistance<T>
      Parameters:
      v1 - the first Float32 vector
      v2 - the second Float32 vector
      Returns:
      the distance between the two Float32 vectors