com.aliasi.matrix

## Class MinkowskiDistance

• All Implemented Interfaces:
Distance<Vector>, Serializable

```public class MinkowskiDistance
extends Object
implements Distance<Vector>, Serializable```
The `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:

` distance(v1,v2,p) = (Σi abs(v1[i] - v2[i])p)(1/p)`
with `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:

Since:
LingPipe3.1
Version:
3.8
Author:
Bob Carpenter
Serialized Form
• ### Constructor Summary

Constructors
Constructor and Description
`MinkowskiDistance(int order)`
Construct a new Minkowski distance of the specified order.
• ### Method Summary

All Methods
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.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Constructor Detail

• #### MinkowskiDistance

`public MinkowskiDistance(int order)`
Construct a new Minkowski distance of the specified order.
Parameters:
`order` - Order of metric.
Throws:
`IllegalArgumentException` - If the order is not 1 or greater.
• ### Method Detail

• #### order

`public int order()`
Returns the order of this Minkowski distance.
Returns:
The order of this Minkowski distance.
• #### distance

```public double distance(Vector v1,
Vector v2)```
Returns the Minkowski distance between the specified pair of vectors.
Specified by:
`distance` in interface `Distance<Vector>`
Parameters:
`v1` - First vector.
`v2` - Second vector.
Returns:
The distance between the vectors.
Throws:
`IllegalArgumentException` - If the vectors are not of the same dimensionality.