RDKit
Open-source cheminformatics and machine learning.
MetricFuncs.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2003-2007 Rational Discovery LLC
3 //
4 // @@ All Rights Reserved @@
5 // This file is part of the RDKit.
6 // The contents are covered by the terms of the BSD license
7 // which is included in the file license.txt, found at the root
8 // of the RDKit source tree.
9 //
10 #ifndef __RD_METRICFUNCS_H__
11 #define __RD_METRICFUNCS_H__
12 #include <cmath>
13 #include <DataStructs/BitOps.h>
14 
15 namespace RDDataManip {
16  //! return the Euclidean distance between two vectors
17  template <typename T1, typename T2>
18  double EuclideanDistanceMetric(const T1 &v1, const T2 &v2, unsigned int dim) {
19  double dist = 0.0;
20  for (unsigned int i = 0; i < dim; i++) {
21  double diff = static_cast<double>(v1[i]) - static_cast<double>(v2[i]);
22  dist += (diff*diff);
23  }
24  return sqrt(dist);
25  };
26 
27 
28  // FIX: there's no reason to have this tied to TanimotoSimilarity... could include
29  // a different sim function as a template param
30  //! return the Tanimoto distance (1-TanimotoSimilarity) between two bit vectors
31  template <typename T1, typename T2>
32  double TanimotoDistanceMetric(const T1 &bv1, const T2 &bv2, unsigned int dim) {
33  // the dim parameter is actually irrelevant here but we have to include it to deal with
34  // template version of setMetricFunc in MetricMatricCalc
35  return (1.0 - SimilarityWrapper(bv1, bv2,(double (*)(const T1&,const T2&))TanimotoSimilarity));
36  };
37 
38  //! return the Tanimoto similarity between two bit vectors
39  template <typename T1, typename T2>
40  double TanimotoSimilarityMetric(const T1 &bv1, const T2 &bv2, unsigned int dim) {
41  return SimilarityWrapper(bv1,bv2,(double (*)(const T1&,const T2&))TanimotoSimilarity);
42  };
43 }
44 
45 #endif
46 
47 
double EuclideanDistanceMetric(const T1 &v1, const T2 &v2, unsigned int dim)
return the Euclidean distance between two vectors
Definition: MetricFuncs.h:18
double TanimotoSimilarity(const T1 &bv1, const T2 &bv2)
returns the Tanimoto similarity between two bit vects
double TanimotoSimilarityMetric(const T1 &bv1, const T2 &bv2, unsigned int dim)
return the Tanimoto similarity between two bit vectors
Definition: MetricFuncs.h:40
double TanimotoDistanceMetric(const T1 &bv1, const T2 &bv2, unsigned int dim)
return the Tanimoto distance (1-TanimotoSimilarity) between two bit vectors
Definition: MetricFuncs.h:32
Contains general bit-comparison and similarity operations.
double SimilarityWrapper(const T &bv1, const T &bv2, double(*metric)(const T &, const T &), bool returnDistance=false)
Definition: BitOps.h:30