public class MinkowskiDistance extends Object implements Distance<Vector>, Serializable
MinkowskiDistance class implements Minkowski
distance of a fixed order between vectors. or Manhattan distance
between vectors. Minkowski distance of any order forms a metric.
The Minkowski distance of order p is often called
Lp or the p-norm distance.
Minkowski distance generalizes taxicab and Euclidean distance,
which are just the Minkowski distances of order 1 and 2
respectively. For orders 1 and 2, the taxicab and Euclidean
distance classes TaxicabDistance and EuclideanDistance are more efficient in that they do not require
exponentiation to be calculated.
The definition of Minkowski distance of order p
over vectors v1 and v2 is:
withdistance(v1,v2,p) = (Σi abs(v1[i] - v2[i])p)(1/p)
v1[i] standing for the method call
v1.value(i) and i ranging over the
dimensions of the vectors, which must be the same.
An understandable explanation of the Minkowski distances,
including the special cases of Taxicab (L1 norm)
and Euclidean (L2 norm) may be
found at:
| Constructor and Description |
|---|
MinkowskiDistance(int order)
Construct a new Minkowski distance of the specified order.
|
| Modifier and Type | Method and Description |
|---|---|
double |
distance(Vector v1,
Vector v2)
Returns the Minkowski distance between the specified pair
of vectors.
|
int |
order()
Returns the order of this Minkowski distance.
|
public MinkowskiDistance(int order)
order - Order of metric.IllegalArgumentException - If the order is not 1 or greater.public int order()
public double distance(Vector v1, Vector v2)
distance in interface Distance<Vector>v1 - First vector.v2 - Second vector.IllegalArgumentException - If the vectors are not of the
same dimensionality.Copyright © 2019 Alias-i, Inc.. All rights reserved.