Преглед изворни кода

using namespace aus header entfernt

Björn Fröhlich пре 14 година
родитељ
комит
ee120d6d01

+ 175 - 166
cbaselib/LabeledSetSelection.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file LabeledSetSelection.h
 * @brief Select a subset of a LabeledSet
 * @author Erik Rodner
@@ -14,177 +14,186 @@
 
 #include <set>
 #include <map>
-  
-namespace OBJREC {
+
+namespace OBJREC
+{
 
 /** Select a subset of a LabeledSet */
 template <class F>
 class LabeledSetSelection
 {
 
-    protected:
-
-    public:
-  
-	static void selectRandom ( const std::map<int,int> & fixedPositiveExamples, const F & base, F & positive, F & negative )
-	{
-	    F & base_nonconst = const_cast< F & >(base);
-	    //srand(time(NULL));
-
-	    for ( std::map<int,int>::const_iterator i = fixedPositiveExamples.begin(); 
-				    i != fixedPositiveExamples.end() ; 
-				    i++ )
-	    {
-			int classno = i->first;
-			int fixedPositiveExamples = i->second;
-
-			std::set<int> memory;
-
-			int count = base_nonconst[classno].size();
-			if ( (count < fixedPositiveExamples) ) {
-				fthrow ( Exception, "LabeledSetSelection::selectRandom: unable to select " << fixedPositiveExamples 
-					<< " of " << count << " examples" );
-			}
-
-			for ( int j = 0 ; j < fixedPositiveExamples ; j++ )
-			{
-				int k;
-				do {
-				k = rand() % count;
-				} while ( memory.find(k) != memory.end() );
-
-				memory.insert(k);
-				positive.add_reference ( classno, base_nonconst[classno][k]);
-			}
-
-			for ( int k = 0 ; k < count ; k++ )
-				if ( memory.find(k) == memory.end() )
-				negative.add_reference ( classno, base_nonconst[classno][k]);
-	    }
-	}
-
-	static void selectRandomMax ( const std::map<int,int> & fixedPositiveExamples, const F & base, F & positive, F & negative )
-	{
-	    F & base_nonconst = const_cast< F & >(base);
-	    //srand(time(NULL));
-
-	    for ( std::map<int,int>::const_iterator i = fixedPositiveExamples.begin(); 
-				    i != fixedPositiveExamples.end() ; 
-				    i++ )
-	    {
-			int classno = i->first;
-			int fixedPositiveExamples = i->second;
-
-			std::set<int> memory;
-
-			int count = base_nonconst[classno].size();
-
-			int m = fixedPositiveExamples < count ? fixedPositiveExamples : count;
-			for ( int j = 0 ; j < m ; j++ )
-			{
-				int k;
-				do {
-					k = rand() % count;
-				} while ( memory.find(k) != memory.end() );
-
-				memory.insert(k);
-				positive.add_reference ( classno, base_nonconst[classno][k]);
-			}
-
-			for ( int k = 0 ; k < count ; k++ )
-				if ( memory.find(k) == memory.end() )
-					negative.add_reference ( classno, base_nonconst[classno][k]);
-	    }
-	}
-
-	static void selectSequentialStep ( const std::map<int, int> & fixedPositiveExamples, const F & base, F & positive, F & negative )
-	{
-	    F & base_nonconst = const_cast< F & >(base);
-
-	    for ( std::map<int,int>::const_iterator i = fixedPositiveExamples.begin(); 
-				    i != fixedPositiveExamples.end() ; 
-				    i++ )
-	    {
-			int classno = i->first;
-			int fixedPositiveExamples = i->second;
-			int count = base_nonconst[classno].size();
-			int step = fixedPositiveExamples ? (count / fixedPositiveExamples) : 0;
-
-			if ( count < fixedPositiveExamples ) {
-				fthrow ( Exception, "LabeledSetSelection::selectSequentialStep: unable to select " << fixedPositiveExamples 
-						<< " of " << count << " examples (classno " << classno << ")" );
-		}
-
-
-		int k = 0;
-		for ( int j = 0 ; j < count ; j++ )
-		{
-		    if ( (step == 0) || (k >= fixedPositiveExamples) || (j % step != 0) ) 
-				negative.add_reference ( classno, base_nonconst[classno][j] );
-		    else {
-				k++;
-				positive.add_reference ( classno, base_nonconst[classno][j] );
-		    }
-		}
-	    }
-	};
-
-
-	static void selectSequential ( const std::map<int, int> & fixedPositiveExamples, const F & base, F & positive, F & negative )
-	{
-	    F & base_nonconst = const_cast< F & >(base);
-
-	    for ( std::map<int,int>::const_iterator i = fixedPositiveExamples.begin(); 
-				    i != fixedPositiveExamples.end() ; 
-				    i++ )
-	    {
-			int classno = i->first;
-			int fixedPositiveExamples = i->second;
-			int count = base_nonconst[classno].size();
-
-			if ( count < fixedPositiveExamples ) {
-				fthrow ( Exception, "LabeledSetSelection::selectSequential: unable to select " << fixedPositiveExamples 
-					<< " of " << count << " examples" );
-			}
-
-			for ( int j = 0 ; j < fixedPositiveExamples ; j++ )
-				positive.add_reference ( classno, base_nonconst[classno][j] );
-			
-			for ( int j = fixedPositiveExamples ; j < count ; j++ )
-				negative.add_reference ( classno, base_nonconst[classno][j] );
-	    }
-
-	};
-
-	static void selectClasses ( const std::set<int> & classnos, const F & base, F & positive, F & negative )
-	{
-	    F & base_nonconst = const_cast< F & >(base);
-
-	    std::vector<int> classes;
-	    base.getClasses(classes);
-
-	    for ( std::set<int>::const_iterator i = classnos.begin(); 
-				    i != classnos.end() ; 
-				    i++ )
-	    {
-			int classno = *i;
-			int count = base_nonconst[classno].size();
-			for ( int j = 0 ; j < count ; j++ )
-				positive.add_reference ( classno, base_nonconst[classno][j]);
-	    }
-
-	    for ( std::vector<int>::const_iterator i = classes.begin(); 
-				    i != classes.end() ; 
-				    i++ )
-	    {
-			int classno = *i;
-			if ( classnos.find(classno) != classnos.end() ) continue;
-			int count = base_nonconst[classno].size();
-			for ( int j = 0 ; j < count ; j++ )
-				negative.add_reference ( classno, base_nonconst[classno][j]);
-	    }
-
-	};
+  protected:
+
+  public:
+
+    static void selectRandom ( const std::map<int,int> & fixedPositiveExamples, const F & base, F & positive, F & negative )
+    {
+      F & base_nonconst = const_cast< F & > ( base );
+      //srand(time(NULL));
+
+      for ( std::map<int,int>::const_iterator i = fixedPositiveExamples.begin();
+            i != fixedPositiveExamples.end() ;
+            i++ )
+      {
+        int classno = i->first;
+        int fixedPositiveExamples = i->second;
+
+        std::set<int> memory;
+
+        int count = base_nonconst[classno].size();
+        if ( ( count < fixedPositiveExamples ) )
+        {
+          fthrow ( NICE::Exception, "LabeledSetSelection::selectRandom: unable to select " << fixedPositiveExamples
+                   << " of " << count << " examples" );
+        }
+
+        for ( int j = 0 ; j < fixedPositiveExamples ; j++ )
+        {
+          int k;
+          do
+          {
+            k = rand() % count;
+          }
+          while ( memory.find ( k ) != memory.end() );
+
+          memory.insert ( k );
+          positive.add_reference ( classno, base_nonconst[classno][k] );
+        }
+
+        for ( int k = 0 ; k < count ; k++ )
+          if ( memory.find ( k ) == memory.end() )
+            negative.add_reference ( classno, base_nonconst[classno][k] );
+      }
+    }
+
+    static void selectRandomMax ( const std::map<int,int> & fixedPositiveExamples, const F & base, F & positive, F & negative )
+    {
+      F & base_nonconst = const_cast< F & > ( base );
+      //srand(time(NULL));
+
+      for ( std::map<int,int>::const_iterator i = fixedPositiveExamples.begin();
+            i != fixedPositiveExamples.end() ;
+            i++ )
+      {
+        int classno = i->first;
+        int fixedPositiveExamples = i->second;
+
+        std::set<int> memory;
+
+        int count = base_nonconst[classno].size();
+
+        int m = fixedPositiveExamples < count ? fixedPositiveExamples : count;
+        for ( int j = 0 ; j < m ; j++ )
+        {
+          int k;
+          do
+          {
+            k = rand() % count;
+          }
+          while ( memory.find ( k ) != memory.end() );
+
+          memory.insert ( k );
+          positive.add_reference ( classno, base_nonconst[classno][k] );
+        }
+
+        for ( int k = 0 ; k < count ; k++ )
+          if ( memory.find ( k ) == memory.end() )
+            negative.add_reference ( classno, base_nonconst[classno][k] );
+      }
+    }
+
+    static void selectSequentialStep ( const std::map<int, int> & fixedPositiveExamples, const F & base, F & positive, F & negative )
+    {
+      F & base_nonconst = const_cast< F & > ( base );
+
+      for ( std::map<int,int>::const_iterator i = fixedPositiveExamples.begin();
+            i != fixedPositiveExamples.end() ;
+            i++ )
+      {
+        int classno = i->first;
+        int fixedPositiveExamples = i->second;
+        int count = base_nonconst[classno].size();
+        int step = fixedPositiveExamples ? ( count / fixedPositiveExamples ) : 0;
+
+        if ( count < fixedPositiveExamples )
+        {
+          fthrow ( NICE::Exception, "LabeledSetSelection::selectSequentialStep: unable to select " << fixedPositiveExamples
+                   << " of " << count << " examples (classno " << classno << ")" );
+        }
+
+
+        int k = 0;
+        for ( int j = 0 ; j < count ; j++ )
+        {
+          if ( ( step == 0 ) || ( k >= fixedPositiveExamples ) || ( j % step != 0 ) )
+            negative.add_reference ( classno, base_nonconst[classno][j] );
+          else
+          {
+            k++;
+            positive.add_reference ( classno, base_nonconst[classno][j] );
+          }
+        }
+      }
+    };
+
+
+    static void selectSequential ( const std::map<int, int> & fixedPositiveExamples, const F & base, F & positive, F & negative )
+    {
+      F & base_nonconst = const_cast< F & > ( base );
+
+      for ( std::map<int,int>::const_iterator i = fixedPositiveExamples.begin();
+            i != fixedPositiveExamples.end() ;
+            i++ )
+      {
+        int classno = i->first;
+        int fixedPositiveExamples = i->second;
+        int count = base_nonconst[classno].size();
+
+        if ( count < fixedPositiveExamples )
+        {
+          fthrow ( NICE::Exception, "LabeledSetSelection::selectSequential: unable to select " << fixedPositiveExamples
+                   << " of " << count << " examples" );
+        }
+
+        for ( int j = 0 ; j < fixedPositiveExamples ; j++ )
+          positive.add_reference ( classno, base_nonconst[classno][j] );
+
+        for ( int j = fixedPositiveExamples ; j < count ; j++ )
+          negative.add_reference ( classno, base_nonconst[classno][j] );
+      }
+
+    };
+
+    static void selectClasses ( const std::set<int> & classnos, const F & base, F & positive, F & negative )
+    {
+      F & base_nonconst = const_cast< F & > ( base );
+
+      std::vector<int> classes;
+      base.getClasses ( classes );
+
+      for ( std::set<int>::const_iterator i = classnos.begin();
+            i != classnos.end() ;
+            i++ )
+      {
+        int classno = *i;
+        int count = base_nonconst[classno].size();
+        for ( int j = 0 ; j < count ; j++ )
+          positive.add_reference ( classno, base_nonconst[classno][j] );
+      }
+
+      for ( std::vector<int>::const_iterator i = classes.begin();
+            i != classes.end() ;
+            i++ )
+      {
+        int classno = *i;
+        if ( classnos.find ( classno ) != classnos.end() ) continue;
+        int count = base_nonconst[classno].size();
+        for ( int j = 0 ; j < count ; j++ )
+          negative.add_reference ( classno, base_nonconst[classno][j] );
+      }
+
+    };
 
 };
 

+ 7 - 7
classifier/genericClassifierSelection.h

@@ -107,22 +107,22 @@ class GenericClassifierSelection
       } else if ( ( classifier_type == "dtgp" ) ) {
         classifier = new VCDTSVM ( conf );
       } else if ( ( classifier_type == "minimum_enclosing_ball" ) ) {
-        string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
+        std::string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
         classifier = new KCMinimumEnclosingBall ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
       } else if ( ( classifier_type == "gp_one_class" ) ) {
-        string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
+        std::string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
         classifier = new KCGPOneClass ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
       } else if ( ( classifier_type == "gp_regression_rbf" ) ) {
-        string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
+        std::string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
         classifier = new KCGPRegression ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
       } else if ( ( classifier_type == "gp_laplace_rbf" ) ) {
-        string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
+        std::string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
         classifier = new KCGPLaplace ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
       } else if ( ( classifier_type == "gp_regression_rbf_onevsall" ) ) {
-        string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
+        std::string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
         classifier = new KCGPRegOneVsAll ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
       } else if ( ( classifier_type == "gp_laplace_rbf_onevsall" ) ) {
-        string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
+        std::string kernel_type = conf->gS ( "Kernel", "kernel_function", "rbf" );
         classifier = new KCGPLaplaceOneVsAll ( conf, GenericKernelSelection::selectKernel ( conf, kernel_type ) );
       } else if ( StringTools::regexMatch ( classifier_type, "^one_vs_one\\(([^\\)]+)\\)$", submatches ) && ( submatches.size() == 2 ) ) {
         classifier = new VCOneVsOne ( conf, selectVecClassifier ( conf, submatches[1] ) );
@@ -131,7 +131,7 @@ class GenericClassifierSelection
       } else if ( StringTools::regexMatch ( classifier_type, "^random_forest\\(([^\\)]+)\\)$", submatches ) && ( submatches.size() == 2 ) ) {
         classifier = new VCPreRandomForest ( conf, "VCPreRandomForest", selectVecClassifier ( conf, submatches[1] ) );
       } else {
-        fthrow ( Exception, "Classifier type " << classifier_type << " not (yet) supported." << endl <<
+        fthrow ( Exception, "Classifier type " << classifier_type << " not (yet) supported." << std::endl <<
                  "(genericClassifierSelection.h contains a list of classifiers to choose from)" );
       }
 

+ 1 - 1
features/localfeatures/GenericLFSelection.h

@@ -83,7 +83,7 @@ class GenericLFSelection
 
 	  // no correct localfeature_type was given
 	  if ( lfrep == NULL )
-		  fthrow(Exception, "Local feature type not found: " << localfeature_type );
+		  fthrow(NICE::Exception, "Local feature type not found: " << localfeature_type );
 
 	  if ( conf->gB(section, "localfeature_cache_save", false) )
 	  {

+ 1 - 1
features/localfeatures/GenericLocalFeatureSelection.h

@@ -55,7 +55,7 @@ class GenericLocalFeatureSelection
 
       // no correct localfeature_type was given
       if ( lf == NULL )
-        fthrow ( Exception, "Local feature type not found: " << localfeature_type );
+        fthrow ( NICE::Exception, "Local feature type not found: " << localfeature_type );
 
       return lf;
     }

+ 80 - 70
features/localfeatures/LFReadCache.tcc

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file LFReadCache.tcc
 * @author Erik Rodner
 * @date 02/14/2008
@@ -18,84 +18,94 @@
 #include "core/basics/FileMgt.h"
 #include "core/vector/VVector.h"
 
-namespace OBJREC {
+namespace OBJREC
+{
 
 template <class ImageClass>
-int LFReadCache::extractFeaturesTemplate ( const ImageClass & img, 
-		  NICE::VVector & features, 
-		  NICE::VVector & positions) const
+int LFReadCache::extractFeaturesTemplate ( const ImageClass & img,
+    NICE::VVector & features,
+    NICE::VVector & positions ) const
 {
-    std::string filename = Globals::getCacheFilename ( cachedir, cachemode );
-    std::string filename_desc = filename + ".desc";
-    std::string filename_pos = filename + ".key";
+  std::string filename = Globals::getCacheFilename ( cachedir, cachemode );
+  std::string filename_desc = filename + ".desc";
+  std::string filename_pos = filename + ".key";
+
+  int ret = 0;
+
+  if ( ! NICE::FileMgt::fileExists ( filename_desc ) ||
+       ! NICE::FileMgt::fileExists ( filename_pos ) )
+  {
+    fprintf ( stderr, "LFReadCache::extractFeatures: recovering data (%s,%s not found)\n", filename_desc.c_str(),
+              filename_pos.c_str() );
+    if ( lfrep == NULL )
+      fthrow ( NICE::Exception, "LocalFeatureRepresentation not available, recovering is impossible!" );
+
+    lfrep->extractFeatures ( img, features, positions );
+
+    features.save ( filename_desc, descFormat );
+    positions.save ( filename_pos, NICE::VVector::FILEFORMAT_LINE );
+  }
+  else
+  {
+    if ( ( descFormat == NICE::VVector::FILEFORMAT_BINARY_DOUBLE ) || ( descFormat == NICE::VVector::FILEFORMAT_BINARY_CHAR ) )
+    {
+      if ( lfrep == NULL )
+      {
+        fthrow ( NICE::Exception, "Raw binary format needs a LocalFeatureRepresentation as prototype" );
+      }
+      else
+      {
+        features.setBufSize ( lfrep->getDescSize() );
+      }
+    }
 
-    int ret = 0;
+    features.read ( filename_desc, descFormat );
+    positions.read ( filename_pos, NICE::VVector::FILEFORMAT_LINE );
+
+    if ( positions.size() != features.size() )
+    {
+      std::cerr << "LFReadCache::extractFeatures: format error ! positions.size=" << positions.size() <<
+                " features.size()=" << features.size() << std::endl;
+      std::cerr << "features: " << filename_desc << std::endl;
+      std::cerr << "positions: " << filename_pos << std::endl;
+      exit ( -1 );
+    }
 
-    if ( ! NICE::FileMgt::fileExists ( filename_desc ) ||
-	 ! NICE::FileMgt::fileExists ( filename_pos ) )
+    if ( ( numFeatures >= 0 ) && ( features.size() > ( size_t ) numFeatures ) )
     {
-		fprintf (stderr, "LFReadCache::extractFeatures: recovering data (%s,%s not found)\n", filename_desc.c_str(),
-			filename_pos.c_str());
-		if ( lfrep == NULL )
-			fthrow(Exception, "LocalFeatureRepresentation not available, recovering is impossible!");
-
-		lfrep->extractFeatures ( img, features, positions );
-
-		features.save ( filename_desc, descFormat );
-		positions.save ( filename_pos, NICE::VVector::FILEFORMAT_LINE );
-    } else {
-		if ( (descFormat == NICE::VVector::FILEFORMAT_BINARY_DOUBLE) || (descFormat == NICE::VVector::FILEFORMAT_BINARY_CHAR) )
-		{
-			if ( lfrep == NULL ) {
-				fthrow(Exception, "Raw binary format needs a LocalFeatureRepresentation as prototype");
-			} else {
-				features.setBufSize(lfrep->getDescSize());
-			}
-		}
-
-		features.read( filename_desc, descFormat );
-		positions.read ( filename_pos, NICE::VVector::FILEFORMAT_LINE );
-
-		if ( positions.size() != features.size() )
-		{
-			std::cerr << "LFReadCache::extractFeatures: format error ! positions.size=" << positions.size() <<
-			" features.size()=" << features.size() << std::endl;
-			std::cerr << "features: " << filename_desc << std::endl;
-			std::cerr << "positions: " << filename_pos << std::endl;
-			exit(-1);
-		}
-
-		if ( (numFeatures >= 0) && (features.size() > (size_t)numFeatures) ) {
-			size_t n = features.size() - numFeatures; // >= 1
-			fprintf (stderr, "LFReadCache: number of local features is restricted: localfeature_count %d, real %d\n",
-			numFeatures, (int)features.size() );
-
-			if ( n > (size_t)numFeatures ) {
-				NICE::VVector nf;
-				NICE::VVector np;
-				for ( size_t l = 0 ; l < (size_t)numFeatures ; l++ )
-				{
-					size_t i = rand() % features.size();
-					nf.push_back ( features[i] );
-					np.push_back ( positions[i] );
-					features.erase ( features.begin() + i );
-					positions.erase ( positions.begin() + i );
-				}
-				positions = np;
-				features = nf;
-			} else {
-				for ( size_t l = 0 ; l < n ; l++ )
-				{
-					size_t i = rand() % features.size();
-					features.erase ( features.begin() + i );
-					positions.erase ( positions.begin() + i );
-				}
-			}
-		}
+      size_t n = features.size() - numFeatures; // >= 1
+      fprintf ( stderr, "LFReadCache: number of local features is restricted: localfeature_count %d, real %d\n",
+                numFeatures, ( int ) features.size() );
+
+      if ( n > ( size_t ) numFeatures )
+      {
+        NICE::VVector nf;
+        NICE::VVector np;
+        for ( size_t l = 0 ; l < ( size_t ) numFeatures ; l++ )
+        {
+          size_t i = rand() % features.size();
+          nf.push_back ( features[i] );
+          np.push_back ( positions[i] );
+          features.erase ( features.begin() + i );
+          positions.erase ( positions.begin() + i );
+        }
+        positions = np;
+        features = nf;
+      }
+      else
+      {
+        for ( size_t l = 0 ; l < n ; l++ )
+        {
+          size_t i = rand() % features.size();
+          features.erase ( features.begin() + i );
+          positions.erase ( positions.begin() + i );
+        }
+      }
     }
+  }
 
 
-    return ret;
+  return ret;
 }
 
 }

+ 2 - 1
features/localfeatures/LFSiftPP.h

@@ -8,10 +8,11 @@
 #ifndef LFSIFTPPINCLUDE
 #define LFSIFTPPINCLUDE
 
+#include "core/imagedisplay/ImageDisplay.h"
+
 #include "core/vector/VectorT.h"
 #include "core/vector/MatrixT.h"
 #include "core/image/ImageT.h"
-#include "core/imagedisplay/ImageDisplay.h"
 
 #include "core/basics/Config.h"
 #include "LocalFeatureRepresentation.h"

+ 2 - 1
features/localfeatures/LocalFeatureRepresentation.h

@@ -8,10 +8,11 @@
 #ifndef LOCALFEATUREREPRESENTATIONINCLUDE
 #define LOCALFEATUREREPRESENTATIONINCLUDE
 
+#include "core/imagedisplay/ImageDisplay.h"
+
 #include "core/vector/VectorT.h"
 #include "core/vector/MatrixT.h"
 #include "core/image/ImageT.h"
-#include "core/imagedisplay/ImageDisplay.h"
  
 #include <vector>
 #include "core/vector/VVector.h"

+ 48 - 48
math/distances/genericDistance.h

@@ -8,54 +8,54 @@ namespace OBJREC
 
 class GenericDistanceSelection
 {
-public:
-
-	static NICE::VectorDistance<double> *selectDistance(
-			std::string distance_type)
-	{
-		NICE::VectorDistance<double> *distance = NULL;
-
-		if (distance_type == "euclidean")
-		{
-			distance = new NICE::EuclidianDistance<double>();
-		}
-		else if (distance_type == "manhattan" || distance_type == "cityblock")
-		{
-			distance = new NICE::ManhattanDistance<double>();
-		}
-		else if (distance_type == "median")
-		{
-			distance = new NICE::MedianDistance<double>();
-		}
-		else if (distance_type == "cosinus")
-		{
-			distance = new NICE::CosDistance<double>();
-		}
-		else if (distance_type == "spherical")
-		{
-			distance = new NICE::SphericalDistance<double>();
-		}
-		else if (distance_type == "chisquare" || distance_type == "chi2")
-		{
-			distance = new NICE::Chi2Distance<double>();
-
-		}
-		else if (distance_type == "kl" || distance_type == "kullbackleibler")
-		{
-			distance = new NICE::KLDistance<double>();
-		}
-		else if (distance_type == "bhattacharyya")
-		{
-			distance = new NICE::BhattacharyyaDistance<double>();
-		}
-		else
-		{
-			fthrow(Exception, "Distance type " << distance_type << " is unknown - euclidean distance used" );
-			distance = new NICE::EuclidianDistance<double>();
-		}
-
-		return distance;
-	}
+  public:
+
+    static NICE::VectorDistance<double> *selectDistance (
+      std::string distance_type )
+    {
+      NICE::VectorDistance<double> *distance = NULL;
+
+      if ( distance_type == "euclidean" )
+      {
+        distance = new NICE::EuclidianDistance<double>();
+      }
+      else if ( distance_type == "manhattan" || distance_type == "cityblock" )
+      {
+        distance = new NICE::ManhattanDistance<double>();
+      }
+      else if ( distance_type == "median" )
+      {
+        distance = new NICE::MedianDistance<double>();
+      }
+      else if ( distance_type == "cosinus" )
+      {
+        distance = new NICE::CosDistance<double>();
+      }
+      else if ( distance_type == "spherical" )
+      {
+        distance = new NICE::SphericalDistance<double>();
+      }
+      else if ( distance_type == "chisquare" || distance_type == "chi2" )
+      {
+        distance = new NICE::Chi2Distance<double>();
+
+      }
+      else if ( distance_type == "kl" || distance_type == "kullbackleibler" )
+      {
+        distance = new NICE::KLDistance<double>();
+      }
+      else if ( distance_type == "bhattacharyya" )
+      {
+        distance = new NICE::BhattacharyyaDistance<double>();
+      }
+      else
+      {
+        fthrow ( NICE::Exception, "Distance type " << distance_type << " is unknown - euclidean distance used" );
+        distance = new NICE::EuclidianDistance<double>();
+      }
+
+      return distance;
+    }
 
 };
 } //namespace

+ 44 - 28
regression/gpregression/modelselcrit/genericGPModelSelection.h

@@ -7,37 +7,53 @@
 #include "GPMSCLooEstimates.h"
 
 
-namespace OBJREC {
+namespace OBJREC
+{
 
 class GenericGPModelSelection
 {
-    public:
-
-		static GPMSCLooLikelihoodRegression *selectModelSel ( const NICE::Config *conf, std::string modelselcrit_s )
-		{
-			 GPMSCLooLikelihoodRegression *modelselcrit = NULL;
-
-			 if ( modelselcrit_s == "loo_pred_prob_weighted" ) {
-				 modelselcrit = new GPMSCLooLikelihoodRegression ( true );
-			 } else if ( modelselcrit_s == "loo_pred_prob" ) {
-				 modelselcrit = new GPMSCLooLikelihoodRegression ( false );
-			 } else if ( modelselcrit_s == "loo_pred_squash_opt" ) {
-				 modelselcrit = new GPMSCLooLikelihoodClassification ( );
-			 } else if ( modelselcrit_s == "loo_pred_squash" ) {
-				 modelselcrit = new GPMSCLooLikelihoodClassificationFixed ( );
-			 } else if ( modelselcrit_s == "loo_recognition_rate" ) {
-				 modelselcrit = new GPMSCLooVarious ( GPMSCLooVarious::P_RECOGNITIONRATE );
-			 } else if ( modelselcrit_s == "loo_auc" ) {
-				 modelselcrit = new GPMSCLooVarious ( GPMSCLooVarious::P_AUC );
-			 } else if ( modelselcrit_s == "loo_avgprec" ) {
-				 modelselcrit = new GPMSCLooVarious ( GPMSCLooVarious::P_AVGPREC );
-			 } else {
-				  fthrow ( Exception, "Model selection criterion unknown " << modelselcrit_s << " not (yet) supported." << std::endl <<
-				  			"(genericGPModelSelection.h contains a list of classifiers to choose from)");
-			 }
-
-			 return modelselcrit;
-		}
+  public:
+
+    static GPMSCLooLikelihoodRegression *selectModelSel ( const NICE::Config *conf, std::string modelselcrit_s )
+    {
+      GPMSCLooLikelihoodRegression *modelselcrit = NULL;
+
+      if ( modelselcrit_s == "loo_pred_prob_weighted" )
+      {
+        modelselcrit = new GPMSCLooLikelihoodRegression ( true );
+      }
+      else if ( modelselcrit_s == "loo_pred_prob" )
+      {
+        modelselcrit = new GPMSCLooLikelihoodRegression ( false );
+      }
+      else if ( modelselcrit_s == "loo_pred_squash_opt" )
+      {
+        modelselcrit = new GPMSCLooLikelihoodClassification ( );
+      }
+      else if ( modelselcrit_s == "loo_pred_squash" )
+      {
+        modelselcrit = new GPMSCLooLikelihoodClassificationFixed ( );
+      }
+      else if ( modelselcrit_s == "loo_recognition_rate" )
+      {
+        modelselcrit = new GPMSCLooVarious ( GPMSCLooVarious::P_RECOGNITIONRATE );
+      }
+      else if ( modelselcrit_s == "loo_auc" )
+      {
+        modelselcrit = new GPMSCLooVarious ( GPMSCLooVarious::P_AUC );
+      }
+      else if ( modelselcrit_s == "loo_avgprec" )
+      {
+        modelselcrit = new GPMSCLooVarious ( GPMSCLooVarious::P_AVGPREC );
+      }
+      else
+      {
+        fthrow ( NICE::Exception, "Model selection criterion unknown " << modelselcrit_s << " not (yet) supported." << std::endl <<
+                 "(genericGPModelSelection.h contains a list of classifiers to choose from)" );
+      }
+
+      return modelselcrit;
+    }
 
 };
 

+ 42 - 31
regression/regressionbase/RegressionAlgorithm.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file RegressionAlgorithm.h
 * @brief interface for a regression algorithm
 * @author Erik Rodner
@@ -10,41 +10,52 @@
 
 #include "core/vector/VVector.h"
 
-namespace OBJREC {
-  
-#define ROADWORKS fthrow(Exception, "Persistent Interface: not yet implemented.");
+namespace OBJREC
+{
+
+#define ROADWORKS fthrow(NICE::Exception, "Persistent Interface: not yet implemented.");
 
 /** interface for a regression algorithm */
 class RegressionAlgorithm : public NICE::Persistent
 {
 
-    protected:
-
-    public:
-  
-	/** simple constructor */
-	RegressionAlgorithm();
-      
-	/** simple destructor */
-	virtual ~RegressionAlgorithm();
-
-	/** learn parameters/models/whatever using a set of vectors and
-	 *  their corresponding function values
-	 */
-	virtual void teach ( const NICE::VVector & x, const NICE::Vector & y ) = 0; 
-
-	/** predict the function value for \c x */
-	virtual double predict ( const NICE::Vector & x ) = 0;
-    
-	/** persistent interface */
-	virtual void restore (std::istream & is, int format = 0) { ROADWORKS };
-	virtual void store (std::ostream & os, int format = 0) const { ROADWORKS };
-	virtual void clear () { ROADWORKS };
-
-	/** clone function */
-	virtual RegressionAlgorithm *clone(void) const {
-		fthrow(Exception, "clone() not yet implemented!\n");
-	}
+  protected:
+
+  public:
+
+    /** simple constructor */
+    RegressionAlgorithm();
+
+    /** simple destructor */
+    virtual ~RegressionAlgorithm();
+
+    /** learn parameters/models/whatever using a set of vectors and
+     *  their corresponding function values
+     */
+    virtual void teach ( const NICE::VVector & x, const NICE::Vector & y ) = 0;
+
+    /** predict the function value for \c x */
+    virtual double predict ( const NICE::Vector & x ) = 0;
+
+    /** persistent interface */
+    virtual void restore ( std::istream & is, int format = 0 )
+    {
+      ROADWORKS
+    };
+    virtual void store ( std::ostream & os, int format = 0 ) const
+    {
+      ROADWORKS
+    };
+    virtual void clear ()
+    {
+      ROADWORKS
+    };
+
+    /** clone function */
+    virtual RegressionAlgorithm *clone ( void ) const
+    {
+      fthrow ( NICE::Exception, "clone() not yet implemented!\n" );
+    }
 
 };
 

+ 49 - 47
regression/regressionbase/RegressionAlgorithmKernel.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file RegressionAlgorithmKernel.h
 * @brief interface for a regression algorithm which is based on kernels
 * @author Erik Rodner
@@ -12,55 +12,57 @@
 #include "vislearning/math/kernels/KernelData.h"
 #include "RegressionAlgorithm.h"
 
-namespace OBJREC {
-  
+namespace OBJREC
+{
+
 /** interface for a regression algorithm which is based on kernels */
 class RegressionAlgorithmKernel : public RegressionAlgorithm
 {
-    protected:
-		NICE::VVector X;
-		NICE::Vector y;
-
-		NICE::Config conf;
-
-		Kernel *kernelFunction;
-
-    public:
-  
-		/** simple constructor */
-		RegressionAlgorithmKernel( const NICE::Config *conf, Kernel *kernelFunction = NULL );
-
-		/** copy constructor */
-		RegressionAlgorithmKernel( const RegressionAlgorithmKernel & src );
-		  
-		/** simple destructor */
-		virtual ~RegressionAlgorithmKernel();
-		 
-		/** learn parameters/models/whatever with a kernel matrix (contained in a general structure kernel data)
-		 *  of a set
-		 *  of vectors and the corresponding function values \c y 
-		 */
-		virtual void teach ( KernelData *kernelData, const NICE::Vector & y ) = 0;
-
-		/** predict the function value for a vector by using its kernel values with
-		 * the used training set, be careful with the order in \c kernelVector
-		 */
-		virtual double predictKernel ( const NICE::Vector & kernelVector, double kernelSelf ) = 0;
-		
-		// functions to build an interface to RegressionAlgorithm
-		
-		/** learn parameters/models/whatever using a set of vectors and
-		 *  their corresponding function values
-		 */
-		void teach ( const NICE::VVector & X, const NICE::Vector & y ); 
-
-		/** predict the function value for \c x */
-		double predict ( const NICE::Vector & x );
-
-		/** clone function */
-		virtual RegressionAlgorithmKernel *clone(void) const {
-			fthrow(Exception, "clone() not yet implemented!\n");
-		}
+  protected:
+    NICE::VVector X;
+    NICE::Vector y;
+
+    NICE::Config conf;
+
+    Kernel *kernelFunction;
+
+  public:
+
+    /** simple constructor */
+    RegressionAlgorithmKernel ( const NICE::Config *conf, Kernel *kernelFunction = NULL );
+
+    /** copy constructor */
+    RegressionAlgorithmKernel ( const RegressionAlgorithmKernel & src );
+
+    /** simple destructor */
+    virtual ~RegressionAlgorithmKernel();
+
+    /** learn parameters/models/whatever with a kernel matrix (contained in a general structure kernel data)
+     *  of a set
+     *  of vectors and the corresponding function values \c y
+     */
+    virtual void teach ( KernelData *kernelData, const NICE::Vector & y ) = 0;
+
+    /** predict the function value for a vector by using its kernel values with
+     * the used training set, be careful with the order in \c kernelVector
+     */
+    virtual double predictKernel ( const NICE::Vector & kernelVector, double kernelSelf ) = 0;
+
+    // functions to build an interface to RegressionAlgorithm
+
+    /** learn parameters/models/whatever using a set of vectors and
+     *  their corresponding function values
+     */
+    void teach ( const NICE::VVector & X, const NICE::Vector & y );
+
+    /** predict the function value for \c x */
+    double predict ( const NICE::Vector & x );
+
+    /** clone function */
+    virtual RegressionAlgorithmKernel *clone ( void ) const
+    {
+      fthrow ( NICE::Exception, "clone() not yet implemented!\n" );
+    }
 
 };