Loading [MathJax]/jax/output/SVG/config.js
Chemical Data Processing Library C++ API - Version 1.2.3
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 
45  {
46 
47  public:
67  double operator()(const Util::BitSet& bs1, const Util::BitSet& bs2) const
68  {
69  return calcTanimotoSimilarity(bs1, bs2);
70  }
71 
85  template <typename V>
86  double operator()(const V& v1, const V& v2) const
87  {
88  return calcTanimotoSimilarity(v1, v2);
89  }
90  };
91 
96  {
97 
98  public:
118  double operator()(const Util::BitSet& bs1, const Util::BitSet& bs2) const
119  {
120  return calcCosineSimilarity(bs1, bs2);
121  }
122 
136  template <typename V>
137  double operator()(const V& v1, const V& v2) const
138  {
139  return calcCosineSimilarity(v1, v2);
140  }
141  };
142 
147  {
148 
149  public:
170  double operator()(const Util::BitSet& bs1, const Util::BitSet& bs2) const
171  {
172  return calcEuclideanSimilarity(bs1, bs2);
173  }
174  };
175 
180  {
181 
182  public:
203  double operator()(const Util::BitSet& bs1, const Util::BitSet& bs2) const
204  {
205  return calcManhattanSimilarity(bs1, bs2);
206  }
207  };
208 
213  {
214 
215  public:
235  double operator()(const Util::BitSet& bs1, const Util::BitSet& bs2) const
236  {
237  return calcDiceSimilarity(bs1, bs2);
238  }
239  };
240 
245  {
246 
247  public:
253  TverskySimilarity(double alpha = 0.95, double beta = 0.05):
254  alpha(alpha), beta(beta) {}
255 
279  double operator()(const Util::BitSet& bs1, const Util::BitSet& bs2) const
280  {
281  return calcTverskySimilarity(bs1, bs2, alpha, beta);
282  }
283 
284  private:
285  double alpha;
286  double beta;
287  };
288 
293  {
294 
295  public:
315  std::size_t operator()(const Util::BitSet& bs1, const Util::BitSet& bs2) const
316  {
317  return calcHammingDistance(bs1, bs2);
318  }
319  };
320 
325  {
326 
327  public:
341  template <typename V>
342  double operator()(const V& v1, const V& v2) const
343  {
344  return calcManhattanDistance(v1, v2);
345  }
346  };
347 
352  {
353 
354  public:
374  double operator()(const Util::BitSet& bs1, const Util::BitSet& bs2) const
375  {
376  return calcEuclideanDistance(bs1, bs2);
377  }
378 
392  template <typename V>
393  double operator()(const V& v1, const V& v2) const
394  {
395  return calcEuclideanDistance(v1, v2);
396  }
397  };
398 
399  } // namespace Descr
400 } // namespace CDPL
401 
402 #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:96
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:118
double operator()(const V &v1, const V &v2) const
Calculates the Cosine Similarity [WCOS] of the vectors v1 and v2.
Definition: SimilarityFunctors.hpp:137
Functor class for calculating the Dice Similarity [GSIM] of bitsets.
Definition: SimilarityFunctors.hpp:213
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:235
Functor class for calculating the Euclidean Distance [CITB] between bitsets and vectors.
Definition: SimilarityFunctors.hpp:352
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:374
double operator()(const V &v1, const V &v2) const
Calculates the Euclidean Distance [CITB] between the vectors v1 and v2.
Definition: SimilarityFunctors.hpp:393
Functor class for calculating the Euclidean Similarity [GSIM] of bitsets.
Definition: SimilarityFunctors.hpp:147
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:170
Functor class for calculating the Hamming Distance [WHAM, CITB] between bitsets.
Definition: SimilarityFunctors.hpp:293
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:315
Functor class for calculating the Manhattan Distance [MADI] between bitsets and vectors.
Definition: SimilarityFunctors.hpp:325
double operator()(const V &v1, const V &v2) const
Calculates the Manhattan Distance [MADI] between the vectors v1 and v2.
Definition: SimilarityFunctors.hpp:342
Functor class for calculating the Manhattan Similarity [GSIM] of bitsets.
Definition: SimilarityFunctors.hpp:180
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:203
Functor class for calculating Tanimoto Similarities [CITB] of bitsets and vectors.
Definition: SimilarityFunctors.hpp:45
double operator()(const Util::BitSet &bs1, const Util::BitSet &bs2) const
Calculates the Tanimoto Similarity of the bitsets bs1 and bs2.
Definition: SimilarityFunctors.hpp:67
double operator()(const V &v1, const V &v2) const
Calculates the Tanimoto Similarity of the vectors v1 and v2.
Definition: SimilarityFunctors.hpp:86
Functor class for calculating the Tversky Similarity [GSIM] of bitsets.
Definition: SimilarityFunctors.hpp:245
TverskySimilarity(double alpha=0.95, double beta=0.05)
Constructor.
Definition: SimilarityFunctors.hpp:253
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:279
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:306
boost::dynamic_bitset BitSet
A dynamic bitset class.
Definition: BitSet.hpp:46
The namespace of the Chemical Data Processing Library.