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.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final CosineSimilarity | INSTANCE
The singleton instance. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Double | Returns: cosine similarity between the two vectors.left vector. leftVector, final Map<CharSequence, Integer> right vector. rightVector)Calculates the cosine similarity for two given vectors. |
| private double | Returns: The dot product.left vector. leftVector, final Map<CharSequence, Integer> right vector. rightVector, final Set<CharSequence> common elements. intersection)Computes the dot product of two vectors. |
| private Set | Returns: common strings.left vector map. leftVector, final Map<CharSequence, Integer> right vector map. rightVector)Returns a set with keys common to the two given maps. |
| INSTANCE | back to summary |
|---|---|
| pack-priv static final CosineSimilarity INSTANCE The singleton instance. | |
| CosineSimilarity | back to summary |
|---|---|
| public CosineSimilarity() Construct a new instance. | |
| cosineSimilarity | back to summary |
|---|---|
| public Double cosineSimilarity(final Map<CharSequence, Integer> leftVector, final Map<CharSequence, Integer> rightVector) Calculates the cosine similarity for two given vectors.
| |
| dot | back to summary |
|---|---|
| private double dot(final Map<CharSequence, Integer> leftVector, final Map<CharSequence, Integer> rightVector, final Set<CharSequence> intersection) Computes the dot product of two vectors. It ignores remaining elements. It means that if a vector is longer than other, then a smaller part of it will be used to compute the dot product.
| |
| getIntersection | back to summary |
|---|---|
| private Set Returns a set with keys common to the two given maps.
| |