public class CosineDistanceMetric extends AbstractCloneableSerializable implements Semimetric<Vectorizable>
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||)Modifier and Type | Field and Description |
---|---|
static CosineDistanceMetric |
INSTANCE
An instance of
CosineDistanceMetric to use since this class has
no internal data. |
Constructor and Description |
---|
CosineDistanceMetric()
Creates a new instance of
CosineDistanceMetric . |
Modifier and Type | Method and Description |
---|---|
double |
evaluate(Vectorizable first,
Vectorizable second)
Evaluates the cosine distance between the two given vectors.
|
clone
public static final CosineDistanceMetric INSTANCE
CosineDistanceMetric
to use since this class has
no internal data.public CosineDistanceMetric()
CosineDistanceMetric
.public double evaluate(Vectorizable first, Vectorizable second)
evaluate
in interface DivergenceFunction<Vectorizable,Vectorizable>
first
- The first Vector.second
- The second Vector.