Metrics
moll.metrics.cosine
cosine(u: ArrayLike, v: ArrayLike) -> Array
Computes the cosine similarity between two vectors: $$ \cos \widehat{\bf u, \bf v} = \dfrac{\bf u \cdot \bf v}{\norm{\bf u} \cdot \norm{\bf v}}, $$ this formula follows from the dot product expression: $$ \bf u \cdot \bf v = \norm{\bf u} \cdot \norm{\bf v} \cdot \cos \widehat{\bf u, \bf v}. $$
Examples:
>>> cosine([1, 0], [1, 0])
Array(1., dtype=float32)
>>> cosine([1, 0], [0, 1])
Array(0., dtype=float32)
>>> cosine([1, 0], [-1, 0])
Array(-1., dtype=float32)
moll.metrics.euclidean
euclidean(u: ArrayLike, v: ArrayLike) -> Array
Computes the Euclidean distance (L2-norm) \(||x - y||_2\) between two vectors.
Examples:
>>> euclidean([1, 2, 3], [1, 2, 3])
Array(0., dtype=float32)
>>> euclidean([1, 2, 3], [1, 2, 4])
Array(1., dtype=float32)
>>> euclidean([1, 2, 3], [4, 5, 6])
Array(5.196152, dtype=float32)
moll.metrics.manhattan
manhattan(u: ArrayLike, v: ArrayLike) -> Array
Computes the Manhattan distance between two vectors.
Examples:
>>> manhattan([1, 2, 3], [1, 2, 3])
Array(0., dtype=float32)
>>> manhattan([1, 2, 3], [1, 2, 4])
Array(1., dtype=float32)
>>> manhattan([1, 2, 3], [4, 5, 6])
Array(9., dtype=float32)
moll.metrics.mismatches
mismatches(u: ArrayLike, v: ArrayLike) -> Array
Computes the L0-norm distance between two vectors.
Examples:
>>> mismatches([1, 2, 3], [1, 2, 3])
Array(0., dtype=float32)
>>> mismatches([1, 2, 3], [1, 2, -3])
Array(1., dtype=float32)
>>> mismatches([1, 2, 3], [4, 5, 6])
Array(3., dtype=float32)
moll.metrics.negative_cosine
negative_cosine(u: ArrayLike, v: ArrayLike) -> Array
Computes the cosine distance between two vectors.
Examples:
>>> negative_cosine([1, 0], [1, 0])
Array(-1., dtype=float32)
>>> negative_cosine([1, 0], [0, 1])
Array(-0., dtype=float32)
>>> negative_cosine([1, 0], [-1, 0])
Array(1., dtype=float32)
moll.metrics.one_minus_tanimoto
one_minus_tanimoto(u: ArrayLike, v: ArrayLike) -> Array
Computes the Tanimoto distance between two vectors.
Examples:
>>> one_minus_tanimoto([1, 1], [1, 0])
Array(0.5, dtype=float32)
>>> one_minus_tanimoto([1, 1], [0, 0])
Array(1., dtype=float32)
moll.metrics.tanimoto
tanimoto(u: ArrayLike, v: ArrayLike) -> Array
Computes the Tanimoto coefficient between two vectors.
Examples:
>>> tanimoto([1, 1], [1, 0])
Array(0.5, dtype=float32)
>>> tanimoto([1, 1], [0, 0])
Array(0., dtype=float32)