فهرست منبع

KMedian: now also with Config

Alexander Freytag 12 سال پیش
والد
کامیت
fcd5652dab
3فایلهای تغییر یافته به همراه39 افزوده شده و 8 حذف شده
  1. 12 1
      math/cluster/KMedian.cpp
  2. 16 6
      math/cluster/KMedian.h
  3. 11 1
      math/cluster/tests/TestKMedian.cpp

+ 12 - 1
math/cluster/KMedian.cpp

@@ -43,7 +43,7 @@ struct CompareSecond
 
 
 
-KMedian::KMedian(int _noClasses, string _distanceType) :
+KMedian::KMedian(const int & _noClasses, const std::string & _distanceType) :
   noClasses(_noClasses), distanceType(_distanceType)
 {
   //srand(time(NULL));
@@ -53,6 +53,17 @@ KMedian::KMedian(int _noClasses, string _distanceType) :
   this->i_maxIterations = 200;
 }
 
+KMedian::KMedian( const NICE::Config *conf, const std::string & _section)
+{       
+  this->distanceType = conf->gS( _section, "distanceType", "euclidean" );
+  this->distancefunction = GenericDistanceSelection::selectDistance(distanceType);
+  
+  this->d_minDelta  = conf->gD( _section, "minDelta", 1e-5 );
+  this->i_maxIterations = conf->gI( _section, "maxIterations", 200);
+  
+  this->noClasses = conf->gI( _section, "noClasses", 20);
+}
+
 KMedian::~KMedian()
 {
 }

+ 16 - 6
math/cluster/KMedian.h

@@ -8,11 +8,12 @@
 #ifndef KMEDIANINCLUDE
 #define KMEDIANINCLUDE
 
-#include "core/vector/VectorT.h"
-#include "core/vector/MatrixT.h"
+#include <core/basics/Config.h>
+#include <core/vector/Distance.h>
+#include <core/vector/MatrixT.h>
+#include <core/vector/VectorT.h>
   
 #include "ClusterAlgorithm.h"
-#include <core/vector/Distance.h>
 
 namespace OBJREC {
 
@@ -86,12 +87,21 @@ namespace OBJREC {
 
       public:
     
+        /**
+        * @brief simple constructor
+        * @param _noClasses the number of clusters to be computed
+        * @param _distanceMode a string specifying the distance function to be used (default: euclidean)
+        */
+        KMedian( const int & _noClasses , const std::string & _distanceMode="euclidean");
+        
         /**
         * @brief standard constructor
-        * @param noClasses the number of clusters to be computed
-        * @param distanceMode a string specifying the distance function to be used (default: euclidean)
+        * @param conf config file specifying all relevant variable settings
+        * @param _section name of the section within the configfile where the settings can be found (default: KMedian)
         */
-        KMedian( int noClasses , std::string distanceMode="euclidean");
+        KMedian( const NICE::Config *conf, const std::string & _section = "KMedian");
+
+        
             
         /** simple destructor */
         virtual ~KMedian();

+ 11 - 1
math/cluster/tests/TestKMedian.cpp

@@ -5,6 +5,7 @@
 
 #include "TestKMedian.h"
 
+#include <core/basics/Config.h>
 #include "vislearning/math/distances/genericDistance.h"
 
 
@@ -29,7 +30,13 @@ void TestKMedian::testKMedianClustering()
   if (verboseStartEnd)
     std::cerr << "================== TestKMedian::testKMedianClustering ===================== " << std::endl;
   
-  OBJREC::KMedian kMedian ( 2 /* noClasses */, "euclidean" /*distanceMode*/ );
+  Config * conf = new Config;
+  std::string section ( "KMedian" );
+  conf->sS( section, "distanceType", "euclidean" );
+  conf->sI( section, "maxIterations", 200 );
+  conf->sI( section, "noClasses", 2 );
+   
+  OBJREC::KMedian kMedian ( conf, section );
   
   //create some artificial data
   NICE::VVector features;
@@ -71,6 +78,9 @@ void TestKMedian::testKMedianClustering()
   
   std::cerr << "                               successfull              " << std::endl;
         
+  //don't waste memory
+  delete conf;
+  
   if (verboseStartEnd)
     std::cerr << "================== TestKMedian::testKMedianClustering done ===================== " << std::endl;
 }