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 forNumberVector
s.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 class
LPNormDistance.Par
Parameterization 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 double
distance(NumberVector v1, NumberVector v2)
Computes the distance between two given DatabaseObjects according to this distance function.boolean
equals(java.lang.Object obj)
SimpleTypeInformation<? super NumberVector>
getInputTypeRestriction()
Get the input data type of the function.double
getInvP()
Get the functions 1/p parameter.double
getP()
Get the functions p parameter.int
hashCode()
boolean
isMetric()
Is this distance function metric (satisfy the triangle inequality)double
minDist(SpatialComparable mbr1, SpatialComparable mbr2)
Computes the distance between the two given MBRs according to this distance function.double
norm(NumberVector v)
Compute the norm of object obj.private double
preDistance(NumberVector v1, NumberVector v2, int start, int end)
Compute unscaled distance in a range of dimensions.private double
preDistanceMBR(SpatialComparable mbr1, SpatialComparable mbr2, int start, int end)
Compute unscaled distance in a range of dimensions.private double
preDistanceVM(NumberVector v, SpatialComparable mbr, int start, int end)
Compute unscaled distance in a range of dimensions.private double
preNorm(NumberVector v, int start, int end)
Compute unscaled norm in a range of dimensions.private double
preNormMBR(SpatialComparable mbr, int start, int end)
Compute unscaled norm in a range of dimensions.java.lang.String
toString()
-
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: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>
- 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:Norm
Compute the norm of object obj.- Specified by:
norm
in interfaceNorm<NumberVector>
- Parameters:
v
- Object- Returns:
- Norm
-
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>
- 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:Distance
Is this distance function metric (satisfy the triangle inequality)- Specified by:
isMetric
in interfaceDistance<NumberVector>
- Returns:
true
when metric.
-
toString
public java.lang.String toString()
- Overrides:
toString
in 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:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
getInputTypeRestriction
public SimpleTypeInformation<? super NumberVector> getInputTypeRestriction()
Description copied from interface:Distance
Get the input data type of the function.- Specified by:
getInputTypeRestriction
in interfaceDistance<NumberVector>
- Specified by:
getInputTypeRestriction
in interfacePrimitiveDistance<NumberVector>
- Returns:
- Type restriction
-
-