Package elki.distance
Class SqrtCosineDistance
- java.lang.Object
-
- elki.distance.CosineDistance
-
- elki.distance.SqrtCosineDistance
-
- All Implemented Interfaces:
Distance<NumberVector>
,NumberVectorDistance<NumberVector>
,PrimitiveDistance<NumberVector>
,SpatialPrimitiveDistance<NumberVector>
public class SqrtCosineDistance extends CosineDistance
Cosine distance function for feature vectors using the square root.The cosine distance is computed from the cosine similarity by
sqrt(1-cosine similarity)
.Cosine similarity is defined as \[ \tfrac{\vec{x}\cdot\vec{y}}{||a||\cdot||b||} \] This versions of cosine distance then is defined as \[ \sqrt{2 - 2\tfrac{\vec{x}\cdot\vec{y}}{||a||\cdot||b||}} \in [0;2] \]
Because of the square root, this is more expensive than regular cosine, but because this corresponds to Euclidean distance on normalized vectors, it is a metric on normalized vectors.
- Since:
- 0.1
- Author:
- Erich Schubert
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SqrtCosineDistance.Par
Parameterization class.
-
Field Summary
Fields Modifier and Type Field Description static SqrtCosineDistance
STATIC
Static instance
-
Constructor Summary
Constructors Constructor Description SqrtCosineDistance()
Deprecated.Use static instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
distance(NumberVector v1, NumberVector v2)
Computes the distance between two given DatabaseObjects according to this distance function.boolean
isMetric()
Is this distance function metric (satisfy the triangle inequality)boolean
isSquared()
Squared distances, that would become metric after square root.double
minDist(SpatialComparable mbr1, SpatialComparable mbr2)
Computes the distance between the two given MBRs according to this distance function.java.lang.String
toString()
-
Methods inherited from class elki.distance.CosineDistance
equals, getInputTypeRestriction, hashCode
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface elki.distance.Distance
isSymmetric
-
Methods inherited from interface elki.distance.SpatialPrimitiveDistance
instantiate
-
-
-
-
Field Detail
-
STATIC
public static final SqrtCosineDistance STATIC
Static instance
-
-
Constructor Detail
-
SqrtCosineDistance
@Deprecated public SqrtCosineDistance()
Deprecated.Use static instanceConstructor - useSTATIC
instead.
-
-
Method Detail
-
distance
public double distance(NumberVector v1, NumberVector v2)
Description copied from interface:PrimitiveDistance
Computes the distance between two given DatabaseObjects according to this distance function.- Specified by:
distance
in interfaceNumberVectorDistance<NumberVector>
- Specified by:
distance
in interfacePrimitiveDistance<NumberVector>
- Overrides:
distance
in classCosineDistance
- 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:SpatialPrimitiveDistance
Computes the distance between the two given MBRs according to this distance function.- Specified by:
minDist
in interfaceSpatialPrimitiveDistance<NumberVector>
- Overrides:
minDist
in classCosineDistance
- 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:
toString
in classCosineDistance
-
isSquared
public boolean isSquared()
Description copied from interface:Distance
Squared distances, that would become metric after square root.E.g. squared Euclidean.
- Specified by:
isSquared
in interfaceDistance<NumberVector>
- Overrides:
isSquared
in classCosineDistance
- Returns:
true
when squared.
-
isMetric
public boolean isMetric()
Description copied from interface:Distance
Is this distance function metric (satisfy the triangle inequality)- Returns:
true
when metric.
-
-