00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2012 Fernando José Iglesias García 00008 * Copyright (C) 2012 Fernando José Iglesias García 00009 */ 00010 00011 #ifndef _MAHALANOBISDISTANCE_H__ 00012 #define _MAHALANOBISDISTANCE_H__ 00013 00014 #ifdef HAVE_LAPACK 00015 00016 #include <shogun/lib/common.h> 00017 #include <shogun/distance/RealDistance.h> 00018 00019 namespace shogun 00020 { 00050 class CMahalanobisDistance: public CRealDistance 00051 { 00052 public: 00054 CMahalanobisDistance(); 00055 00061 CMahalanobisDistance(CDenseFeatures<float64_t>* l, CDenseFeatures<float64_t>* r); 00062 virtual ~CMahalanobisDistance(); 00063 00070 virtual bool init(CFeatures* l, CFeatures* r); 00071 00073 virtual void cleanup(); 00074 00079 virtual EDistanceType get_distance_type() { return D_MAHALANOBIS; } 00080 00085 virtual EFeatureType get_feature_type() { return F_DREAL; } 00086 00091 virtual const char* get_name() const { return "MahalanobisDistance"; } 00092 00098 virtual bool get_disable_sqrt() { return disable_sqrt; }; 00099 00105 virtual void set_disable_sqrt(bool state) { disable_sqrt=state; }; 00106 00112 virtual bool get_use_mean() { return use_mean; }; 00113 00119 virtual void set_use_mean(bool state) { use_mean=state; }; 00120 00121 protected: 00131 virtual float64_t compute(int32_t idx_a, int32_t idx_b); 00132 00133 private: 00134 void init(); 00135 00136 protected: 00138 bool disable_sqrt; 00139 00141 bool use_mean; 00142 00144 SGVector<float64_t> mean; 00146 SGMatrix<float64_t> icov; 00147 }; 00148 00149 } // namespace shogun 00150 #endif /* HAVE_LAPACK */ 00151 #endif /* _MAHALANOBISDISTANCE_H__ */