![]() |
Chemical Data Processing Library C++ API - Version 1.3.0
|
Functor class for calculating Cosine Similarities [WCOS] of bitsets and vectors. More...
#include <SimilarityFunctors.hpp>
Public Member Functions | |
double | operator() (const Util::BitSet &bs1, const Util::BitSet &bs2) const |
Calculates the Cosine Similarity [WCOS] of the bitsets bs1 and bs2. More... | |
template<typename V > | |
double | operator() (const V &v1, const V &v2) const |
Calculates the Cosine Similarity [WCOS] of the vectors v1 and v2. More... | |
Functor class for calculating Cosine Similarities [WCOS] of bitsets and vectors.
|
inline |
Calculates the Cosine Similarity [WCOS] of the bitsets bs1 and bs2.
The Cosine Similarity S_{ab} is calculated by:
S_{ab} = \frac{N_{ab}}{\sqrt{N_a * N_b}}
where N_{ab} is the number of bits that are set in both bitsets, N_a is the number of bits that are set in the first bitset and N_b is the number of bits that are set in the second bitset.
If the specified bitsets bs1 and bs2 are of different size, missing bits at the end of the smaller bitset are assumed to be zero.
bs1 | The first bitset. |
bs2 | The second bitset. |
|
inline |
Calculates the Cosine Similarity [WCOS] of the vectors v1 and v2.
The Cosine Similarity S_{12} is calculated by:
S_{12} = \frac{\vec{v}_1 \cdot \vec{v}_2}{{\left \| \vec{v}_1 \right \|}{\left \| \vec{v}_2 \right \|}}
v1 | The first vector. |
v2 | The second vector. |