public class Similarity extends Object
| Constructor and Description |
|---|
Similarity() |
| Modifier and Type | Method and Description |
|---|---|
static double |
cosine(float[] a,
float[] b)
Calculates cosine similarity between two vectors.
|
public static double cosine(float[] a,
float[] b)
Cosine similarity measures the cosine of the angle between two vectors, indicating their directional similarity. It produces a value in the range: - -1 indicates vectors are diametrically opposed (opposite directions). - 0 indicates vectors are orthogonal (no directional similarity). - 1 indicates vectors are pointing in the same direction (but not necessarily of the same magnitude).
Not to be confused with cosine distance ([0..2]), which quantifies how different two vectors are.
a - first vectorb - second vectorCopyright © 2023. All rights reserved.