فهرست منبع

some bugs with pca fixed

Bjoern Froehlich 13 سال پیش
والد
کامیت
e54a7744c0
5فایلهای تغییر یافته به همراه641 افزوده شده و 625 حذف شده
  1. 26 26
      baselib/RunningStat.h
  2. 317 317
      cbaselib/LabeledSet.cpp
  3. 107 95
      cbaselib/LabeledSet.h
  4. 135 129
      math/ftransform/PCA.cpp
  5. 56 58
      math/ftransform/PCA.h

+ 26 - 26
baselib/RunningStat.h

@@ -1,4 +1,4 @@
-/** 
+/**
  * @file RunningStat.h
  * @brief B. P. Welford Computation of Mean and Variance download at: http://www.johndcook.com/standard_deviation.html
  * @author Michael Koch
@@ -12,31 +12,31 @@ namespace OBJREC {
 /** @brief online statistics */
 class RunningStat
 {
-     public:
-          RunningStat() : m_n(0) {}
-
-	  /** clear the current statistics */
-          void Clear();
-          
-	  /** add a new data element */
-          void Push(double x);
-          
-	  /** get number of data elements */
-          size_t NumDataValues() const;
-
-	  /** get mean value */
-          double Mean() const;
-          
-	  /** get variance */
-	  double Variance() const;
-          
-	  /** get standard deviation */
-          double StandardDeviation() const;
-         
-
-     private:
-          size_t m_n;
-          double m_oldM, m_newM, m_oldS, m_newS;
+  public:
+    RunningStat() : m_n ( 0 ) {}
+
+    /** clear the current statistics */
+    void Clear();
+
+    /** add a new data element */
+    void Push ( double x );
+
+    /** get number of data elements */
+    size_t NumDataValues() const;
+
+    /** get mean value */
+    double Mean() const;
+
+    /** get variance */
+    double Variance() const;
+
+    /** get standard deviation */
+    double StandardDeviation() const;
+
+
+  private:
+    size_t m_n;
+    double m_oldM, m_newM, m_oldS, m_newS;
 };
 
 }

+ 317 - 317
cbaselib/LabeledSet.cpp

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file LabeledSet.cpp
 * @brief Labeled set of vectors
 * @author Erik Rodner
@@ -23,93 +23,93 @@ using namespace std;
 using namespace NICE;
 
 
-LabeledSet::LabeledSet ( bool _selection ) : selection(_selection)
+LabeledSet::LabeledSet ( bool _selection ) : selection ( _selection )
 {
 }
-	
+
 LabeledSet::~LabeledSet ()
 {
-    //This is a big problem when using selections
-    //clear();
-    //fprintf (stderr, "LabeledSet: destructor (FIXME: memory leak)\n");
+  //This is a big problem when using selections
+  //clear();
+  //fprintf (stderr, "LabeledSet: destructor (FIXME: memory leak)\n");
 }
 
 int LabeledSet::count ( int classno ) const
 {
-    const_iterator i = find(classno);
-    return ( i == end() ) ? 0 : i->second.size();
+  const_iterator i = find ( classno );
+  return ( i == end() ) ? 0 : i->second.size();
 }
 
 int LabeledSet::count () const
 {
-    int mycount = 0;
-    for ( const_iterator i = begin() ; i != end() ; i++ )
-    {
-		mycount += i->second.size();
-    }
-    return mycount;
+  int mycount = 0;
+  for ( const_iterator i = begin() ; i != end() ; i++ )
+  {
+    mycount += i->second.size();
+  }
+  return mycount;
 }
 
 void LabeledSet::clear ()
 {
-    if ( !selection ) 
+  if ( !selection )
+  {
+    for ( Permutation::const_iterator i  = insertOrder.begin();
+          i != insertOrder.end();
+          i++ )
     {
-		for ( Permutation::const_iterator i  = insertOrder.begin(); 
-						  i != insertOrder.end();
-						  i++ )
-		{
-			const ImageInfo *s = i->second;
-			delete s;
-		}
+      const ImageInfo *s = i->second;
+      delete s;
     }
-    
-    std::map< int, vector<ImageInfo *> >::clear();
+  }
+
+  std::map< int, vector<ImageInfo *> >::clear();
 }
 
 void LabeledSet::add ( int classno, ImageInfo *x )
 {
-    if ( selection ) {
-		fprintf (stderr, "Operation not available for selections !\n");
-		exit(-1);
-    }
-
-    iterator i = find(classno);
-    if ( i == end() ) {
-		operator[](classno) = vector<ImageInfo *>();
-		i = find(classno);
-    }
-    i->second.push_back ( x ); 
-    insertOrder.push_back ( ElementPointer ( classno, x ) );
+  if ( selection ) {
+    fprintf ( stderr, "Operation not available for selections !\n" );
+    exit ( -1 );
+  }
+
+  iterator i = find ( classno );
+  if ( i == end() ) {
+    operator[] ( classno ) = vector<ImageInfo *>();
+    i = find ( classno );
+  }
+  i->second.push_back ( x );
+  insertOrder.push_back ( ElementPointer ( classno, x ) );
 }
-	
+
 void LabeledSet::getPermutation ( Permutation & permutation ) const
 {
-    permutation = Permutation ( insertOrder );
+  permutation = Permutation ( insertOrder );
 }
 
 void LabeledSet::add_reference ( int classno, ImageInfo *pointer )
 {
-    iterator i = find(classno);
-    if ( i == end() ) {
-		operator[](classno) = vector<ImageInfo *>();
-		i = find(classno);
-    }
-    i->second.push_back ( pointer ); 
-    insertOrder.push_back ( ElementPointer ( classno, pointer ) );
+  iterator i = find ( classno );
+  if ( i == end() ) {
+    operator[] ( classno ) = vector<ImageInfo *>();
+    i = find ( classno );
+  }
+  i->second.push_back ( pointer );
+  insertOrder.push_back ( ElementPointer ( classno, pointer ) );
 }
 
 void LabeledSet::getClasses ( std::vector<int> & classes ) const
 {
-    for ( const_iterator i = begin(); i != end(); i++ )
-		classes.push_back ( i->first );
+  for ( const_iterator i = begin(); i != end(); i++ )
+    classes.push_back ( i->first );
 }
 
 void LabeledSet::printInformation () const
 {
-    for ( const_iterator i = begin(); i != end(); i++ )
-    {
-	cerr << "class " << i->first << ": " << i->second.size() << endl;
-    }
+  for ( const_iterator i = begin(); i != end(); i++ )
+  {
+    cerr << "class " << i->first << ": " << i->second.size() << endl;
+  }
 }
 
 
@@ -118,353 +118,353 @@ void LabeledSet::printInformation () const
 *************************************/
 
 
-LabeledSetVector::LabeledSetVector (bool _selection) : selection(_selection)
+LabeledSetVector::LabeledSetVector ( bool _selection ) : selection ( _selection )
 {}
-	
+
 LabeledSetVector::~LabeledSetVector ()
 {
-    // FIXME: THIS is a big problem with selections !!!
-    //clear();
+  // FIXME: THIS is a big problem with selections !!!
+  //clear();
 }
 
 int LabeledSetVector::dimension () const
 {
-    if ( insertOrder.size() <= 0 ) return -1;
-    return (*(begin()->second.begin()))->size();
-    //insertOrder[0].second->size();
+  if ( insertOrder.size() <= 0 ) return -1;
+  return ( * ( begin()->second.begin() ) )->size();
+  //insertOrder[0].second->size();
 }
 
-void LabeledSetVector::restore (istream & is, int format)
+void LabeledSetVector::restore ( istream & is, int format )
 {
-    if ( format == FILEFORMAT_RAW )
-		restoreRAW ( is );
-    else
-		restoreASCII ( is, format );
+  if ( format == FILEFORMAT_RAW )
+    restoreRAW ( is );
+  else
+    restoreASCII ( is, format );
 }
 
-void LabeledSetVector::restoreASCII (istream & is, int format)
+void LabeledSetVector::restoreASCII ( istream & is, int format )
 {
-    const int bufsize = 1024*1024;
-    char *buf = new char[bufsize];
-    std::string buf_s;
+  const int bufsize = 1024 * 1024;
+  char *buf = new char[bufsize];
+  std::string buf_s;
+
+  vector<string> elements;
+  vector<string> pair;
 
-    vector<string> elements;
-    vector<string> pair;
+  // maximal dimension of all feature vectors;
+  int dataset_dimension = -numeric_limits<int>::max();
 
-	// maximal dimension of all feature vectors;
-	int dataset_dimension = -numeric_limits<int>::max();
+  while ( ! is.eof() )
+  {
+    elements.clear();
+    int classno;
 
-    while (! is.eof())
+    if ( ! ( is >> classno ) ) {
+      break;
+    }
+
+    is.get ( buf, bufsize );
+    buf_s = buf;
+
+    if ( buf_s.size() <= 0 )
+      break;
+
+    StringTools::split ( buf_s, ' ', elements );
+
+    if ( elements.size() <= 1 )
+      break;
+
+    int dimension = - numeric_limits<int>::max();
+    if ( format == FILEFORMAT_INDEX_SPARSE_ONE )
     {
-		elements.clear();
-		int classno;
-		
-		if ( ! (is >> classno) ) {
-			break;
-		}
-
-		is.get ( buf, bufsize );
-		buf_s = buf;
-
-		if ( buf_s.size() <= 0 ) 
-			break;
-
-		StringTools::split ( buf_s, ' ', elements );
-
-		if ( elements.size() <= 1 )
-			break;
-		
-		int dimension = - numeric_limits<int>::max();
-		if ( format == FILEFORMAT_INDEX_SPARSE_ONE ) 
-		{
-			// in this format we have to determine the maximum index
-			for ( vector<string>::const_iterator i  = elements.begin()+1; 
-							 i != elements.end();
-							 i++ ) 
-			{
-				pair.clear();
-				StringTools::split ( *i, ':', pair );
-				if ( pair.size() != 2 ) continue;
-
-				int index = atoi(pair[0].c_str());
-				
-				if ( index > dimension )
-					dimension = index;
-			}
-
-			if ( dimension > dataset_dimension )
-				dataset_dimension = dimension;
-
-			
-		} else {
-			// skip first element because of white space
-			dimension = elements.size()-1;
-		}
-
-
-		NICE::Vector vec ( dimension, 0.0 );
-		size_t l = 0;
-
-		// skip first element because of white space
-		for ( vector<string>::const_iterator i  = elements.begin()+1; 
-							 i != elements.end();
-							 i++, l++ )
-		{
-			if ( format == FILEFORMAT_INDEX ) 
-			{
-				pair.clear();
-				StringTools::split ( *i, ':', pair );
-				if ( pair.size() == 2 ) {
-					double val = atof ( pair[1].c_str() );
-					vec[l] = val;
-				}
-			} else if ( format == FILEFORMAT_INDEX_SPARSE_ONE ) 
-			{
-				pair.clear();
-				StringTools::split ( *i, ':', pair );
-				if ( pair.size() == 2 ) {
-					double val = atof ( pair[1].c_str() );
-					int index = atoi ( pair[0].c_str() ) - 1;
-					vec[index] = val;
-				}
-			} else {
-				vec[l] = atof( i->c_str() );
-			}
-		}
-		add( classno, vec );
+      // in this format we have to determine the maximum index
+      for ( vector<string>::const_iterator i  = elements.begin() + 1;
+            i != elements.end();
+            i++ )
+      {
+        pair.clear();
+        StringTools::split ( *i, ':', pair );
+        if ( pair.size() != 2 ) continue;
+
+        int index = atoi ( pair[0].c_str() );
+
+        if ( index > dimension )
+          dimension = index;
+      }
+
+      if ( dimension > dataset_dimension )
+        dataset_dimension = dimension;
+
+
+    } else {
+      // skip first element because of white space
+      dimension = elements.size() - 1;
     }
-    delete [] buf;
-
-	if ( format == FILEFORMAT_INDEX_SPARSE_ONE ) {
-		// we have to resize all feature vectors of the dataset to dataset_dimension
-		for ( LabeledSetVector::iterator iLOOP_ALL = begin() ; iLOOP_ALL != end() ; iLOOP_ALL++)
-			for ( vector<NICE::Vector *>::iterator jLOOP_ALL = iLOOP_ALL->second.begin(); 
-									 jLOOP_ALL != iLOOP_ALL->second.end(); 
-									 jLOOP_ALL++ )
-			{
-				NICE::Vector *x = (*jLOOP_ALL);
-
-				uint old_dimension = x->size();
-
-				// resize the vector to the dataset dimension
-				x->resize(dataset_dimension);
-				
-				// set all elements to zero, which are new after the resize operation
-				for ( uint k = old_dimension; k < x->size(); k++ )
-					(*x)[k] = 0.0;
-			}
-	}
-}
 
-void LabeledSetVector::store (ostream & os, int format) const
-{
-    for ( Permutation::const_iterator i  = insertOrder.begin();
-				      i != insertOrder.end();
-				      i++ )
+
+    NICE::Vector vec ( dimension, 0.0 );
+    size_t l = 0;
+
+    // skip first element because of white space
+    for ( vector<string>::const_iterator i  = elements.begin() + 1;
+          i != elements.end();
+          i++, l++ )
     {
-		int classno = i->first;
-		const NICE::Vector & x = *(i->second);
-		
-		storeElement ( os, classno, x, format );
+      if ( format == FILEFORMAT_INDEX )
+      {
+        pair.clear();
+        StringTools::split ( *i, ':', pair );
+        if ( pair.size() == 2 ) {
+          double val = atof ( pair[1].c_str() );
+          vec[l] = val;
+        }
+      } else if ( format == FILEFORMAT_INDEX_SPARSE_ONE )
+      {
+        pair.clear();
+        StringTools::split ( *i, ':', pair );
+        if ( pair.size() == 2 ) {
+          double val = atof ( pair[1].c_str() );
+          int index = atoi ( pair[0].c_str() ) - 1;
+          vec[index] = val;
+        }
+      } else {
+        vec[l] = atof ( i->c_str() );
+      }
     }
+    add ( classno, vec );
+  }
+  delete [] buf;
+
+  if ( format == FILEFORMAT_INDEX_SPARSE_ONE ) {
+    // we have to resize all feature vectors of the dataset to dataset_dimension
+    for ( LabeledSetVector::iterator iLOOP_ALL = begin() ; iLOOP_ALL != end() ; iLOOP_ALL++ )
+      for ( vector<NICE::Vector *>::iterator jLOOP_ALL = iLOOP_ALL->second.begin();
+            jLOOP_ALL != iLOOP_ALL->second.end();
+            jLOOP_ALL++ )
+      {
+        NICE::Vector *x = ( *jLOOP_ALL );
+
+        uint old_dimension = x->size();
+
+        // resize the vector to the dataset dimension
+        x->resize ( dataset_dimension );
+
+        // set all elements to zero, which are new after the resize operation
+        for ( uint k = old_dimension; k < x->size(); k++ )
+          ( *x ) [k] = 0.0;
+      }
+  }
+}
+
+void LabeledSetVector::store ( ostream & os, int format ) const
+{
+  for ( Permutation::const_iterator i  = insertOrder.begin();
+        i != insertOrder.end();
+        i++ )
+  {
+    int classno = i->first;
+    const NICE::Vector & x = * ( i->second );
+
+    storeElement ( os, classno, x, format );
+  }
 }
 
 void LabeledSetVector::storeElement ( ostream & os, int classno, const NICE::Vector & x, int format )
 {
-    if ( format != FILEFORMAT_RAW ) {
-		os << classno << " ";
-		for ( size_t k = 0 ; k < x.size() ; k++ )
-		{
-			if ( format == FILEFORMAT_INDEX )
-				os << k+1 << ":" << x[k];
-			else if ( format == FILEFORMAT_NOINDEX )  
-				os << x[k];
-			else if ( format == FILEFORMAT_INDEX_SPARSE_ONE )  {
-				if ( x[k] != 0.0 ) 
-					os << k+1 << ":" << x[k];
-			}
-
-			if ( k != x.size() )
-				os << " ";
-		}
-		os << endl;
-	} else {
-		const double *data = x.getDataPointer();
-		int dimension = x.size();
-
-		os.write ( (char *)&classno, sizeof(int) );
-		os.write ( (char *)&dimension, sizeof(int) );
-		os.write ( (char *)data, sizeof(double)*dimension );
+  if ( format != FILEFORMAT_RAW ) {
+    os << classno << " ";
+    for ( size_t k = 0 ; k < x.size() ; k++ )
+    {
+      if ( format == FILEFORMAT_INDEX )
+        os << k + 1 << ":" << x[k];
+      else if ( format == FILEFORMAT_NOINDEX )
+        os << x[k];
+      else if ( format == FILEFORMAT_INDEX_SPARSE_ONE )  {
+        if ( x[k] != 0.0 )
+          os << k + 1 << ":" << x[k];
+      }
+
+      if ( k != x.size() )
+        os << " ";
     }
+    os << endl;
+  } else {
+    const double *data = x.getDataPointer();
+    int dimension = x.size();
+
+    os.write ( ( char * ) &classno, sizeof ( int ) );
+    os.write ( ( char * ) &dimension, sizeof ( int ) );
+    os.write ( ( char * ) data, sizeof ( double ) *dimension );
+  }
 }
 
-void LabeledSetVector::restoreRAW (istream & is)
+void LabeledSetVector::restoreRAW ( istream & is )
 {
-    while (! is.eof())
-    {
-		int classno;
-		int dimension;
-
-		is.read ( (char *)&classno, sizeof(int) );
-		if ( is.gcount() != sizeof(int) )
-			return;
-
-		is.read ( (char *)&dimension, sizeof(int) );
-		if ( is.gcount() != sizeof(int) )
-			return;
-
-		NICE::Vector vec;
-
-		try {
-			vec.resize(dimension);
-		} catch ( std::bad_alloc ) {
-			fthrow(IOException, "Unable to allocate a vector with size " << dimension << "." << endl 
-					<< "(debug: class " << classno << " ; " << "sizeof(int) = " << 8*sizeof(int) << " Bit ; " << endl
-					<< "elements read = " << count() << " )" << endl );
-		}
-		double *data = vec.getDataPointer();
-
-		is.read ( (char *)data, sizeof(double)*dimension );
-		if ( (int)is.gcount() != (int)sizeof(double)*dimension )
-			return;
-
-		for ( int k = 0 ; k < dimension ; k++ )
-			if ( isnan(data[k]) ) {
-				cerr << "WARNING: nan's found !!" << endl;
-				data[k] = 0.0;
-			}
-		
-		add( classno, vec );
+  while ( ! is.eof() )
+  {
+    int classno;
+    int dimension;
+
+    is.read ( ( char * ) &classno, sizeof ( int ) );
+    if ( is.gcount() != sizeof ( int ) )
+      return;
+
+    is.read ( ( char * ) &dimension, sizeof ( int ) );
+    if ( is.gcount() != sizeof ( int ) )
+      return;
+
+    NICE::Vector vec;
+
+    try {
+      vec.resize ( dimension );
+    } catch ( std::bad_alloc ) {
+      fthrow ( IOException, "Unable to allocate a vector with size " << dimension << "." << endl
+               << "(debug: class " << classno << " ; " << "sizeof(int) = " << 8*sizeof ( int ) << " Bit ; " << endl
+               << "elements read = " << count() << " )" << endl );
     }
+    double *data = vec.getDataPointer();
+
+    is.read ( ( char * ) data, sizeof ( double ) *dimension );
+    if ( ( int ) is.gcount() != ( int ) sizeof ( double ) *dimension )
+      return;
+
+    for ( int k = 0 ; k < dimension ; k++ )
+      if ( isnan ( data[k] ) ) {
+        cerr << "WARNING: nan's found !!" << endl;
+        data[k] = 0.0;
+      }
+
+    add ( classno, vec );
+  }
 }
 
 LabeledSetVector::ElementPointer LabeledSetVector::pickRandomSample () const
 {
-    if ( insertOrder.size() <= 0 ) {
-		fprintf (stderr, "LabeledSet::pickRandomSample: failure !\n");
-		exit(-1);
-    }
-    
-    int selection = rand() % insertOrder.size();
-    return insertOrder[selection];
+  if ( insertOrder.size() <= 0 ) {
+    fprintf ( stderr, "LabeledSet::pickRandomSample: failure !\n" );
+    exit ( -1 );
+  }
+
+  int selection = rand() % insertOrder.size();
+  return insertOrder[selection];
 }
 
 int LabeledSetVector::count ( int classno ) const
 {
-    const_iterator i = find(classno);
-    return ( i == end() ) ? 0 : i->second.size();
+  const_iterator i = find ( classno );
+  return ( i == end() ) ? 0 : i->second.size();
 }
 
 int LabeledSetVector::count () const
 {
-    int mycount = 0;
-    for ( const_iterator i = begin() ; i != end() ; i++ )
-		mycount += i->second.size();
-    return mycount;
+  int mycount = 0;
+  for ( const_iterator i = begin() ; i != end() ; i++ )
+    mycount += i->second.size();
+  return mycount;
 }
 
 int LabeledSetVector::pickRandomSample ( int classno, ElementPointer & i ) const
 {
-    const_iterator j = find(classno);
-    if ( j == end() ) return -1;
+  const_iterator j = find ( classno );
+  if ( j == end() ) return -1;
 
-    const vector<Vector *> & l = j->second;
-    int num = rand() % l.size();
+  const vector<Vector *> & l = j->second;
+  int num = rand() % l.size();
 
-    i.first = classno;
-    i.second = l[num];
+  i.first = classno;
+  i.second = l[num];
 
-    return classno;
+  return classno;
 }
 
 void LabeledSetVector::clear ()
 {
-    if ( ! selection ) {
-		for ( Permutation::const_iterator i  = insertOrder.begin(); 
-						  i != insertOrder.end();
-						  i++ )
-		{
-			const NICE::Vector *s = i->second;
-			delete s;
-		}
-		insertOrder.clear();
+  if ( ! selection ) {
+    for ( Permutation::const_iterator i  = insertOrder.begin();
+          i != insertOrder.end();
+          i++ )
+    {
+      const NICE::Vector *s = i->second;
+      delete s;
     }
+    insertOrder.clear();
+  }
 
-    std::map< int, vector<Vector *> >::clear();
+  std::map< int, vector<Vector *> >::clear();
 }
 
 void LabeledSetVector::add ( int classno, const NICE::Vector & x )
 {
-    if ( selection ) {
-		fprintf (stderr, "Add operation not available for selections !\n");
-		exit(-1);
-    }
-
-    iterator i = find(classno);
-    if ( i == end() ) {
-		operator[](classno) = vector<Vector *>();
-		i = find(classno);
-    }
-    NICE::Vector *xp = new Vector(x);
-
-    i->second.push_back ( xp ); 
-    insertOrder.push_back ( ElementPointer ( classno, xp ) );
+  if ( selection ) {
+    fprintf ( stderr, "Add operation not available for selections !\n" );
+    exit ( -1 );
+  }
+
+  iterator i = find ( classno );
+  if ( i == end() ) {
+    operator[] ( classno ) = vector<Vector *>();
+    i = find ( classno );
+  }
+  NICE::Vector *xp = new Vector ( x );
+
+  i->second.push_back ( xp );
+  insertOrder.push_back ( ElementPointer ( classno, xp ) );
 }
-    
+
 void LabeledSetVector::getPermutation ( Permutation & permutation ) const
 {
-    permutation = Permutation ( insertOrder );
+  permutation = Permutation ( insertOrder );
 }
 
 void LabeledSetVector::add_reference ( int classno, NICE::Vector *pointer )
 {
-    iterator i = find(classno);
-    if ( i == end() ) {
-		operator[](classno) = vector<Vector *>();
-		i = find(classno);
-    }
-    i->second.push_back ( pointer ); 
-    insertOrder.push_back ( ElementPointer ( classno, pointer ) );
+  iterator i = find ( classno );
+  if ( i == end() ) {
+    operator[] ( classno ) = vector<Vector *>();
+    i = find ( classno );
+  }
+  i->second.push_back ( pointer );
+  insertOrder.push_back ( ElementPointer ( classno, pointer ) );
 }
-	
+
 void LabeledSetVector::getClasses ( std::vector<int> & classes ) const
 {
-    for ( const_iterator i = begin(); i != end(); i++ )
-	classes.push_back ( i->first );
+  for ( const_iterator i = begin(); i != end(); i++ )
+    classes.push_back ( i->first );
 }
-	
+
 void LabeledSetVector::printInformation () const
 {
-    for ( const_iterator i = begin(); i != end(); i++ )
-    {
-		cerr << "class " << i->first << ": " << i->second.size() << endl;
-    }
+  for ( const_iterator i = begin(); i != end(); i++ )
+  {
+    cerr << "class " << i->first << ": " << i->second.size() << endl;
+  }
 }
-	
+
 int LabeledSetVector::getMaxClassno() const
 {
-    int maxclassno = 0;
+  int maxclassno = 0;
 
-    for ( const_iterator i = begin(); i != end(); i++ )
-		if ( i->first > maxclassno ) 
-			maxclassno = i->first;
+  for ( const_iterator i = begin(); i != end(); i++ )
+    if ( i->first > maxclassno )
+      maxclassno = i->first;
 
-    return maxclassno;
+  return maxclassno;
 }
 
 void LabeledSetVector::getFlatRepresentation ( VVector & vecSet, NICE::Vector & vecSetLabels ) const
 {
-	int k = 0;
-	vecSetLabels.resize(count());
-	for ( LabeledSetVector::const_iterator iLOOP_ALL = begin() ; iLOOP_ALL != end() ; iLOOP_ALL++)
-		for ( vector<NICE::Vector *>::const_iterator jLOOP_ALL = iLOOP_ALL->second.begin(); 
-								 jLOOP_ALL != iLOOP_ALL->second.end(); 
-								 jLOOP_ALL++,k++ )
-		{
-			const NICE::Vector & (x) = *(*jLOOP_ALL);
-			vecSet.push_back ( x );
-			vecSetLabels[k] = iLOOP_ALL->first;
-		}
+  int k = 0;
+  vecSetLabels.resize ( count() );
+  for ( LabeledSetVector::const_iterator iLOOP_ALL = begin() ; iLOOP_ALL != end() ; iLOOP_ALL++ )
+    for ( vector<NICE::Vector *>::const_iterator jLOOP_ALL = iLOOP_ALL->second.begin();
+          jLOOP_ALL != iLOOP_ALL->second.end();
+          jLOOP_ALL++, k++ )
+    {
+      const NICE::Vector & ( x ) = * ( *jLOOP_ALL );
+      vecSet.push_back ( x );
+      vecSetLabels[k] = iLOOP_ALL->first;
+    }
 
 }
 

+ 107 - 95
cbaselib/LabeledSet.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file LabeledSet.h
 * @brief Labeled set of vectors
 * @author Erik Rodner
@@ -18,143 +18,155 @@
 #include "ImageInfo.h"
 
 #define LOOP_ALL(ls) for(LabeledSetVector::const_iterator iLOOP_ALL = (ls).begin() ; iLOOP_ALL != (ls).end() ; iLOOP_ALL++) \
-				    for ( std::vector<NICE::Vector *>::const_iterator jLOOP_ALL = iLOOP_ALL->second.begin(); \
-									 jLOOP_ALL != iLOOP_ALL->second.end(); \
-									 jLOOP_ALL++ )
+    for ( std::vector<NICE::Vector *>::const_iterator jLOOP_ALL = iLOOP_ALL->second.begin(); \
+          jLOOP_ALL != iLOOP_ALL->second.end(); \
+          jLOOP_ALL++ )
 #define EACH(classno,x) int (classno) = iLOOP_ALL->first; \
-			const NICE::Vector & (x) = *(*jLOOP_ALL);
-	
+  const NICE::Vector & (x) = *(*jLOOP_ALL);
+
 #define LOOP_ALL_NONCONST(ls) for(LabeledSetVector::iterator iLOOP_ALL = (ls).begin() ; iLOOP_ALL != (ls).end() ; iLOOP_ALL++) \
-				    for ( std::vector<NICE::Vector *>::iterator jLOOP_ALL = iLOOP_ALL->second.begin(); \
-									 jLOOP_ALL != iLOOP_ALL->second.end(); \
-									 jLOOP_ALL++ )
+    for ( std::vector<NICE::Vector *>::iterator jLOOP_ALL = iLOOP_ALL->second.begin(); \
+          jLOOP_ALL != iLOOP_ALL->second.end(); \
+          jLOOP_ALL++ )
 #define EACH_NONCONST(classno,x) int (classno) = iLOOP_ALL->first; \
-			NICE::Vector & (x) = *(*jLOOP_ALL);
-				
+  NICE::Vector & (x) = *(*jLOOP_ALL);
+
 #define LOOP_ALL_S(ls) for(LabeledSet::const_iterator iLOOP_ALL = (ls).begin() ; iLOOP_ALL != (ls).end() ; iLOOP_ALL++) \
-				    for ( std::vector<ImageInfo *>::const_iterator jLOOP_ALL = iLOOP_ALL->second.begin(); \
-									 jLOOP_ALL != iLOOP_ALL->second.end(); \
-									 jLOOP_ALL++ )
+    for ( std::vector<ImageInfo *>::const_iterator jLOOP_ALL = iLOOP_ALL->second.begin(); \
+          jLOOP_ALL != iLOOP_ALL->second.end(); \
+          jLOOP_ALL++ )
 #define EACH_S(classno,x) int (classno) = iLOOP_ALL->first; \
-			const std::string & (x) = (*jLOOP_ALL)->img();
+  const std::string & (x) = (*jLOOP_ALL)->img();
 
 #define EACH_INFO(classno,x) int (classno) = iLOOP_ALL->first; \
-			const ImageInfo & (x) = *(*jLOOP_ALL);
+  const ImageInfo & (x) = *(*jLOOP_ALL);
 
 
 namespace OBJREC {
 
-class LabeledSet : 
-	public std::map< int, std::vector<ImageInfo *> >
+class LabeledSet :
+      public std::map< int, std::vector<ImageInfo *> >
 {
-    public:
-	typedef std::vector<std::string *> ElementIterator;
-	typedef std::pair<size_t, const ImageInfo *> ElementPointer;
-	typedef std::vector< ElementPointer > Permutation;
+  public:
+    typedef std::vector<std::string *> ElementIterator;
+    typedef std::pair<size_t, const ImageInfo *> ElementPointer;
+    typedef std::vector< ElementPointer > Permutation;
+
+  private:
+    bool selection;
 
-    private:
-	bool selection;
+    Permutation insertOrder;
 
-	Permutation insertOrder;
+  public:
 
-    public:
+    void add_reference ( int classno, ImageInfo *pointer );
 
-	void add_reference ( int classno, ImageInfo *pointer );
+    LabeledSet ( bool selection = false );
+    ~LabeledSet ();
 
-	LabeledSet ( bool selection = false );
-	~LabeledSet ();
+    int numClasses () const
+    {
+      return size();
+    }
 
-	int numClasses () const
-	{   return size();   }
+    int count ( int classno ) const;
+    int count () const;
 
-	int count ( int classno ) const;
-	int count () const;
-	
-	void clear ();
+    void clear ();
 
-	void add ( int classno, ImageInfo *x );
+    void add ( int classno, ImageInfo *x );
 
-	void getPermutation ( Permutation & permutation ) const; 
-	void getClasses ( std::vector<int> & classes ) const; 
+    void getPermutation ( Permutation & permutation ) const;
+    void getClasses ( std::vector<int> & classes ) const;
 
-	void printInformation () const;
+    void printInformation () const;
 
-	friend class LabeledSetSelection<LabeledSet>;
+    friend class LabeledSetSelection<LabeledSet>;
 };
 
 
 /** simple labeled set of vectors as a specialization of std::map<> */
-class LabeledSetVector : 
-	public std::map< int, std::vector<NICE::Vector *> >, 
-	public NICE::Persistent
+class LabeledSetVector :
+      public std::map< int, std::vector<NICE::Vector *> >,
+      public NICE::Persistent
 {
-    public:
-	typedef std::vector<NICE::Vector *> ElementIterator;
-	typedef std::pair<int, const NICE::Vector *> ElementPointer;
-	typedef std::vector< ElementPointer > Permutation;	
-
-	enum {
-	    FILEFORMAT_INDEX = 0,
-	    FILEFORMAT_NOINDEX = 1,
-	    FILEFORMAT_RAW = 2,
-	    FILEFORMAT_INDEX_SPARSE_ONE = 3
-	};
-    
-    private:
-	bool selection;
+  public:
+    typedef std::vector<NICE::Vector *> ElementIterator;
+    typedef std::pair<int, const NICE::Vector *> ElementPointer;
+    typedef std::vector< ElementPointer > Permutation;
+
+    enum {
+      FILEFORMAT_INDEX = 0,
+      FILEFORMAT_NOINDEX = 1,
+      FILEFORMAT_RAW = 2,
+      FILEFORMAT_INDEX_SPARSE_ONE = 3
+    };
 
-	Permutation insertOrder;
+  private:
+    bool selection;
 
-    public:
+    Permutation insertOrder;
 
-	LabeledSetVector ( bool selection = false );
-	~LabeledSetVector ();
+  public:
 
-	void add_reference ( int classno, NICE::Vector *pointer );
+    LabeledSetVector ( bool selection = false );
+    ~LabeledSetVector ();
 
-	int dimension () const;
+    void add_reference ( int classno, NICE::Vector *pointer );
 
-	int numClasses () const
-	{   return size();   }
+    int dimension () const;
+
+    int numClasses () const
+    {
+      return size();
+    }
+
+    void restore ( std::istream & is, int format = FILEFORMAT_INDEX );
+    void restoreRAW ( std::istream & is );
+    void restoreASCII ( std::istream & is, int format = FILEFORMAT_INDEX );
+    void store ( std::ostream & os, int format = FILEFORMAT_INDEX ) const;
+    static void storeElement ( std::ostream & os, int classno, const NICE::Vector & x, int format = FILEFORMAT_INDEX );
+
+    ElementPointer pickRandomSample () const;
+
+    int count ( int classno ) const;
+    
+    /**
+     * @brief count all features
+     *
+     * @return int number of features
+     **/
+    int count () const;
 
-	void restore (std::istream & is, int format = FILEFORMAT_INDEX);
-	void restoreRAW ( std::istream & is );
-	void restoreASCII (std::istream & is, int format = FILEFORMAT_INDEX);
-	void store (std::ostream & os, int format = FILEFORMAT_INDEX) const;
-	static void storeElement ( std::ostream & os, int classno, const NICE::Vector & x, int format = FILEFORMAT_INDEX );
+    int pickRandomSample ( int classno, ElementPointer & i ) const;
 
-	ElementPointer pickRandomSample () const;
+    void clear ();
 
-	int count ( int classno ) const;
-	int count () const;
-	
-	int pickRandomSample ( int classno, ElementPointer & i ) const;
+    /** most important function: add a labeled vector */
+    void add ( int classno, const NICE::Vector & x );
 
-	void clear ();
+    void getPermutation ( Permutation & permutation ) const;
+    void getClasses ( std::vector<int> & classes ) const;
 
-	/** most important function: add a labeled vector */
-	void add ( int classno, const NICE::Vector & x );
+    void printInformation () const;
 
-	void getPermutation ( Permutation & permutation ) const; 
-	void getClasses ( std::vector<int> & classes ) const; 
-	
-	void printInformation () const;
+    void setSelection ( bool _selection = true ) {
+      selection = _selection;
+    };
 
-	void setSelection ( bool _selection = true ) { selection = _selection; };
+    /**
+     * returns the highest class number (not the number of classes!)
+     */
+    int getMaxClassno() const;
 
-	/**
-	 * returns the highest class number (not the number of classes!)
-	 */
-	int getMaxClassno() const;
+    /**
+     * converts LabeledSetVector to a NICE::VVector Set (containing data) and a Labelvector (containing labels for each Data)
+     * @param vecSet dataset (output)
+     * @param vecSetLabels labels (output)
+     */
+    void getFlatRepresentation ( NICE::VVector & vecSet, NICE::Vector & vecSetLabels ) const;
 
-	/**
-	 * converts LabeledSetVector to a NICE::VVector Set (containing data) and a Labelvector (containing labels for each Data)
-	 * @param vecSet dataset (output)
-	 * @param vecSetLabels labels (output)
-	 */
-	void getFlatRepresentation ( NICE::VVector & vecSet, NICE::Vector & vecSetLabels ) const;
-	
-	friend class LabeledSetSelection<LabeledSetVector>;
+    friend class LabeledSetSelection<LabeledSetVector>;
 };
 
 

+ 135 - 129
math/ftransform/PCA.cpp

@@ -30,39 +30,39 @@ using namespace OBJREC;
 using namespace std;
 using namespace NICE;
 
-PCA::PCA(uint dim, uint maxiteration, double mindelta)
+PCA::PCA ( uint dim, uint maxiteration, double mindelta )
 {
-	init(dim, maxiteration, mindelta);
+  init ( dim, maxiteration, mindelta );
 }
 
-PCA::PCA(void)
+PCA::PCA ( void )
 {
-	init();
+  init();
 }
 
 PCA::~PCA()
 {
 }
 
-void PCA::init(uint dim, uint maxiteration, double mindelta)
+void PCA::init ( uint dim, uint maxiteration, double mindelta )
 {
-	this->targetDimension = dim;
-	this->maxiteration = maxiteration;
-	this->mindelta = mindelta;
+  this->targetDimension = dim;
+  this->maxiteration = maxiteration;
+  this->mindelta = mindelta;
 }
 
-void PCA::restore(istream & is, int format)
+void PCA::restore ( istream & is, int format )
 {
 
-	is >> basis;
-	is >> normalization;
-	is >> mean;
-	is >> targetDimension;
+  is >> basis;
+  is >> normalization;
+  is >> mean;
+  is >> targetDimension;
 }
 
-void PCA::store(ostream & os, int format) const
+void PCA::store ( ostream & os, int format ) const
 {
-	os << basis << normalization << mean << targetDimension;
+  os << basis << normalization << mean << targetDimension;
 }
 
 void PCA::clear()
@@ -70,165 +70,171 @@ void PCA::clear()
 
 }
 
-void PCA::calculateBasis(const NICE::Matrix &features,
-		const uint targetDimension, const uint mode)
+void PCA::calculateBasis ( const NICE::Matrix &features,
+                           const uint targetDimension, const uint mode )
 {
-	calculateBasis(features, targetDimension, false);
+  calculateBasis ( features, targetDimension, false );
 }
 
 void PCA::calculateMean ( const NICE::Matrix &features, NICE::Vector & mean )
 {
   // data vectors are put row-wise in the matrix
-  mean.resize(features.cols());
+  mean.resize ( features.cols() );
+  mean.set(0);
   for ( uint i = 0 ; i < features.rows(); i++ )
-    mean = mean + features.getRow(i);
+    mean = mean + features.getRow ( i );
 }
 
-void PCA::calculateBasis(const NICE::Matrix &features,
-		const uint targetDimension, const bool adaptive,
-		const double targetRatio)
+void PCA::calculateBasis ( const NICE::Matrix &features,
+                           const uint targetDimension, const bool adaptive,
+                           const double targetRatio )
 {
-	this->targetDimension = targetDimension;
+  this->targetDimension = targetDimension;
   // dimension of the feature vectors
-	uint srcFeatureSize = features.cols();
-	uint mindimension = std::min(this->targetDimension, srcFeatureSize);
+  uint srcFeatureSize = features.cols();
+  uint mindimension = std::min ( this->targetDimension, srcFeatureSize );
 
-	NICE::Matrix eigenvectors;
+  NICE::Matrix eigenvectors;
+
+  NICE::Vector eigenvalue;
+
+  calculateMean ( features, mean );
 
-	NICE::Vector eigenvalue;
-  
-  calculateMean(features, mean);
 #ifdef NICE_USELIB_TRLAN
-  EigValues *eig = new EigValuesTRLAN();//fast lanczos TRLAN
+  EigValues *eig;
+  if(mindimension < 4)
+    eig = new EVArnoldi();//Arnoldi for (srcFeatureSize<n)
+  else
+    eig = new EigValuesTRLAN();//fast lanczos TRLAN
 #else
   EigValues *eig = new EVArnoldi();//Arnoldi for (srcFeatureSize<n)
 #endif
   NICE::Matrix features_transpose = features.transpose();
-  GMCovariance C(&features_transpose);
-  if (adaptive)
+  GMCovariance C ( &features_transpose );
+  if ( adaptive )
   {
-    eig->getEigenvalues(C, eigenvalue, eigenvectors, srcFeatureSize);
+    eig->getEigenvalues ( C, eigenvalue, eigenvectors, srcFeatureSize );
   }
   else
   {
-    eig->getEigenvalues(C, eigenvalue, eigenvectors, mindimension);
+    eig->getEigenvalues ( C, eigenvalue, eigenvectors, mindimension );
   }
 
 #ifdef DEBUG
-	fprintf(stderr, "Eigenvalue Decomposition ready \n");
-	cerr << eigenvectors << endl;
-	cerr << eigenvalue << endl;
+  fprintf ( stderr, "Eigenvalue Decomposition ready \n" );
+  cerr << eigenvectors << endl;
+  cerr << eigenvalue << endl;
 
-	//sort values
-	fprintf(stderr, "Eigenvector-Rows:%i Eigenvector-Cols:%i\n", (int)eigenvectors.rows(), (int)eigenvectors.cols());
+  //sort values
+  fprintf ( stderr, "Eigenvector-Rows:%i Eigenvector-Cols:%i\n", ( int ) eigenvectors.rows(), ( int ) eigenvectors.cols() );
 #endif
 
-	multimap<double, NICE::Vector> map;
-	double sumeigen = 0.0;
-
-	NICE::Vector ratio(eigenvectors.cols());
-	for (uint i = 0; i < eigenvectors.cols(); i++)//every eigenvector
-	{
-		NICE::Vector eigenvector(srcFeatureSize);
-		for (uint k = 0; k < srcFeatureSize; k++)
-		{
-			eigenvector[k] = eigenvectors(k, i);
-		}
-		map.insert(pair<double, NICE::Vector> (eigenvalue[i], eigenvector));
-		sumeigen += eigenvalue[i];
-	}
-
-	//compute basis size
-
-
-	if (adaptive)
-	{ //compute target dimension
-		uint dimensioncount = 0;
-		double addedratio = 0.0;
-		multimap<double, NICE::Vector>::reverse_iterator it = map.rbegin();
-		while (addedratio <= targetRatio && it != map.rend())
-		{
-			//calc ratio
-			ratio[dimensioncount] = (*it).first / sumeigen;
-			addedratio += ratio[dimensioncount];
-			dimensioncount++;
-			it++;
-		}
-		this->targetDimension = dimensioncount;
-	}
-
-	mindimension = std::min(this->targetDimension, srcFeatureSize);
-	this->targetDimension = mindimension;
-	basis = NICE::Matrix(srcFeatureSize, mindimension);
-	//get sorted values
-	uint count = 0;
-	multimap<double, NICE::Vector>::reverse_iterator it = map.rbegin();
-	while (count < this->targetDimension && it != map.rend())
-	{
-		NICE::Vector eigenvector = (*it).second;
-		//put eigenvector into column
-		for (uint k = 0; k < srcFeatureSize; k++)
-		{
-			basis(k, count) = eigenvector[k];
-		}
-		//calc ratio
-		ratio[count] = (*it).first / sumeigen;
-
-		count++;
-		it++;
-	}
-	//normalization matrix / modify variance to 1 for all eigenvectors
-	normalization = NICE::Matrix(mindimension, mindimension, 0);
-	for (uint k = 0; k < mindimension; k++)
-	{
-		normalization(k, k) = 1.0 / sqrt(eigenvalue[k]);
-	}
+  multimap<double, NICE::Vector> map;
+  double sumeigen = 0.0;
+
+  NICE::Vector ratio ( eigenvectors.cols() );
+  for ( uint i = 0; i < eigenvectors.cols(); i++ ) //every eigenvector
+  {
+    NICE::Vector eigenvector ( srcFeatureSize );
+    for ( uint k = 0; k < srcFeatureSize; k++ )
+    {
+      eigenvector[k] = eigenvectors ( k, i );
+    }
+    map.insert ( pair<double, NICE::Vector> ( eigenvalue[i], eigenvector ) );
+    sumeigen += eigenvalue[i];
+  }
+
+  //compute basis size
+
+
+  if ( adaptive )
+  { //compute target dimension
+    uint dimensioncount = 0;
+    double addedratio = 0.0;
+    multimap<double, NICE::Vector>::reverse_iterator it = map.rbegin();
+    while ( addedratio <= targetRatio && it != map.rend() )
+    {
+      //calc ratio
+      ratio[dimensioncount] = ( *it ).first / sumeigen;
+      addedratio += ratio[dimensioncount];
+      dimensioncount++;
+      it++;
+    }
+    this->targetDimension = dimensioncount;
+  }
+
+  mindimension = std::min ( this->targetDimension, srcFeatureSize );
+  this->targetDimension = mindimension;
+  basis = NICE::Matrix ( srcFeatureSize, mindimension );
+  //get sorted values
+  uint count = 0;
+  multimap<double, NICE::Vector>::reverse_iterator it = map.rbegin();
+  while ( count < this->targetDimension && it != map.rend() )
+  {
+    NICE::Vector eigenvector = ( *it ).second;
+    //put eigenvector into column
+    for ( uint k = 0; k < srcFeatureSize; k++ )
+    {
+      basis ( k, count ) = eigenvector[k];
+    }
+    //calc ratio
+    ratio[count] = ( *it ).first / sumeigen;
+
+    count++;
+    it++;
+  }
+  //normalization matrix / modify variance to 1 for all eigenvectors
+  normalization = NICE::Matrix ( mindimension, mindimension, 0 );
+  for ( uint k = 0; k < mindimension; k++ )
+  {
+    normalization ( k, k ) = 1.0 / sqrt ( eigenvalue[k] );
+  }
 
 #ifdef DEBUG
-	cout << "Eigenvalue-absolute:" << eigenvalue << endl;
-	cout << "Eigenvalue-ratio:" << ratio << endl;
+  cout << "Eigenvalue-absolute:" << eigenvalue << endl;
+  cout << "Eigenvalue-ratio:" << ratio << endl;
 #endif
 
 }
 
-NICE::Vector PCA::getFeatureVector(const NICE::Vector &data,
-		const bool normalize)
+NICE::Vector PCA::getFeatureVector ( const NICE::Vector &data,
+                                     const bool normalize )
 {
-	//free data of mean
-	if (normalize)
-	{
-
-		NICE::Vector meanfree(data);
-		meanfree -= mean;
-		//Y=W^t * B^T
-		if(normbasis.rows() == 0)
-			normbasis.multiply(normalization, basis, false, true);
-		NICE::Vector tmp;
-		tmp.multiply(normbasis, meanfree);
-		return tmp;
-	}
-	else
-	{
-		NICE::Vector meanfree(data);
-		meanfree -= mean;
-		//Y=W^t * B^T
-		NICE::Vector tmp;
-		tmp.multiply(basis, meanfree, true);
-		return tmp;
-	}
+  //free data of mean
+  if ( normalize )
+  {
+
+    NICE::Vector meanfree ( data );
+    meanfree -= mean;
+    //Y=W^t * B^T
+    if ( normbasis.rows() == 0 )
+      normbasis.multiply ( normalization, basis, false, true );
+    NICE::Vector tmp;
+    tmp.multiply ( normbasis, meanfree );
+    return tmp;
+  }
+  else
+  {
+    NICE::Vector meanfree ( data );
+    meanfree -= mean;
+    //Y=W^t * B^T
+    NICE::Vector tmp;
+    tmp.multiply ( basis, meanfree, true );
+    return tmp;
+  }
 }
 
 NICE::Vector PCA::getMean()
 {
-	return mean;
+  return mean;
 }
 
 NICE::Matrix PCA::getBasis()
 {
-	return basis;
+  return basis;
 }
 
 int PCA::getTargetDim()
 {
-	return targetDimension;
+  return targetDimension;
 }

+ 56 - 58
math/ftransform/PCA.h

@@ -1,4 +1,4 @@
-/** 
+/**
  * @file PCA.h
  * @brief extract fourier domain value
  * @author Michael Koch
@@ -21,63 +21,61 @@ namespace OBJREC {
 class PCA: public FTransform
 {
 
-     protected:
-          NICE::Vector mean;
-
-          NICE::Matrix basis;
-		      NICE::Matrix normbasis;
-		  
-          NICE::Matrix normalization;
-          uint targetDimension; 
-          uint maxiteration;
-          double mindelta; 
-
-          void calculateMean ( const NICE::Matrix &features, NICE::Vector & mean );
- 
-     public:
-       
-          PCA (uint dim,uint maxiteration=100,double mindelta=1e-4);
-          PCA (void);
-
-          NICE::Matrix getBasis();
-     
-          NICE::Vector getMean();       
-          void restore (std::istream & is, int format = 0);
-          void store (std::ostream & os, int format = 0) const;
-          void clear ();
-          
-          /**
-           * get Basis Vectors of PCA
-           * @param features Input Features
-           * @param dimension Dimension size / number of principal components 
-          * @return Basis Vectors 
-          */
-          void calculateBasis(const NICE::Matrix &features,const uint targetDimension,const uint mode=0);
-          void calculateBasis(const NICE::Matrix &features,const uint targetDimension,const bool adaptive,const double targetRatio=1.0);
-		  
-		  /**
-		   * returns the dimension of the transformed features
-		   * @return feature dim
-		   */
-		  int getTargetDim();
-          
-          /**
-           * get Features in PCA Space
-           * @param data input data
-           * @param normalize normalisation switch
-           * @return Features as Vector
-           */
-
-          NICE::Vector getFeatureVector(const NICE::Vector &data,const bool normalize=true);
-          
-       
-          
-          ~PCA();
-
-   private:
- 
-          void init (uint dim=10,uint maxiteration=100,double mindelta=1e-4);
-        
+  protected:
+    NICE::Vector mean;
+
+    NICE::Matrix basis;
+    NICE::Matrix normbasis;
+
+    NICE::Matrix normalization;
+    uint targetDimension;
+    uint maxiteration;
+    double mindelta;
+
+    void calculateMean ( const NICE::Matrix &features, NICE::Vector & mean );
+
+  public:
+
+    PCA ( uint dim, uint maxiteration = 100, double mindelta = 1e-4 );
+    PCA ( void );
+
+    NICE::Matrix getBasis();
+
+    NICE::Vector getMean();
+    void restore ( std::istream & is, int format = 0 );
+    void store ( std::ostream & os, int format = 0 ) const;
+    void clear ();
+
+    /**
+     * get Basis Vectors of PCA
+     * @param features Input Features
+     * @param dimension Dimension size / number of principal components
+    * @return Basis Vectors
+    */
+    void calculateBasis ( const NICE::Matrix &features, const uint targetDimension, const uint mode = 0 );
+    void calculateBasis ( const NICE::Matrix &features, const uint targetDimension, const bool adaptive, const double targetRatio = 1.0 );
+
+    /**
+     * returns the dimension of the transformed features
+     * @return feature dim
+     */
+    int getTargetDim();
+
+    /**
+     * get Features in PCA Space
+     * @param data input data
+     * @param normalize normalisation switch
+     * @return Features as Vector
+     */
+
+    NICE::Vector getFeatureVector ( const NICE::Vector &data, const bool normalize = true );
+
+    ~PCA();
+
+  private:
+
+    void init ( uint dim = 10, uint maxiteration = 100, double mindelta = 1e-4 );
+
 };