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, wait
instantiate
isMetric, isSquared, isSymmetric
public 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)
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.