com.aliasi.matrix

## Class CosineDistance

• All Implemented Interfaces:
Proximity<Vector>, Serializable

```public class CosineDistance
extends Object
implements Proximity<Vector>, Serializable```
The `CosineDistance` class implements proximity as vector cosine. Distance is defined as one minus the proximity.

The vector cosine operation is defined in the vector interface, `Vector.cosine(Vector)`

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

Fields
Modifier and Type Field and Description
`static CosineDistance` `DISTANCE`
A constant for the cosine distance.
• ### Constructor Summary

Constructors
Constructor and Description
`CosineDistance()`
Construct a cosine proximity.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`double` ```distance(Vector v1, Vector v2)```
Returns one minus the proximity of the vectors.
`double` ```proximity(Vector v1, Vector v2)```
Returns the cosine between the specified 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 CosineDistance DISTANCE`
A constant for the cosine distance. Because the distance function is thread safe, this single instance may be used wherever the cosine distance is needed.
• ### Constructor Detail

• #### CosineDistance

`public CosineDistance()`
Construct a cosine proximity.
• ### Method Detail

• #### distance

```public double distance(Vector v1,
Vector v2)```
Returns one minus the proximity of the vectors.
`    distance(v1,v2) = 1.0 - proximity(v1,v2)`
With this definition, distances run between 0 and 2, with identical vectors being at distance 0, orthogonal vectors at distance 1 and oppositive vectors at distance 2.
Parameters:
`v1` - First vector.
`v2` - Second vector.
Returns:
The negative cosine between the first and second vector.
• #### proximity

```public double proximity(Vector v1,
Vector v2)```
Returns the cosine between the specified vectors. The proximity will be 1 if the vectors are identical in direction, 0 if they are orthogonal, and -1 if they are in opposite directions.
Specified by:
`proximity` in interface `Proximity<Vector>`
Parameters:
`v1` - First vector.
`v2` - Second vector.
Returns:
The cosine between the first and second vector.