## Class TriangularDistance

• All Implemented Interfaces:
Distance<NumberVector>, NumberVectorDistance<NumberVector>, PrimitiveDistance<NumberVector>, SpatialPrimitiveDistance<NumberVector>

@Reference(authors="R. Connor, F. A. Cardillo, L. Vadicamo, F. Rabitti",
title="Hilbert Exclusion: Improved Metric Search through Finite Isometric Embeddings",
booktitle="arXiv preprint arXiv:1604.08640",
url="http://arxiv.org/abs/1604.08640",
bibkey="DBLP:journals/corr/ConnorCVR16")
public class TriangularDistance
extends TriangularDiscriminationDistance
Triangular Distance has relatively tight upper and lower bounds to the (square root of the) Jensen-Shannon divergence, but is much less expensive.

$\text{Triangular-Distance}(\vec{x},\vec{y}):=\sqrt{ \sum\nolimits_i \tfrac{|x_i-y_i|^2}{x_i+y_i}}$

This distance function is meant for distribution vectors that sum to 1, and does not work on negative values.

This differs from TriangularDistance simply by the square root, which makes it a proper metric and a good approximation for the much more expensive SqrtJensenShannonDivergenceDistance.

Reference:

R. Connor, F. A. Cardillo, L. Vadicamo, F. Rabitti
Hilbert Exclusion: Improved Metric Search through Finite Isometric Embeddings
arXiv preprint arXiv:1604.08640

TODO: support sparse vectors, varying length

Since:
0.7.5
Author:
Erich Schubert
• ### Nested Class Summary

Nested Classes
Modifier and Type Class Description
static class  TriangularDistance.Par
Parameterization class, using the static instance.
• ### Field Summary

Fields
Modifier and Type Field Description
static TriangularDistance STATIC
Static instance.
• ### Constructor Summary

Constructors
Modifier Constructor Description
private  TriangularDistance()
Deprecated.
• ### Method Summary

All 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 equals​(java.lang.Object obj)
int hashCode()
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.AbstractNumberVectorDistance

dimensionality, dimensionality, dimensionality, dimensionality, dimensionality, dimensionality, dimensionality, dimensionality, getInputTypeRestriction
• ### 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.PrimitiveDistance

getInputTypeRestriction
• ### Methods inherited from interface elki.distance.SpatialPrimitiveDistance

instantiate
• ### Field Detail

• #### STATIC

public static final TriangularDistance STATIC
Static instance. Use this!
• ### Constructor Detail

• #### TriangularDistance

@Deprecated
private TriangularDistance()
Deprecated.
Deprecated constructor: use the static instance STATIC 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 interface NumberVectorDistance<NumberVector>
Specified by:
distance in interface PrimitiveDistance<NumberVector>
Overrides:
distance in class TriangularDiscriminationDistance
Parameters:
v1 - first DatabaseObject
v2 - 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 interface SpatialPrimitiveDistance<NumberVector>
Overrides:
minDist in class TriangularDiscriminationDistance
Parameters:
mbr1 - the first MBR object
mbr2 - the second MBR object
Returns:
the distance between the two given MBRs according to this distance function
• #### 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 interface Distance<NumberVector>
Overrides:
isSquared in class TriangularDiscriminationDistance
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.
• #### toString

public java.lang.String toString()
Overrides:
toString in class TriangularDiscriminationDistance
• #### equals

public boolean equals​(java.lang.Object obj)
Overrides:
equals in class TriangularDiscriminationDistance
• #### hashCode

public int hashCode()
Overrides:
hashCode in class TriangularDiscriminationDistance