MetricFuncs.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (C) 2003-2007 Rational Discovery LLC
00003 //
00004 //  @@ All Rights Reserved @@
00005 //  This file is part of the RDKit.
00006 //  The contents are covered by the terms of the BSD license
00007 //  which is included in the file license.txt, found at the root
00008 //  of the RDKit source tree.
00009 //
00010 #ifndef __RD_METRICFUNCS_H__
00011 #define __RD_METRICFUNCS_H__
00012 #include <cmath>
00013 #include <DataStructs/BitOps.h>
00014 
00015 namespace RDDataManip {
00016   //! return the Euclidean distance between two vectors
00017   template <typename T1, typename T2>
00018   double EuclideanDistanceMetric(const T1 &v1, const T2 &v2, unsigned int dim) {
00019     double dist = 0.0;
00020     for (unsigned int i = 0; i < dim; i++) {
00021       double diff = static_cast<double>(v1[i]) - static_cast<double>(v2[i]);
00022       dist += (diff*diff);
00023     }
00024     return sqrt(dist);
00025   };
00026 
00027 
00028   // FIX: there's no reason to have this tied to TanimotoSimilarity... could include
00029   // a different sim function as a template param
00030   //! return the Tanimoto distance (1-TanimotoSimilarity) between two bit vectors
00031   template <typename T1, typename T2>
00032   double TanimotoDistanceMetric(const T1 &bv1, const T2 &bv2, unsigned int dim) {
00033     // the dim parameter is actually irrelevant here but we have to include it to deal with 
00034     // template version of setMetricFunc in MetricMatricCalc
00035     return (1.0 - SimilarityWrapper(bv1, bv2,(double (*)(const T1&,const T2&))TanimotoSimilarity));
00036   };
00037 
00038   //! return the Tanimoto similarity between two bit vectors
00039   template <typename T1, typename T2>
00040   double TanimotoSimilarityMetric(const T1 &bv1, const T2 &bv2, unsigned int dim) {
00041     return SimilarityWrapper(bv1,bv2,(double (*)(const T1&,const T2&))TanimotoSimilarity);
00042   };
00043 }
00044 
00045 #endif
00046     
00047