瀏覽代碼

minor changes on KMedian for running the tests properly

Alexander Freytag 12 年之前
父節點
當前提交
88cfbd1508
共有 2 個文件被更改,包括 14 次插入14 次删除
  1. 13 13
      math/cluster/KMedian.cpp
  2. 1 1
      math/cluster/tests/TestKMedian.cpp

+ 13 - 13
math/cluster/KMedian.cpp

@@ -42,8 +42,8 @@ struct CompareSecond
 
 
 
-KMedian::KMedian(const int & _noClasses, const std::string & _distanceType) :
-  noClasses(_noClasses), distanceType(_distanceType)
+KMedian::KMedian(const int & _noClusters, const std::string & _distanceType) :
+  noClusters(_noClusters), distanceType(_distanceType)
 {
   //srand(time(NULL));
   distancefunction = GenericDistanceSelection::selectDistance(distanceType);
@@ -60,7 +60,7 @@ KMedian::KMedian( const NICE::Config *conf, const std::string & _section)
   this->d_minDelta  = conf->gD( _section, "minDelta", 1e-5 );
   this->i_maxIterations = conf->gI( _section, "maxIterations", 200);
   
-  this->noClasses = conf->gI( _section, "noClasses", 20);
+  this->noClusters = conf->gI( _section, "noClusters", 20);
 }
 
 KMedian::~KMedian()
@@ -101,13 +101,13 @@ int KMedian::compute_prototypes(const VVector & features, VVector & prototypes,
   #endif
   
   //initialization
-  for (int k = 0; k < noClasses; k++)
+  for (int k = 0; k < noClusters; k++)
   {
     prototypes[k].set(0);
     weights[k] = 0;
   }
   
-  NICE::VectorT<int> numberOfCurrentAssignments ( noClasses ) ;
+  NICE::VectorT<int> numberOfCurrentAssignments ( noClusters ) ;
   numberOfCurrentAssignments.set ( 0 );
   
   int exCnt = 0;  
@@ -120,12 +120,12 @@ int KMedian::compute_prototypes(const VVector & features, VVector & prototypes,
   }
     
   #ifdef DEBUG_KMEDIAN_PROTOCOMP    
-    std::cerr << "k-median -- current assignmens: " << numberOfCurrentAssignments << std::endl << "noClasses: " << noClasses << std::endl;
+    std::cerr << "k-median -- current assignmens: " << numberOfCurrentAssignments << std::endl << "noClusters: " << noClusters << std::endl;
   #endif
   
   //compute the median for every cluster
   #pragma omp parallel for
-  for (int clusterCnt = 0; clusterCnt < noClasses; clusterCnt++)
+  for (int clusterCnt = 0; clusterCnt < noClusters; clusterCnt++)
   {    
     NICE::Vector overallDistances ( numberOfCurrentAssignments[ clusterCnt ] );
     VVector::const_iterator lastExampleWorkedOn = features.begin();
@@ -302,7 +302,7 @@ double KMedian::compute_weights(const VVector & features,
                                 std::vector<double> & weights,
                                 std::vector<int> & assignment)
 {
-  for (int k = 0; k < noClasses; k++)
+  for (int k = 0; k < noClusters; k++)
     weights[k] = 0;
 
   int j = 0;
@@ -313,7 +313,7 @@ double KMedian::compute_weights(const VVector & features,
     weights[k]++;
   }
 
-  for (int k = 0; k < noClasses; k++)
+  for (int k = 0; k < noClusters; k++)
     weights[k] = weights[k] / features.size();
 
   return 0.0;
@@ -329,21 +329,21 @@ void KMedian::cluster(const NICE::VVector & features,
   prototypes.clear();
   weights.clear();
   assignment.clear();
-  weights.resize(noClasses, 0);
+  weights.resize(noClusters, 0);
   assignment.resize(features.size(), 0);
 
   int dimension;
 
-  if ((int) features.size() >= noClasses)
+  if ((int) features.size() >= noClusters)
     dimension = features[0].size();
   else
   {
     fprintf(stderr,
-        "FATAL ERROR: Not enough feature vectors provided for kMeans\n");
+        "FATAL ERROR: Not enough feature vectors provided for kMedians -- number of Features: %i - number of clusters: %i\n", (int) features.size(), noClusters);
     exit(-1);
   }
 
-  for (int k = 0; k < noClasses; k++)
+  for (int k = 0; k < noClusters; k++)
   {
     prototypes.push_back( NICE::Vector(dimension) );
     prototypes[k].set(0);

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

@@ -34,7 +34,7 @@ void TestKMedian::testKMedianClustering()
   std::string section ( "KMedian" );
   conf->sS( section, "distanceType", "euclidean" );
   conf->sI( section, "maxIterations", 200 );
-  conf->sI( section, "noClasses", 2 );
+  conf->sI( section, "noClusters", 2 );
    
   OBJREC::KMedian kMedian ( conf, section );