## de.aitools.aq.algebra.vector.functions Class CosineSimilarity

```java.lang.Object de.aitools.aq.algebra.vector.functions.CosineSimilarity
```
All Implemented Interfaces:
Proximity<Vector>, Similarity<Vector>

`public final class CosineSimilarityextends java.lang.Objectimplements Similarity<Vector>`

A `Similarity` measure for `Vector`s.
The Cosine Similarity of two vectors is defined as the cosine of the angle between them.
It is calculated as the dot product of the both vectors divided by the multiplied euclidean norms of both.
The resulting similarity of a vector a and a vector b is between -1 (if a equals -b * k) and 1 (if a equals b * k), with k being a positive rational number (and thus not zero). A value of 0 signals that the two vectors are orthogonal or at least one of them is the null vector.
`Proximity` of this measure is equal to similarity. Normalized proximity is the proximity plus one and divided by two.

Version:
\$Id: CosineSimilarity.java,v 1.3 2011/08/24 08:25:28 gollub Exp \$
Author:
johannes.kiesel(/\t)uni-weimar.de

Constructor Summary
`CosineSimilarity()`
Construct a new `CosineSimilarity`.

Method Summary
` double` ```computeNormalizedProximity(Vector v1, Vector v2)```
Compute a kind of proximity between two objects.
The value returned by this method has to be between 0 (meaning they are as far away (according to the proximity measure) from each other as possible) and 1 (identical objects according to the proximity measure).
` double` ```computeProximity(Vector v1, Vector v2)```
Compute a kind of proximity between two objects.
` double` ```computeSimilarity(Vector v1, Vector v2)```
Compute the `Similarity` between two objects.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### CosineSimilarity

`public CosineSimilarity()`
Construct a new `CosineSimilarity`.

Method Detail

### computeSimilarity

```public double computeSimilarity(Vector v1,
Vector v2)```
Description copied from interface: `Similarity`
Compute the `Similarity` between two objects. A higher value signals higher similarity.

Specified by:
`computeSimilarity` in interface `Similarity<Vector>`
Parameters:
`v1` - One object, to be compared to the...
`v2` - ...second object
Returns:
Computed similarity

### computeProximity

```public double computeProximity(Vector v1,
Vector v2)```
Description copied from interface: `Proximity`
Compute a kind of proximity between two objects. A higher value signals higher proximity.

Specified by:
`computeProximity` in interface `Proximity<Vector>`
Parameters:
`v1` - One object, to be compared to the...
`v2` - ...second object
Returns:
Computed proximity

### computeNormalizedProximity

```public double computeNormalizedProximity(Vector v1,
Vector v2)```
Description copied from interface: `Proximity`
Compute a kind of proximity between two objects.
The value returned by this method has to be between 0 (meaning they are as far away (according to the proximity measure) from each other as possible) and 1 (identical objects according to the proximity measure).

Specified by:
`computeNormalizedProximity` in interface `Proximity<Vector>`
Parameters:
`v1` - One object, to be compared to the...
`v2` - ...second object
Returns:
Computed normalized proximity