com.aliasi.matrix
Class TaxicabDistance

java.lang.Object
  extended by com.aliasi.matrix.TaxicabDistance
All Implemented Interfaces:
Distance<Vector>, Serializable

public class TaxicabDistance
extends Object
implements Distance<Vector>, Serializable

The TaxicabDistance class implements standard taxicab, or Manhattan distance between vectors. The taxicab distance forms a metric. The taxicab distance is often called the L1 distance, because it is 1-norm Minkowski distance after the inventor of the general family of vector distance metrics and related geometries.

The definition of the taxicab distance over vectors v1 and v2 is:

 distance(v1,v2) = Σi abs(v1[i] - v2[i])
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 taxicab distance and related distances may be found at:

Since:
LingPipe3.1
Version:
3.8
Author:
Bob Carpenter
See Also:
Serialized Form

Field Summary
static TaxicabDistance DISTANCE
          The taxicab distance.
 
Constructor Summary
TaxicabDistance()
          Construct a new taxicab distance.
 
Method Summary
 double distance(Vector v1, Vector v2)
          Returns the taxicab distance between the specified pair of vectors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DISTANCE

public static final TaxicabDistance DISTANCE
The taxicab distance. All instances of taxicab distance perform the same function. Because the distance function is thread safe, this instance may be used wherever taxicab distance is needed.

Constructor Detail

TaxicabDistance

public TaxicabDistance()
Construct a new taxicab distance.

Method Detail

distance

public double distance(Vector v1,
                       Vector v2)
Returns the taxicab distance between the specified pair of vectors. See the class definition above for details.

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.