Package elki.distance
Class ArcCosineUnitlengthDistance
- java.lang.Object
-
- elki.distance.ArcCosineUnitlengthDistance
-
- All Implemented Interfaces:
Distance<NumberVector>,NumberVectorDistance<NumberVector>,PrimitiveDistance<NumberVector>,SpatialPrimitiveDistance<NumberVector>
public class ArcCosineUnitlengthDistance extends java.lang.Object implements SpatialPrimitiveDistance<NumberVector>, NumberVectorDistance<NumberVector>
Arcus cosine distance function for feature vectors.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
ArcCosineDistanceinstead!CosineUnitlengthDistanceandSqrtCosineUnitlengthDistanceare a bit less expensive to compute, and will yield the same ranking of neighbors.- Since:
- 0.7.5
- Author:
- Erich Schubert
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classArcCosineUnitlengthDistance.ParParameterization class.
-
Field Summary
Fields Modifier and Type Field Description static ArcCosineUnitlengthDistanceSTATICStatic instance
-
Constructor Summary
Constructors Constructor Description ArcCosineUnitlengthDistance()Deprecated.Use static instance!
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doubledistance(NumberVector v1, NumberVector v2)Computes the distance between two given DatabaseObjects according to this distance function.booleanequals(java.lang.Object obj)SimpleTypeInformation<? super NumberVector>getInputTypeRestriction()Get the input data type of the function.inthashCode()doubleminDist(SpatialComparable mbr1, SpatialComparable mbr2)Computes the distance between the two given MBRs according to this distance function.java.lang.StringtoString()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface elki.distance.Distance
isMetric, isSquared, isSymmetric
-
Methods inherited from interface elki.distance.SpatialPrimitiveDistance
instantiate
-
-
-
-
Field Detail
-
STATIC
public static final ArcCosineUnitlengthDistance STATIC
Static instance
-
-
Constructor Detail
-
ArcCosineUnitlengthDistance
@Deprecated public ArcCosineUnitlengthDistance()
Deprecated.Use static instance!Constructor - useSTATICinstead.
-
-
Method Detail
-
distance
public double distance(NumberVector v1, NumberVector v2)
Description copied from interface:PrimitiveDistanceComputes the distance between two given DatabaseObjects according to this distance function.- Specified by:
distancein interfaceNumberVectorDistance<NumberVector>- Specified by:
distancein interfacePrimitiveDistance<NumberVector>- Parameters:
v1- first DatabaseObjectv2- second DatabaseObject- Returns:
- the distance between two given DatabaseObjects according to this distance function
-
minDist
public double minDist(SpatialComparable mbr1, SpatialComparable mbr2)
Description copied from interface:SpatialPrimitiveDistanceComputes the distance between the two given MBRs according to this distance function.- Specified by:
minDistin interfaceSpatialPrimitiveDistance<NumberVector>- Parameters:
mbr1- the first MBR objectmbr2- the second MBR object- Returns:
- the distance between the two given MBRs according to this distance function
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
getInputTypeRestriction
public SimpleTypeInformation<? super NumberVector> getInputTypeRestriction()
Description copied from interface:DistanceGet the input data type of the function.- Specified by:
getInputTypeRestrictionin interfaceDistance<NumberVector>- Specified by:
getInputTypeRestrictionin interfacePrimitiveDistance<NumberVector>- Returns:
- Type restriction
-
-