# `Similarity`
[🔗](https://github.com/preciz/similarity/blob/v0.5.1/lib/similarity.ex#L1)

Contains basic functions for similarity calculation.

`Similarity.Cosine` - easy cosine similarity calculation

`Similarity.Simhash` - simhash similarity calculation between two strings

`Similarity.SorensenDice` - Sorensen-Dice similarity for strings and collections

# `cosine`

Calculates Cosine similarity between two vectors.

[https://en.wikipedia.org/wiki/Cosine_similarity#Definition](https://en.wikipedia.org/wiki/Cosine_similarity#Definition)

## Example:
    Similarity.cosine([1, 2, 3], [1, 2, 8])

Raises `ArgumentError` when the vectors have different lengths or either vector
has zero magnitude.

# `cosine_srol`

Multiplies cosine similarity with the square root of compared vectors length.

srol here means square root of length

This gives better comparable numbers where the number of attributes
compared might differ. You can try to use this instead of `cosine/2`
if the number of shared attributes differ.

## Example:
    Similarity.cosine_srol([1, 2, 3], [1, 2, 8])

# `dot_product`

Calculates Euclidean dot product of two vectors.

[https://en.wikipedia.org/wiki/Euclidean_vector#Dot_product](https://en.wikipedia.org/wiki/Euclidean_vector#Dot_product)

## Example:
    iex> Similarity.dot_product([1, 2], [3, 4])
    11

Raises `ArgumentError` when the vectors have different lengths.

# `magnitude`

Calculates Euclidean magnitude of one vector.

[https://en.wikipedia.org/wiki/Magnitude_(mathematics)#Euclidean_vector_space](https://en.wikipedia.org/wiki/Magnitude_(mathematics)#Euclidean_vector_space)

## Example:
    iex> Similarity.magnitude([2])
    2.0

# `simhash`

For docs see `Similarity.Simhash`

# `sorensen_dice`

For docs see `Similarity.SorensenDice`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
