public class ArcCosineUnitlengthDistanceFunction extends java.lang.Object implements SpatialPrimitiveDistanceFunction<NumberVector>, NumberVectorDistanceFunction<NumberVector>
The arc cosine distance is computed as the arcus from the cosine similarity
value, i.e., arccos(<v1,v2>)
.
Cosine similarity is defined as \[ \tfrac{\vec{x}\cdot\vec{y}}{||a||\cdot||b||} =_{||a||=||b||=1} \vec{x}\cdot\vec{y} \] Arcus cosine distance then is \[ \operatorname{arccos} \tfrac{\vec{x}\cdot\vec{y}}{||a||\cdot||b||} =_{||a||=||b||=1} \operatorname{arccos} \vec{x}\cdot\vec{y} \in [0;\pi] \]
This implementation assumes that \(||a||=||b||=1\). If this does not
hold for your data, use ArcCosineDistanceFunction
instead!
CosineUnitlengthDistanceFunction
is a bit less expensive, and will
yield the same ranking of neighbors.
Modifier and Type | Class and Description |
---|---|
static class |
ArcCosineUnitlengthDistanceFunction.Parameterizer
Parameterization class.
|
Modifier and Type | Field and Description |
---|---|
static ArcCosineUnitlengthDistanceFunction |
STATIC
Static instance
|
Constructor and Description |
---|
ArcCosineUnitlengthDistanceFunction()
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 ArcCosineUnitlengthDistanceFunction STATIC
@Deprecated public ArcCosineUnitlengthDistanceFunction()
STATIC
instead.public double distance(NumberVector v1, NumberVector v2)
The cosine distance is computed as the arcus from the cosine similarity
value, i.e., arccos(<v1,v2>)
.
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.