@Priority(value=100) @Alias(value="cosine") public class CosineDistanceFunction extends java.lang.Object implements SpatialPrimitiveDistanceFunction<NumberVector>, NumberVectorDistanceFunction<NumberVector>
The cosine distance is computed from the cosine similarity by
1-(cosine similarity)
.
Cosine similarity is defined as \[ \tfrac{\vec{x}\cdot\vec{y}}{||a||\cdot||b||} \] Cosine distance then is defined as \[ 1 - \tfrac{\vec{x}\cdot\vec{y}}{||a||\cdot||b||} \in [0;2] \]
ArcCosineDistanceFunction
may sometimes be more appropriate, but also
more computationally expensive.
Modifier and Type | Class and Description |
---|---|
static class |
CosineDistanceFunction.Parameterizer
Parameterization class.
|
Modifier and Type | Field and Description |
---|---|
static CosineDistanceFunction |
STATIC
Static instance
|
Constructor and Description |
---|
CosineDistanceFunction()
Deprecated.
Use static instance
|
Modifier and Type | Method and Description |
---|---|
double |
distance(NumberVector v1,
NumberVector v2)
Computes the cosine distance for two given feature vectors.
|
boolean |
equals(java.lang.Object obj) |
SimpleTypeInformation<? super NumberVector> |
getInputTypeRestriction()
Get the input data type of the function.
|
int |
hashCode() |
double |
minDist(SpatialComparable mbr1,
SpatialComparable mbr2)
Computes the distance between the two given MBRs according to this distance
function.
|
java.lang.String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
instantiate
isMetric, isSquared, isSymmetric
public static final CosineDistanceFunction STATIC
@Deprecated public CosineDistanceFunction()
STATIC
instead.public double distance(NumberVector v1, NumberVector v2)
1-(cosine similarity)
.distance
in interface NumberVectorDistanceFunction<NumberVector>
distance
in interface PrimitiveDistanceFunction<NumberVector>
v1
- first feature vectorv2
- second feature vectorpublic double minDist(SpatialComparable mbr1, SpatialComparable mbr2)
SpatialPrimitiveDistanceFunction
minDist
in interface SpatialPrimitiveDistanceFunction<NumberVector>
mbr1
- the first MBR objectmbr2
- the second MBR objectpublic java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public SimpleTypeInformation<? super NumberVector> getInputTypeRestriction()
DistanceFunction
getInputTypeRestriction
in interface DistanceFunction<NumberVector>
getInputTypeRestriction
in interface PrimitiveDistanceFunction<NumberVector>
Copyright © 2019 ELKI Development Team. License information.