CosineSimilarity (Apache Commons Text 1.13.0 API)
Description: declaration: package: org.apache.commons.text.similarity, class: CosineSimilarity

Package org.apache.commons.text.similarity

# Class CosineSimilarity

java.lang.Object
org.apache.commons.text.similarity.CosineSimilarity

public class CosineSimilarity extends Object
Measures the Cosine similarity of two vectors of an inner product space and compares the angle between them.

For further explanation about the Cosine Similarity, refer to https://en.wikipedia.org/wiki/Cosine_similarity.

Instances of this class are immutable and are safe for use by multiple concurrent threads.

Since:
  1.0

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CosineSimilarity()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Double`
  `cosineSimilarity(Map<CharSequence,Integer> leftVector, Map<CharSequence,Integer> rightVector)`
  Calculates the cosine similarity for two given vectors.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### CosineSimilarity

    public CosineSimilarity()

- ## Method Details

  - ### cosineSimilarity

    public Double cosineSimilarity(Map<CharSequence,Integer> leftVector, Map<CharSequence,Integer> rightVector)
    Calculates the cosine similarity for two given vectors.
    Parameters:
      `leftVector` - left vector
      `rightVector` - right vector
    Returns:
      cosine similarity between the two vectors