Similarity v0.2.0 Similarity View Source

Contains basic functions for similarity calculation.

Similarity.Cosine - easy cosine similarity calculation

Similarity.Simhash - simhash similarity calculation between two strings

Link to this section Summary

Functions

Calculates Cosine similarity between two vectors.

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

Calculates Euclidean dot product of two vectors.

Calculates Euclidean magnitude of one vector.

Link to this section Functions

Calculates Cosine similarity between two vectors.

https://en.wikipedia.org/wiki/Cosine_similarity#Definition

Example:

Similarity.cosine([1, 2, 3], [1, 2, 8])
Link to this function

cosine_srol(list_a, list_b) View Source

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

srol = square root of length

This gives better comparable numbers in real life where the number of attributes compared might differ. Use this if the number of shared attributes between real world objects differ.

Example:

Similarity.cosine_srol([1, 2, 3], [1, 2, 8])
Link to this function

dot_product(list_a, list_b, acc \\ 0) View Source

Calculates Euclidean dot product of two vectors.

https://en.wikipedia.org/wiki/Euclidean_vector#Dot_product

Example:

iex> Similarity.dot_product([1, 2], [3, 4])
11
Link to this function

magnitude(list, acc \\ 0) View Source

Calculates Euclidean magnitude of one vector.

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

Example:

iex> Similarity.magnitude([2])
2.0
Link to this function

simhash(left, right, options \\ []) View Source

See Similarity.Simhash.similarity/3.