Package elki.distance.minkowski
Class LPNormDistance
- java.lang.Object
-
- elki.distance.minkowski.LPNormDistance
-
- All Implemented Interfaces:
Distance<NumberVector>,Norm<NumberVector>,NumberVectorDistance<NumberVector>,PrimitiveDistance<NumberVector>,SpatialPrimitiveDistance<NumberVector>
- Direct Known Subclasses:
LPIntegerNormDistance,MaximumDistance,WeightedLPNormDistance
@Priority(200) @Alias({"lp","minkowski","p"}) public class LPNormDistance extends java.lang.Object implements SpatialPrimitiveDistance<NumberVector>, NumberVectorDistance<NumberVector>, Norm<NumberVector>
Lp-Norm (Minkowski norms) are a family of distances forNumberVectors.The Lp distance is defined as: \[ L_p(\vec{x},\vec{y}) := \left(\sum\nolimits_i (x_i-y_i)\right)^{1/p} \]
For p >= 1 this is a metric. For p=1, this yields the well known
ManhattanDistance, for p = 2 the standardEuclideanDistance.- Since:
- 0.1
- Author:
- Arthur Zimek
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLPNormDistance.ParParameterization class.
-
Constructor Summary
Constructors Constructor Description LPNormDistance(double p)Constructor, internal version.
-
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.doublegetInvP()Get the functions 1/p parameter.doublegetP()Get the functions p parameter.inthashCode()booleanisMetric()Is this distance function metric (satisfy the triangle inequality)doubleminDist(SpatialComparable mbr1, SpatialComparable mbr2)Computes the distance between the two given MBRs according to this distance function.doublenorm(NumberVector v)Compute the norm of object obj.private doublepreDistance(NumberVector v1, NumberVector v2, int start, int end)Compute unscaled distance in a range of dimensions.private doublepreDistanceMBR(SpatialComparable mbr1, SpatialComparable mbr2, int start, int end)Compute unscaled distance in a range of dimensions.private doublepreDistanceVM(NumberVector v, SpatialComparable mbr, int start, int end)Compute unscaled distance in a range of dimensions.private doublepreNorm(NumberVector v, int start, int end)Compute unscaled norm in a range of dimensions.private doublepreNormMBR(SpatialComparable mbr, int start, int end)Compute unscaled norm in a range of dimensions.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
isSquared, isSymmetric
-
Methods inherited from interface elki.distance.SpatialPrimitiveDistance
instantiate
-
-
-
-
Method Detail
-
preDistance
private double preDistance(NumberVector v1, NumberVector v2, int start, int end)
Compute unscaled distance in a range of dimensions.- Parameters:
v1- First objectv2- Second objectstart- First dimensionend- Exclusive last dimension- Returns:
- Aggregated values.
-
preDistanceVM
private double preDistanceVM(NumberVector v, SpatialComparable mbr, int start, int end)
Compute unscaled distance in a range of dimensions.- Parameters:
v- First vectormbr- Second MBRstart- First dimensionend- Exclusive last dimension- Returns:
- Aggregated values.
-
preDistanceMBR
private double preDistanceMBR(SpatialComparable mbr1, SpatialComparable mbr2, int start, int end)
Compute unscaled distance in a range of dimensions.- Parameters:
mbr1- First MBRmbr2- Second MBRstart- First dimensionend- Exclusive last dimension- Returns:
- Aggregated values.
-
preNorm
private double preNorm(NumberVector v, int start, int end)
Compute unscaled norm in a range of dimensions.- Parameters:
v- Data objectstart- First dimensionend- Exclusive last dimension- Returns:
- Aggregated values.
-
preNormMBR
private double preNormMBR(SpatialComparable mbr, int start, int end)
Compute unscaled norm in a range of dimensions.- Parameters:
mbr- Data objectstart- First dimensionend- Exclusive last dimension- Returns:
- Aggregated values.
-
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
-
norm
public double norm(NumberVector v)
Description copied from interface:NormCompute the norm of object obj.- Specified by:
normin interfaceNorm<NumberVector>- Parameters:
v- Object- Returns:
- Norm
-
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
-
isMetric
public boolean isMetric()
Description copied from interface:DistanceIs this distance function metric (satisfy the triangle inequality)- Specified by:
isMetricin interfaceDistance<NumberVector>- Returns:
truewhen metric.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getP
public double getP()
Get the functions p parameter.- Returns:
- p
-
getInvP
public double getInvP()
Get the functions 1/p parameter.- Returns:
- 1/p
-
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
-
-