com.aliasi.matrix

## Class EuclideanDistance

• All Implemented Interfaces:
Distance<Vector>, Serializable

```public class EuclideanDistance
extends Object
implements Distance<Vector>, Serializable```
The `EuclideanDistance` class implements standard Euclidean distance between vectors. Euclidean distance forms a metric. Euclidean distance is often called the `L2` distance, because it is 2-norm Minkowski distance.

The definition of Euclidean distance over vectors `v1` and `v2` is:

``` distance(v1,v2) = sqrt(Σi (v1[i] - v2[i])2  )
```
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.

Note that the Euclidean distance is equivalent to the Minkowski distance metric of order 2. See the class documentation for `MinkowskiDistance` for more information.

An understandable explanation of Euclidean and related distances may be found at:

Since:
LingPipe3.1
Version:
3.1
Author:
Bob Carpenter
Serialized Form
• ### Field Summary

Fields
Modifier and Type Field and Description
`static EuclideanDistance` `DISTANCE`
The Euclidean distance.
• ### Constructor Summary

Constructors
Constructor and Description
`EuclideanDistance()`
Construct a new Euclidean distance.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`double` ```distance(Vector v1, Vector v2)```
Returns the Euclidean 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 EuclideanDistance DISTANCE`
The Euclidean distance. All instances of Euclidean distance perform the same function. Because the distance function is thread safe, this instance may be used wherever Euclidean distance is needed.
• ### Constructor Detail

• #### EuclideanDistance

`public EuclideanDistance()`
Construct a new Euclidean distance.
• ### Method Detail

• #### distance

```public double distance(Vector v1,
Vector v2)```
Returns the Euclidean 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.