MetricFuncs.h

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

Generated on Fri Apr 3 06:03:02 2009 for RDCode by  doxygen 1.5.6