Loading [MathJax]/extensions/tex2jax.js
Chemical Data Processing Library C++ API - Version 1.3.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SimilarityFunctors.hpp
Go to the documentation of this file.
1 /*
2  * SimilarityFunctors.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_DESCR_SIMILARITYFUNCTORS_HPP
30 #define CDPL_DESCR_SIMILARITYFUNCTORS_HPP
31 
33 
34 
35 namespace CDPL
36 {
37 
38  namespace Descr
39  {
40 
46  {
47 
48  public:
68  double operator()(const Util::BitSet& bs1, const Util::BitSet& bs2) const
69  {
70  return calcTanimotoSimilarity(bs1, bs2);
71  }
72 
86  template <typename V>
87  double operator()(const V& v1, const V& v2) const
88  {
89  return calcTanimotoSimilarity(v1, v2);
90  }
91  };
92 
98  {
99 
100  public:
120  double operator()(const Util::BitSet& bs1, const Util::BitSet& bs2) const
121  {
122  return calcCosineSimilarity(bs1, bs2);
123  }
124 
138  template <typename V>
139  double operator()(const V& v1, const V& v2) const
140  {
141  return calcCosineSimilarity(v1, v2);
142  }
143  };
144 
150  {
151 
152  public:
173  double operator()(const Util::BitSet& bs1, const Util::BitSet& bs2) const
174  {
175  return calcEuclideanSimilarity(bs1, bs2);
176  }
177  };
178 
184  {
185 
186  public:
207  double operator()(const Util::BitSet& bs1, const Util::BitSet& bs2) const
208  {
209  return calcManhattanSimilarity(bs1, bs2);
210  }
211  };
212 
218  {
219 
220  public:
240  double operator()(const Util::BitSet& bs1, const Util::BitSet& bs2) const
241  {
242  return calcDiceSimilarity(bs1, bs2);
243  }
244  };
245 
251  {
252 
253  public:
259  TverskySimilarity(double alpha = 0.95, double beta = 0.05):
260  alpha(alpha), beta(beta) {}
261 
285  double operator()(const Util::BitSet& bs1, const Util::BitSet& bs2) const
286  {
287  return calcTverskySimilarity(bs1, bs2, alpha, beta);
288  }
289 
290  private:
291  double alpha;
292  double beta;
293  };
294 
300  {
301 
302  public:
322  std::size_t operator()(const Util::BitSet& bs1, const Util::BitSet& bs2) const
323  {
324  return calcHammingDistance(bs1, bs2);
325  }
326  };
327 
333  {
334 
335  public:
349  template <typename V>
350  double operator()(const V& v1, const V& v2) const
351  {
352  return calcManhattanDistance(v1, v2);
353  }
354  };
355 
361  {
362 
363  public:
383  double operator()(const Util::BitSet& bs1, const Util::BitSet& bs2) const
384  {
385  return calcEuclideanDistance(bs1, bs2);
386  }
387 
401  template <typename V>
402  double operator()(const V& v1, const V& v2) const
403  {
404  return calcEuclideanDistance(v1, v2);
405  }
406  };
407 
408  } // namespace Descr
409 } // namespace CDPL
410 
411 #endif // CDPL_DESCR_SIMILARITYFUNCTORS_HPP
Provides functions for the calculation of various similarity and distance measures.
Functor class for calculating Cosine Similarities [WCOS] of bitsets and vectors.
Definition: SimilarityFunctors.hpp:98
double operator()(const Util::BitSet &bs1, const Util::BitSet &bs2) const
Calculates the Cosine Similarity [WCOS] of the bitsets bs1 and bs2.
Definition: SimilarityFunctors.hpp:120
double operator()(const V &v1, const V &v2) const
Calculates the Cosine Similarity [WCOS] of the vectors v1 and v2.
Definition: SimilarityFunctors.hpp:139
Functor class for calculating the Dice Similarity [GSIM] of bitsets.
Definition: SimilarityFunctors.hpp:218
double operator()(const Util::BitSet &bs1, const Util::BitSet &bs2) const
Calculates the Dice Similarity [GSIM] of the bitsets bs1 and bs2.
Definition: SimilarityFunctors.hpp:240
Functor class for calculating the Euclidean Distance [CITB] between bitsets and vectors.
Definition: SimilarityFunctors.hpp:361
double operator()(const Util::BitSet &bs1, const Util::BitSet &bs2) const
Calculates the Euclidean Distance [CITB] between the bitsets bs1 and bs2.
Definition: SimilarityFunctors.hpp:383
double operator()(const V &v1, const V &v2) const
Calculates the Euclidean Distance [CITB] between the vectors v1 and v2.
Definition: SimilarityFunctors.hpp:402
Functor class for calculating the Euclidean Similarity [GSIM] of bitsets.
Definition: SimilarityFunctors.hpp:150
double operator()(const Util::BitSet &bs1, const Util::BitSet &bs2) const
Calculates the Euclidean Similarity [GSIM] of the bitsets bs1 and bs2.
Definition: SimilarityFunctors.hpp:173
Functor class for calculating the Hamming Distance [WHAM, CITB] between bitsets.
Definition: SimilarityFunctors.hpp:300
std::size_t operator()(const Util::BitSet &bs1, const Util::BitSet &bs2) const
Calculates the Hamming Distance [WHAM, CITB] between the bitsets bs1 and bs2.
Definition: SimilarityFunctors.hpp:322
Functor class for calculating the Manhattan Distance [MADI] between bitsets and vectors.
Definition: SimilarityFunctors.hpp:333
double operator()(const V &v1, const V &v2) const
Calculates the Manhattan Distance [MADI] between the vectors v1 and v2.
Definition: SimilarityFunctors.hpp:350
Functor class for calculating the Manhattan Similarity [GSIM] of bitsets.
Definition: SimilarityFunctors.hpp:184
double operator()(const Util::BitSet &bs1, const Util::BitSet &bs2) const
Calculates the Manhattan Similarity [GSIM] of the bitsets bs1 and bs2.
Definition: SimilarityFunctors.hpp:207
Functor class for calculating Tanimoto Similarities [CITB] of bitsets and vectors.
Definition: SimilarityFunctors.hpp:46
double operator()(const Util::BitSet &bs1, const Util::BitSet &bs2) const
Calculates the Tanimoto Similarity of the bitsets bs1 and bs2.
Definition: SimilarityFunctors.hpp:68
double operator()(const V &v1, const V &v2) const
Calculates the Tanimoto Similarity of the vectors v1 and v2.
Definition: SimilarityFunctors.hpp:87
Functor class for calculating the Tversky Similarity [GSIM] of bitsets.
Definition: SimilarityFunctors.hpp:251
TverskySimilarity(double alpha=0.95, double beta=0.05)
Constructor.
Definition: SimilarityFunctors.hpp:259
double operator()(const Util::BitSet &bs1, const Util::BitSet &bs2) const
Calculates the Tversky Similarity [GSIM] of the bitsets bs1 and bs2.
Definition: SimilarityFunctors.hpp:285
constexpr unsigned int V
Specifies Vanadium.
Definition: AtomType.hpp:177
CDPL_DESCR_API double calcManhattanSimilarity(const Util::BitSet &bs1, const Util::BitSet &bs2)
Calculates the Manhattan Similarity [GSIM] of the bitsets bs1 and bs2.
CDPL_DESCR_API double calcCosineSimilarity(const Util::BitSet &bs1, const Util::BitSet &bs2)
Calculates the Cosine Similarity [WCOS] of the bitsets bs1 and bs2.
CDPL_DESCR_API double calcTverskySimilarity(const Util::BitSet &bs1, const Util::BitSet &bs2, double a, double b)
Calculates the Tversky Similarity [GSIM] of the bitsets bs1 and bs2.
CDPL_DESCR_API double calcTanimotoSimilarity(const Util::BitSet &bs1, const Util::BitSet &bs2)
Calculates the Tanimoto Similarity [CITB] of the bitsets bs1 and bs2.
CDPL_DESCR_API double calcDiceSimilarity(const Util::BitSet &bs1, const Util::BitSet &bs2)
Calculates the Dice Similarity [GSIM] of the bitsets bs1 and bs2.
CDPL_DESCR_API double calcEuclideanSimilarity(const Util::BitSet &bs1, const Util::BitSet &bs2)
Calculates the Euclidean Similarity [GSIM] of the bitsets bs1 and bs2.
CDPL_DESCR_API std::size_t calcHammingDistance(const Util::BitSet &bs1, const Util::BitSet &bs2)
Calculates the Hamming Distance [WHAM, CITB] between the bitsets bs1 and bs2.
CDPL_DESCR_API double calcEuclideanDistance(const Util::BitSet &bs1, const Util::BitSet &bs2)
Calculates the Euclidean Distance [CITB] between the bitsets bs1 and bs2.
double calcManhattanDistance(const V &v1, const V &v2)
Calculates the Manhattan Distance [MADI] between the vectors v1 and v2.
Definition: SimilarityFunctions.hpp:310
boost::dynamic_bitset BitSet
A dynamic bitset class.
Definition: BitSet.hpp:46
The namespace of the Chemical Data Processing Library.