public class CosineUnitlengthDistanceFunction 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||} =_{||a||=||b||=1} \vec{x}\cdot\vec{y} \] Cosine distance then is defined as \[ 1 - \tfrac{\vec{x}\cdot\vec{y}}{||a||\cdot||b||} =_{||a||=||b||=1} 1-\vec{x}\cdot\vec{y} \in [0;2] \]
This implementation assumes that \(||a||=||b||=1\). If this does not
hold for your data, use CosineDistanceFunction instead!
ArcCosineUnitlengthDistanceFunction may sometimes be more
appropriate, but also more computationally expensive.
| Modifier and Type | Class and Description |
|---|---|
static class |
CosineUnitlengthDistanceFunction.Parameterizer
Parameterization class.
|
| Modifier and Type | Field and Description |
|---|---|
static CosineUnitlengthDistanceFunction |
STATIC
Static instance
|
| Constructor and Description |
|---|
CosineUnitlengthDistanceFunction()
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, waitinstantiateisMetric, isSquared, isSymmetricpublic static final CosineUnitlengthDistanceFunction STATIC
@Deprecated public CosineUnitlengthDistanceFunction()
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)
SpatialPrimitiveDistanceFunctionminDist in interface SpatialPrimitiveDistanceFunction<NumberVector>mbr1 - the first MBR objectmbr2 - the second MBR objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic SimpleTypeInformation<? super NumberVector> getInputTypeRestriction()
DistanceFunctiongetInputTypeRestriction in interface DistanceFunction<NumberVector>getInputTypeRestriction in interface PrimitiveDistanceFunction<NumberVector>Copyright © 2019 ELKI Development Team. License information.