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 #include <RDGeneral/export.h>
11 #ifndef __RD_METRICFUNCS_H__
12 #define __RD_METRICFUNCS_H__
13 #include <cmath>
14 #include <DataStructs/BitOps.h>
15 #include <RDGeneral/Invariant.h>
16 
17 namespace RDDataManip {
18 //! return the Euclidean distance between two vectors
19 template <typename T1, typename T2>
20 double EuclideanDistanceMetric(const T1 &v1, const T2 &v2, unsigned int dim) {
21  double dist = 0.0;
22  for (unsigned int i = 0; i < dim; i++) {
23  double diff = static_cast<double>(v1[i]) - static_cast<double>(v2[i]);
24  dist += (diff * diff);
25  }
26  return sqrt(dist);
27 };
28 
29 // FIX: there's no reason to have this tied to TanimotoSimilarity... could
30 // include
31 // a different sim function as a template param
32 //! return the Tanimoto distance (1-TanimotoSimilarity) between two bit vectors
33 template <typename T1, typename T2>
34 double TanimotoDistanceMetric(const T1 &bv1, const T2 &bv2, unsigned int dim) {
35  // the dim parameter is actually irrelevant here but we have to include it to
36  // deal with
37  // template version of setMetricFunc in MetricMatricCalc
38  RDUNUSED_PARAM(dim);
39  return (1.0 - SimilarityWrapper(
40  bv1, bv2,
41  (double (*)(const T1 &, const T2 &))TanimotoSimilarity));
42 };
43 
44 //! return the Tanimoto similarity between two bit vectors
45 template <typename T1, typename T2>
46 double TanimotoSimilarityMetric(const T1 &bv1, const T2 &bv2,
47  unsigned int dim) {
48  RDUNUSED_PARAM(dim);
49  return SimilarityWrapper(
50  bv1, bv2, (double (*)(const T1 &, const T2 &))TanimotoSimilarity);
51 };
52 } // namespace RDDataManip
53 
54 #endif
SimilarityWrapper
double SimilarityWrapper(const T &bv1, const T &bv2, double(*metric)(const T &, const T &), bool returnDistance=false)
Definition: BitOps.h:31
RDDataManip
Definition: MetricFuncs.h:17
BitOps.h
Contains general bit-comparison and similarity operations.
RDUNUSED_PARAM
#define RDUNUSED_PARAM(x)
Definition: Invariant.h:196
Invariant.h
TanimotoSimilarity
RDKIT_DATASTRUCTS_EXPORT double TanimotoSimilarity(const T1 &bv1, const T2 &bv2)
returns the Tanimoto similarity between two bit vects
RDDataManip::TanimotoDistanceMetric
double TanimotoDistanceMetric(const T1 &bv1, const T2 &bv2, unsigned int dim)
return the Tanimoto distance (1-TanimotoSimilarity) between two bit vectors
Definition: MetricFuncs.h:34
RDDataManip::TanimotoSimilarityMetric
double TanimotoSimilarityMetric(const T1 &bv1, const T2 &bv2, unsigned int dim)
return the Tanimoto similarity between two bit vectors
Definition: MetricFuncs.h:46
RDDataManip::EuclideanDistanceMetric
double EuclideanDistanceMetric(const T1 &v1, const T2 &v2, unsigned int dim)
return the Euclidean distance between two vectors
Definition: MetricFuncs.h:20
export.h