Pārlūkot izejas kodu

SparseVectorT changes

Bjoern Froehlich 13 gadi atpakaļ
vecāks
revīzija
9fe82f90bc

+ 1 - 1
cbaselib/CachedExample.h

@@ -11,7 +11,7 @@
 #include <assert.h>
 #include <map>
 
-#include "core/vector/SparseVector.h"
+#include "core/vector/SparseVectorT.h"
 #include "core/image/MultiChannelImageT.h"
 #include "core/basics/FileMgt.h"
 

+ 1 - 1
cbaselib/ClassificationResult.h

@@ -14,7 +14,7 @@
 
 #include <string>
 #include <map>
-#include "core/vector/SparseVector.h"
+#include "core/vector/SparseVectorT.h"
 #include "vislearning/math/mathbase/FullVector.h"
   
 

+ 1 - 1
features/fpfeatures/SparseVectorFeature.h

@@ -15,7 +15,7 @@
  
 #include "core/basics/Config.h"
 #include "vislearning/cbaselib/Feature.h"
-#include "core/vector/SparseVector.h"
+#include "core/vector/SparseVectorT.h"
 
 
 namespace OBJREC {

+ 55 - 39
features/simplefeatures/Codebook.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file Codebook.h
 * @brief feature codebook
 * @author Erik Rodner
@@ -16,7 +16,7 @@
 #include <string>
 
 #include "core/basics/Persistent.h"
-#include "core/vector/SparseVector.h"
+#include "core/vector/SparseVectorT.h"
 
 
 namespace OBJREC {
@@ -24,43 +24,59 @@ namespace OBJREC {
 /** feature codebook */
 class Codebook : public NICE::Persistent
 {
-    protected:
-	NICE::Vector thresholds;
-	NICE::Vector informativeMeasure;
-	NICE::VectorT<int> classnos;
-
-    public:
-	
-	/** simple destructor */
-	virtual ~Codebook() {};
-    
-	virtual void vote ( const NICE::Vector & feature, int & codebookEntry, 
-			      double & weight, double & distance ) const = 0;
-
-	virtual void vote ( const NICE::Vector & feature, NICE::Vector & histogram, int & codebookEntry, 
-			      double & weight, double & distance ) const;
-
-	virtual void vote ( const NICE::Vector & feature, NICE::SparseVector & votes ) const;
-    	
-	virtual bool allowsMultipleVoting () { return false; };	
-	virtual void add ( const Codebook *codebook ) = 0;
-	virtual void copy ( const Codebook *codebook );
-	virtual Codebook *clone () const = 0;
-
-	size_t getCodebookSize() const { return informativeMeasure.size(); };
-	void reinit ( int numCodebookEntries );
-
-	const NICE::Vector & getThresholds () const { return thresholds; };
-	const NICE::Vector & getInformativeMeasure () const { return informativeMeasure; };
-	const NICE::VectorT<int> & getClassNos () const { return classnos; };
-	
-	void setThresholds ( const NICE::Vector & _thresholds ) { thresholds = _thresholds; };
-	void setInformativeMeasure ( const NICE::Vector & _informativeMeasure ) { informativeMeasure = _informativeMeasure; };
-	void setClassNos ( const NICE::VectorT<int> & _classnos ) { classnos = _classnos; };
-
-	virtual void clear ();
-	virtual void restore ( std::istream & is, int format );
-	virtual void store ( std::ostream & os, int format ) const;
+protected:
+    NICE::Vector thresholds;
+    NICE::Vector informativeMeasure;
+    NICE::VectorT<int> classnos;
+
+public:
+
+    /** simple destructor */
+    virtual ~Codebook() {};
+
+    virtual void vote ( const NICE::Vector & feature, int & codebookEntry,
+                        double & weight, double & distance ) const = 0;
+
+    virtual void vote ( const NICE::Vector & feature, NICE::Vector & histogram, int & codebookEntry,
+                        double & weight, double & distance ) const;
+
+    virtual void vote ( const NICE::Vector & feature, NICE::SparseVector & votes ) const;
+
+    virtual bool allowsMultipleVoting () {
+        return false;
+    };
+    virtual void add ( const Codebook *codebook ) = 0;
+    virtual void copy ( const Codebook *codebook );
+    virtual Codebook *clone () const = 0;
+
+    size_t getCodebookSize() const {
+        return informativeMeasure.size();
+    };
+    void reinit ( int numCodebookEntries );
+
+    const NICE::Vector & getThresholds () const {
+        return thresholds;
+    };
+    const NICE::Vector & getInformativeMeasure () const {
+        return informativeMeasure;
+    };
+    const NICE::VectorT<int> & getClassNos () const {
+        return classnos;
+    };
+
+    void setThresholds ( const NICE::Vector & _thresholds ) {
+        thresholds = _thresholds;
+    };
+    void setInformativeMeasure ( const NICE::Vector & _informativeMeasure ) {
+        informativeMeasure = _informativeMeasure;
+    };
+    void setClassNos ( const NICE::VectorT<int> & _classnos ) {
+        classnos = _classnos;
+    };
+
+    virtual void clear ();
+    virtual void restore ( std::istream & is, int format );
+    virtual void store ( std::ostream & os, int format ) const;
 };
 
 

+ 53 - 53
math/mathbase/Featuretype.cpp

@@ -6,85 +6,85 @@ using namespace OBJREC;
 using namespace NICE;
 using namespace std;
 
-FeatureType::FeatureType(const FeatureType &_ft)
+FeatureType::FeatureType ( const FeatureType &_ft )
 {
-	sv = _ft.sv;
-	v = _ft.v;
-	ft = _ft.ft;
+  sv = _ft.sv;
+  v = _ft.v;
+  ft = _ft.ft;
 }
 
-FeatureType::FeatureType(int f, int dim)
+FeatureType::FeatureType ( int f, int dim )
 {
-	ft = f;
-	setDim(dim);
+  ft = f;
+  setDim ( dim );
 }
 
-FeatureType::FeatureType(SparseVector &tsv) : sv(tsv)
+FeatureType::FeatureType ( SparseVector &tsv ) : sv ( tsv )
 {
-	sv = tsv;
-	ft = SPARSEVECTORFEATURE;
-	v.clear();
+  sv = tsv;
+  ft = SPARSEVECTORFEATURE;
+  v.clear();
 }
 
-FeatureType::FeatureType(Vector &tv) //: v(tv)
+FeatureType::FeatureType ( Vector &tv ) //: v(tv)
 {
-	v.resize(tv.size());
-	for(int i = 0; i < v.size(); i++)
-	{
-		v[i] = tv[i];
-	}
-	ft = VECTORFEATURE;
-	sv.clear();
+  v.resize ( tv.size() );
+  for ( int i = 0; i < v.size(); i++ )
+  {
+    v[i] = tv[i];
+  }
+  ft = VECTORFEATURE;
+  sv.clear();
 }
-					
-void FeatureType::setDim(int dim)
+
+void FeatureType::setDim ( int dim )
 {
-	if(ft == SPARSEVECTORFEATURE)
-	{
-		sv.setDim(dim);
-	}
-	else
-	{
-		v.resize(dim);
-	}
+  if ( ft == SPARSEVECTORFEATURE )
+  {
+    sv.setDim ( dim );
+  }
+  else
+  {
+    v.resize ( dim );
+  }
 }
-					
-double FeatureType::get(int pos) const
+
+double FeatureType::get ( int pos ) const
 {
-	assert(pos < getDim());
-	if(ft == SPARSEVECTORFEATURE)
-	{
-		return sv.get(pos);
-	}
-	else
-	{
-		return v[pos];
-	}
+  assert ( pos < getDim() );
+  if ( ft == SPARSEVECTORFEATURE )
+  {
+    return sv.get ( pos );
+  }
+  else
+  {
+    return v[pos];
+  }
 }
-					
+
 int FeatureType::getType()
 {
-	return ft;
+  return ft;
 }
 
 int FeatureType::getDim() const
 {
-	if(ft == SPARSEVECTORFEATURE)
-	{
-		return sv.getDim();
-	}
-	else
-	{
-		return (int)v.size();
-	}
+  if ( ft == SPARSEVECTORFEATURE )
+  {
+    return sv.getDim();
+  }
+  else
+  {
+    return ( int ) v.size();
+  }
 }
-		
+
 const NICE::Vector& FeatureType::getVec() const
 {
-	return v;
+  return v;
 }
 
 const SparseVector& FeatureType::getSVec() const
 {
-	return sv;
+  return sv;
 }

+ 73 - 73
math/mathbase/Featuretype.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file FeatureType.h
 * @brief dynamic selection between SparseVector and Vector
 * @author Björn Fröhlich
@@ -8,84 +8,84 @@
 #ifndef FeatureTypeINCLUDE
 #define FeatureTypeINCLUDE
 
- 
-#include "core/vector/SparseVector.h"
+
+#include "core/vector/SparseVectorT.h"
 
 #include "core/basics/Persistent.h"
 
 
 namespace OBJREC {
 
-	//! enumeration for feature types
-	enum Featuretype
-	{
-		VECTORFEATURE,
-		SPARSEVECTORFEATURE
-	};
-
-	//! a class to differ between Vector und Sparsevector features
-	class FeatureType
-	{
-		protected:
-			//! Sparse or Vectorfeature?
-			int ft;
-			
-			//! save to sv if Sparsefeatures
-			NICE::SparseVector sv;
-			
-			//! save to v if vectorfeature
-			NICE::Vector v;
-		public:
-			
-			/**
-			 * constructor
-			 * @param f type of the faeture
-			 * @param dim dimension of the new feature
-			 */
-			FeatureType(int f, int dim);
-			
-			/**
-			 * constructor setting SparseFeature
-			 * @param tsv input SparseFeature
-			 */
-			FeatureType(NICE::SparseVector &tsv);
-			
-			/**
-			 * constructor setting VectorFeature
-			 * @param tv input VectorFeature
-			 */
-			FeatureType(NICE::Vector &tv);
-			
-			/**
-			 * copy constructor
-			 * @param _ft 
-			 */
-			FeatureType(const FeatureType &_ft);
-					
-			void setDim(int dim);
-			
-			/**
-			 * get the dimension of feature
-			 * @return dimension of feature
-			 */
-			int getDim() const;
-					
-			/**
-			 * returns adress of Vector
-			 * @return 
-			 */
-			const NICE::Vector& getVec() const;
-			
-			/**
-			 * returns adress of SparseVector
-			 * @return 
-			 */
-			const NICE::SparseVector& getSVec() const;
-			
-			double get(int pos) const;
-					
-			int getType();
-	};	
+//! enumeration for feature types
+enum Featuretype
+{
+    VECTORFEATURE,
+    SPARSEVECTORFEATURE
+};
+
+//! a class to differ between Vector und Sparsevector features
+class FeatureType
+{
+protected:
+    //! Sparse or Vectorfeature?
+    int ft;
+
+    //! save to sv if Sparsefeatures
+    NICE::SparseVector sv;
+
+    //! save to v if vectorfeature
+    NICE::Vector v;
+public:
+
+    /**
+     * constructor
+     * @param f type of the faeture
+     * @param dim dimension of the new feature
+     */
+    FeatureType(int f, int dim);
+
+    /**
+     * constructor setting SparseFeature
+     * @param tsv input SparseFeature
+     */
+    FeatureType(NICE::SparseVector &tsv);
+
+    /**
+     * constructor setting VectorFeature
+     * @param tv input VectorFeature
+     */
+    FeatureType(NICE::Vector &tv);
+
+    /**
+     * copy constructor
+     * @param _ft
+     */
+    FeatureType(const FeatureType &_ft);
+
+    void setDim(int dim);
+
+    /**
+     * get the dimension of feature
+     * @return dimension of feature
+     */
+    int getDim() const;
+
+    /**
+     * returns adress of Vector
+     * @return
+     */
+    const NICE::Vector& getVec() const;
+
+    /**
+     * returns adress of SparseVector
+     * @return
+     */
+    const NICE::SparseVector& getSVec() const;
+
+    double get(int pos) const;
+
+    int getType();
+};
 
 } // namespace
 

+ 257 - 257
math/mathbase/FullVector.cpp

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file FullVector.cpp
 * @brief non sparse vector
 * @author Erik Rodner
@@ -30,389 +30,389 @@ using namespace std;
 
 FullVector::FullVector ( const map<int, double> & mymap )
 {
-    length = 0;
-    for ( map<int, double>::const_iterator i = mymap.begin();
-		i != mymap.end(); i++ )
-    {
-	int k = i->first;
-	if ( k+1 > length )
-	    length = k+1;
-    }
+  length = 0;
+  for ( map<int, double>::const_iterator i = mymap.begin();
+        i != mymap.end(); i++ )
+  {
+    int k = i->first;
+    if ( k + 1 > length )
+      length = k + 1;
+  }
+
+  data = new double[length];
+  memset ( ( void * ) data, 0, sizeof ( double ) *length );
+
+  for ( map<int, double>::const_iterator i = mymap.begin();
+        i != mymap.end(); i++ )
+  {
+    int k = i->first;
+    double v = i->second;
+    data[k] = v;
+  }
 
-    data = new double[length];
-    memset ( (void *)data, 0, sizeof(double)*length );
-  
-    for ( map<int, double>::const_iterator i = mymap.begin();
-		i != mymap.end(); i++ )
-    {
-	int k = i->first;
-	double v = i->second;
-	data[k] = v;
-    }
- 
 }
 
 FullVector::FullVector ( const map<short, double> & mymap )
 {
-	length = 0;
-	for ( map<short, double>::const_iterator i = mymap.begin();
-		     i != mymap.end(); i++ )
-	{
-		int k = (int)i->first;
-		if ( k+1 > length )
-			length = k+1;
-	}
-
-	data = new double[length];
-	memset ( (void *)data, 0, sizeof(double)*length );
-  
-	for ( map<short, double>::const_iterator i = mymap.begin();
-		     i != mymap.end(); i++ )
-	{
-		int k = i->first;
-		double v = i->second;
-		data[k] = v;
-	}
- 
+  length = 0;
+  for ( map<short, double>::const_iterator i = mymap.begin();
+        i != mymap.end(); i++ )
+  {
+    int k = ( int ) i->first;
+    if ( k + 1 > length )
+      length = k + 1;
+  }
+
+  data = new double[length];
+  memset ( ( void * ) data, 0, sizeof ( double ) *length );
+
+  for ( map<short, double>::const_iterator i = mymap.begin();
+        i != mymap.end(); i++ )
+  {
+    int k = i->first;
+    double v = i->second;
+    data[k] = v;
+  }
+
 }
 
 FullVector::FullVector ( const FullVector & v )
 {
-    length = v.length;
+  length = v.length;
 
-	if ( length == 0 )
-		data = NULL;
-	else {
-		data = new double[length];
-		memset ( (void *)data, 0, sizeof(double)*length );
+  if ( length == 0 )
+    data = NULL;
+  else {
+    data = new double[length];
+    memset ( ( void * ) data, 0, sizeof ( double ) *length );
 
-		for ( int i = 0 ; i < length ; i++ )
-			data[i] = v.data[i];
-	}
+    for ( int i = 0 ; i < length ; i++ )
+      data[i] = v.data[i];
+  }
 }
 
 FullVector::FullVector ()
 {
-    length = 0;
-    data = NULL;
+  length = 0;
+  data = NULL;
 }
 
-FullVector::FullVector (int _length) 
+FullVector::FullVector ( int _length )
 {
-    length = _length;
-    if ( length > 0 )
-    {
-		data = new double[length];
-		memset ( (void *)data, 0, sizeof(double)*length );
-    } else {
-		data = NULL;
-    }
+  length = _length;
+  if ( length > 0 )
+  {
+    data = new double[length];
+    memset ( ( void * ) data, 0, sizeof ( double ) *length );
+  } else {
+    data = NULL;
+  }
 }
 
 FullVector::~FullVector ()
 {
-    if ( data != NULL )
-		delete [] data;
+  if ( data != NULL )
+    delete [] data;
 }
 
-void FullVector::set ( double val ) 
+void FullVector::set ( double val )
 {
-    for ( int i = 0 ; i < length ; i++  )
-		data[i] = val;
+  for ( int i = 0 ; i < length ; i++ )
+    data[i] = val;
 }
 
 void FullVector::reinit ( int _length )
 {
-    if ( data != NULL ) {
-		delete [] data;
-    }
-    length = _length;
-    data = new double [ length ];
-    memset ( (void *)data, 0, sizeof(double)*length );
+  if ( data != NULL ) {
+    delete [] data;
+  }
+  length = _length;
+  data = new double [ length ];
+  memset ( ( void * ) data, 0, sizeof ( double ) *length );
 }
 
 void FullVector::add ( const FullVector & v )
 {
-    add ( v, 1.0 );
+  add ( v, 1.0 );
 }
 
-double & FullVector::operator[] (int i)
+double & FullVector::operator[] ( int i )
 {
-	assert ( i < length );
-    	return data[i];
+  assert ( i < length );
+  return data[i];
 }
 
-const double & FullVector::operator[] (int i) const
+const double & FullVector::operator[] ( int i ) const
 {
-    assert ( i < length );
-    return data[i];
+  assert ( i < length );
+  return data[i];
 }
 
 void FullVector::add ( const FullVector & v, double lambda )
 {
-    assert ( v.length >= length );
-    for ( int i = 0 ; i < v.length ; i++  )
-	data[i] += v.data[i] * lambda;
+  assert ( v.length >= length );
+  for ( int i = 0 ; i < v.length ; i++ )
+    data[i] += v.data[i] * lambda;
 }
 
 void FullVector::add ( double beta )
 {
-    for ( int i = 0 ; i < length; i++ )
-		data[i] += beta;
+  for ( int i = 0 ; i < length; i++ )
+    data[i] += beta;
 }
 
 void FullVector::divide ( const FullVector & v )
 {
-    assert ( v.length >= length );
-    for ( int i = 0 ; i < length ; i++ )
-    {
-		if ( fabs(data[i]) < 10e-11 ) continue;
-
-		double value = v.data[i];
-		if ( fabs(value) < 10e-11 ) {
-			fprintf (stderr, "FullVector::divide: Division by Zero !\n");
-			exit(-1);
-		} else {
-			data[i] /= value;
-		}
+  assert ( v.length >= length );
+  for ( int i = 0 ; i < length ; i++ )
+  {
+    if ( fabs ( data[i] ) < 10e-11 ) continue;
+
+    double value = v.data[i];
+    if ( fabs ( value ) < 10e-11 ) {
+      fprintf ( stderr, "FullVector::divide: Division by Zero !\n" );
+      exit ( -1 );
+    } else {
+      data[i] /= value;
     }
+  }
 }
 
 void FullVector::multiply ( const FullVector & v )
 {
-    assert ( v.length >= length );
-    for ( int i = 0 ; i < length ; i++ )
-    {
-		data[i] *= v.data[i];
-    }
+  assert ( v.length >= length );
+  for ( int i = 0 ; i < length ; i++ )
+  {
+    data[i] *= v.data[i];
+  }
 }
 
 void FullVector::multiply ( double val )
 {
-    for ( int i = 0 ; i < length ; i++ )
-		data[i] *= val;
+  for ( int i = 0 ; i < length ; i++ )
+    data[i] *= val;
 }
 
-void FullVector::restore (istream & is, int format)
+void FullVector::restore ( istream & is, int format )
 {
-	std::string tag;
-	is >> tag;
-	if ( tag != "SVECTOR" ) {
-		fprintf (stderr, "FullVector: format error !\n");
-	}
-    
-	const int bufsize = 1024*1024;
-	char *buf = new char[bufsize];
-	std::string buf_s;
-
-	vector<string> elements;
-	vector<string> pair;
-	
-	elements.clear();
-	
-	is.get ( buf, bufsize );
-	buf_s = buf;
-
-	if ( buf_s.size() <= 0 ) 
-		return;
-
-	StringTools::split ( buf_s, ' ', elements );
-
-	if ( elements.size() <= 1 )
-		return;
-
-	reinit(elements.size()-1);
-
-	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++ )
-	{
-		pair.clear();
-		StringTools::split ( *i, ':', pair );
-		if ( pair.size() == 2 ) 
-		{
-			double val = atof ( pair[1].c_str() );
-			(*this)[l] = val;
-		}
-	}
-
-    delete [] buf;
-}
+  std::string tag;
+  is >> tag;
+  if ( tag != "SVECTOR" ) {
+    fprintf ( stderr, "FullVector: format error !\n" );
+  }
 
-void FullVector::store (ostream & os, int format) const
-{
-    os << "SVECTOR ";
-    for ( int i = 0 ; i < length ; i++ )
+  const int bufsize = 1024 * 1024;
+  char *buf = new char[bufsize];
+  std::string buf_s;
+
+  vector<string> elements;
+  vector<string> pair;
+
+  elements.clear();
+
+  is.get ( buf, bufsize );
+  buf_s = buf;
+
+  if ( buf_s.size() <= 0 )
+    return;
+
+  StringTools::split ( buf_s, ' ', elements );
+
+  if ( elements.size() <= 1 )
+    return;
+
+  reinit ( elements.size() - 1 );
+
+  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++ )
+  {
+    pair.clear();
+    StringTools::split ( *i, ':', pair );
+    if ( pair.size() == 2 )
     {
-		os << i << ":" << data[i] << " ";
+      double val = atof ( pair[1].c_str() );
+      ( *this ) [l] = val;
     }
-    os << "END" << endl;
+  }
+
+  delete [] buf;
+}
+
+void FullVector::store ( ostream & os, int format ) const
+{
+  os << "SVECTOR ";
+  for ( int i = 0 ; i < length ; i++ )
+  {
+    os << i << ":" << data[i] << " ";
+  }
+  os << "END" << endl;
 }
 
 void FullVector::clear ()
 {
-    if ( length != 0 ) 
-		memset ( data, 0x0, sizeof(double)*length );
+  if ( length != 0 )
+    memset ( data, 0x0, sizeof ( double ) *length );
 }
 
 double FullVector::sum () const
 {
-    double sumv = 0.0;
-    for ( int i = 0 ; i < length ; i++ )
-		sumv += data[i];
+  double sumv = 0.0;
+  for ( int i = 0 ; i < length ; i++ )
+    sumv += data[i];
 
-    return sumv;
+  return sumv;
 }
 
 void FullVector::normalize ()
 {
-    double sum = 0;
-    for ( int i = 0 ; i < length ; i++ )
-		sum += data[i];
+  double sum = 0;
+  for ( int i = 0 ; i < length ; i++ )
+    sum += data[i];
 
 #ifdef FULLVECTOR_THROW_NORMALIZATION_EXCEPTION
-    assert ( fabs(sum) > 1e-10 );
+  assert ( fabs ( sum ) > 1e-10 );
 #endif
-    if ( fabs(sum) < 1e-10 ) {
-		//fprintf (stderr, "WARNING: normalization failed !\n");
-		for ( int i = 0 ; i < length ; i++ )
-			data[i] = 0.0;
+  if ( fabs ( sum ) < 1e-10 ) {
+    //fprintf (stderr, "WARNING: normalization failed !\n");
+    for ( int i = 0 ; i < length ; i++ )
+      data[i] = 0.0;
 
-    } else {
-		for ( int i = 0 ; i < length ; i++ )
-			data[i] /= sum;
-    }
+  } else {
+    for ( int i = 0 ; i < length ; i++ )
+      data[i] /= sum;
+  }
 }
 
 void FullVector::addMap ( const map<int, int> & v, double lambda )
 {
-    for ( map<int, int>::const_iterator v_it = v.begin();
-				       v_it != v.end();
-				       v_it++ )
-    {
-		int i = v_it->first;
-		assert ( i < length );
-		data[i] += v_it->second * lambda;
-    }
+  for ( map<int, int>::const_iterator v_it = v.begin();
+        v_it != v.end();
+        v_it++ )
+  {
+    int i = v_it->first;
+    assert ( i < length );
+    data[i] += v_it->second * lambda;
+  }
 }
 
 void FullVector::addMap ( const map<int, double> & v, double lambda )
 {
-    for ( map<int, double>::const_iterator v_it = v.begin();
-				       v_it != v.end();
-				       v_it++ )
-    {
-		int i = v_it->first;
-		assert ( i < length );
-		data[i] += v_it->second * lambda;
-    }
+  for ( map<int, double>::const_iterator v_it = v.begin();
+        v_it != v.end();
+        v_it++ )
+  {
+    int i = v_it->first;
+    assert ( i < length );
+    data[i] += v_it->second * lambda;
+  }
 }
 
 int FullVector::maxElement () const
 {
-    int maxindex = 0;
-    double max = - numeric_limits<double>::max();
-    for ( int i = 0 ; i < length ; i++ )
+  int maxindex = 0;
+  double max = - numeric_limits<double>::max();
+  for ( int i = 0 ; i < length ; i++ )
+  {
+    if ( data[i] > max )
     {
-		if ( data[i] > max )
-		{
-			maxindex = i;
-			max = data[i];
-		}
+      maxindex = i;
+      max = data[i];
     }
-    return maxindex;
+  }
+  return maxindex;
 }
 
 int FullVector::maxElementExclusive ( int key ) const
 {
-    int maxindex = (key == 0) ? 1 : 0;
-    double max = - numeric_limits<double>::max();
-    for ( int i = 0 ; i < length ; i++ )
+  int maxindex = ( key == 0 ) ? 1 : 0;
+  double max = - numeric_limits<double>::max();
+  for ( int i = 0 ; i < length ; i++ )
+  {
+    double val = data[i];
+    if ( ( i != key ) && ( val > max ) )
     {
-		double val = data[i];
-		if ( (i != key) && (val > max) )
-		{
-			maxindex = i;
-			max = val;
-		}
+      maxindex = i;
+      max = val;
     }
-    return maxindex;
+  }
+  return maxindex;
 }
 
 double FullVector::entropy () const
 {
-    double entropy = 0.0;
-    double sum = 0.0;
-    for ( int i = 0 ; i < length ; i++ )
-    {
-		double val = data[i];
-		if ( val <= 0.0 ) continue;
-			entropy -= val*log(val);
-		sum += val;
-    }
-    entropy /= sum;
-    entropy += log(sum);
-    return entropy;
+  double entropy = 0.0;
+  double sum = 0.0;
+  for ( int i = 0 ; i < length ; i++ )
+  {
+    double val = data[i];
+    if ( val <= 0.0 ) continue;
+    entropy -= val * log ( val );
+    sum += val;
+  }
+  entropy /= sum;
+  entropy += log ( sum );
+  return entropy;
 }
-	
+
 void FullVector::getSortedIndices ( vector<int> & indizes ) const
 {
-    vector< pair<double, int> > tmp;
-    for ( int i = 0 ; i < length ; i++ )
-	if ( fabs(data[i]) > 10e-11 )
-	    tmp.push_back ( pair<double, int> (  data[i], i  ) );
+  vector< pair<double, int> > tmp;
+  for ( int i = 0 ; i < length ; i++ )
+    if ( fabs ( data[i] ) > 10e-11 )
+      tmp.push_back ( pair<double, int> ( data[i], i ) );
 
-    sort ( tmp.begin(), tmp.end() );
+  sort ( tmp.begin(), tmp.end() );
 
-    for ( vector<pair<double,int> >::const_iterator j = tmp.begin();
-		j != tmp.end(); j++ )
-	indizes.push_back ( j->second );
+  for ( vector<pair<double, int> >::const_iterator j = tmp.begin();
+        j != tmp.end(); j++ )
+    indizes.push_back ( j->second );
 }
-	
+
 double FullVector::max () const
 {
-    double max = - numeric_limits<double>::max();
-    for ( int i = 0 ; i < length ; i++ )
-    {
-		if ( data[i] > max )
-			max = data[i];
-    }
-    return max;
+  double max = - numeric_limits<double>::max();
+  for ( int i = 0 ; i < length ; i++ )
+  {
+    if ( data[i] > max )
+      max = data[i];
+  }
+  return max;
 }
 
 double FullVector::min () const
 {
-    double min = numeric_limits<double>::max();
-    for ( int i = 0 ; i < length ; i++ )
-    {
-		if ( data[i] < min )
-			min = data[i];
-    }
-    return min;
+  double min = numeric_limits<double>::max();
+  for ( int i = 0 ; i < length ; i++ )
+  {
+    if ( data[i] < min )
+      min = data[i];
+  }
+  return min;
 }
 
 double FullVector::get ( size_t i ) const
 {
-    assert ( (int)i < length );
-    return data[i];
+  assert ( ( int ) i < length );
+  return data[i];
 }
-	
+
 void FullVector::operator= ( const FullVector & v )
 {
-    if ( data != NULL )
-		delete [] data;
+  if ( data != NULL )
+    delete [] data;
 
-    length = v.length;
+  length = v.length;
 
-	if ( length == 0 )
-		data = NULL;
-	else {
-		data = new double[length];
-		memset ( (void *)data, 0, sizeof(double)*length );
+  if ( length == 0 )
+    data = NULL;
+  else {
+    data = new double[length];
+    memset ( ( void * ) data, 0, sizeof ( double ) *length );
 
-		for ( int i = 0 ; i < length ; i++ )
-			data[i] = v.data[i];
-	}
+    for ( int i = 0 ; i < length ; i++ )
+      data[i] = v.data[i];
+  }
 }

+ 47 - 43
math/mathbase/FullVector.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file FullVector.h
 * @brief non sparse vector
 * @author Erik Rodner
@@ -8,7 +8,7 @@
 #ifndef FullVectorINCLUDE
 #define FullVectorINCLUDE
 
- 
+
 #include <vector>
 #include <map>
 #include <iostream>
@@ -22,62 +22,66 @@ namespace OBJREC {
 class FullVector : public NICE::Persistent
 {
 
-    protected:
+  protected:
 
-    public:
+  public:
 
-	double *data;
-	int length;
+    double *data;
+    int length;
 
-	FullVector ( const std::map<int, double> & mymap );
-	FullVector ( const std::map<short, double> & mymap );
-	/**
-	 * Creates a vector with specified size (values will be randomized initialized)
-	 * @param length 
-	 */
-	FullVector (int length);
-	FullVector ();
-	FullVector ( const FullVector & v );
-	~FullVector ();
+    FullVector ( const std::map<int, double> & mymap );
+    FullVector ( const std::map<short, double> & mymap );
+    /**
+     * Creates a vector with specified size (values will be randomized initialized)
+     * @param length
+     */
+    FullVector ( int length );
+    FullVector ();
+    FullVector ( const FullVector & v );
+    ~FullVector ();
 
-	void set ( double val ); 
+    void set ( double val );
 
-	void add ( const FullVector & v );
-	void add ( const FullVector & v, double lambda );
-	void add ( double beta );
+    void add ( const FullVector & v );
+    void add ( const FullVector & v, double lambda );
+    void add ( double beta );
 
-	void addMap ( const std::map<int, int> & v, double lambda = 1.0 );
-	void addMap ( const std::map<int, double> & v, double lambda = 1.0 );
+    void addMap ( const std::map<int, int> & v, double lambda = 1.0 );
+    void addMap ( const std::map<int, double> & v, double lambda = 1.0 );
 
-	void normalize ();
+    void normalize ();
 
-	void reinit ( int length );
+    void reinit ( int length );
 
-	void restore (std::istream & is, int format = 0);
-	void store (std::ostream & os, int format = 0) const;
-	void clear ();
+    void restore ( std::istream & is, int format = 0 );
+    void store ( std::ostream & os, int format = 0 ) const;
+    void clear ();
 
-	double entropy () const;
+    double entropy () const;
 
-	void multiply ( const FullVector & v );
-	void multiply ( double val );
-	void divide ( const FullVector & v );
-	double sum () const;
+    void multiply ( const FullVector & v );
+    void multiply ( double val );
+    void divide ( const FullVector & v );
+    double sum () const;
 
-	double max () const;
-	double min () const;
-	int maxElement () const;
-	int maxElementExclusive ( int key ) const;
-	void getSortedIndices ( std::vector<int> & indizes ) const;
+    double max () const;
+    double min () const;
+    int maxElement () const;
+    int maxElementExclusive ( int key ) const;
+    void getSortedIndices ( std::vector<int> & indizes ) const;
 
-	double get( size_t i ) const;
+    double get ( size_t i ) const;
 
-	inline int size() const { return length; };
-	inline bool empty() { return length == 0; };
+    inline int size() const {
+      return length;
+    };
+    inline bool empty() {
+      return length == 0;
+    };
 
-	double & operator[] (int i);
-	void operator= ( const FullVector & v );
-	const double & operator[] (int i) const;
+    double & operator[] ( int i );
+    void operator= ( const FullVector & v );
+    const double & operator[] ( int i ) const;
 
 };
 

+ 0 - 88
math/mathbase/progs/Makefile.inc

@@ -1,88 +0,0 @@
-# BINARY-DIRECTORY-MAKEFILE
-# conventions:
-# - there are no subdirectories, they are ignored!
-# - all ".C", ".cpp" and ".c" files in the current directory are considered
-#   independent binaries, and linked as such.
-# - the binaries depend on the library of the parent directory
-# - the binary names are created with $(BINNAME), i.e. it will be more or less
-#   the name of the .o file
-# - all binaries will be added to the default build list ALL_BINARIES
-
-# --------------------------------
-# - remember the last subdirectory
-#
-# set the variable $(SUBDIR) correctly to the current subdirectory. this
-# variable can be used throughout the current makefile.inc. The many 
-# SUBDIR_before, _add, and everything are only required so that we can recover
-# the previous content of SUBDIR before exitting the makefile.inc
-
-SUBDIR_add:=$(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
-SUBDIR_before:=$(SUBDIR)
-SUBDIR:=$(strip $(SUBDIR_add))
-SUBDIR_before_$(SUBDIR):=$(SUBDIR_before)
-
-# ------------------------
-# - include subdirectories
-#
-# note the variables $(SUBDIRS_OF_$(SUBDIR)) are required later on to recover
-# the dependencies automatically. if you handle dependencies on your own, you
-# can also dump the $(SUBDIRS_OF_$(SUBDIR)) variable, and include the
-# makefile.inc of the subdirectories on your own...
-
-#SUBDIRS_OF_$(SUBDIR):=$(patsubst %/Makefile.inc,%,$(wildcard $(SUBDIR)*/Makefile.inc))
-#include $(SUBDIRS_OF_$(SUBDIR):%=%/Makefile.inc)
-
-# ----------------------------
-# - include local dependencies
-#
-# include the libdepend.inc file, which gives additional dependencies for the
-# libraries and binaries. additionally, an automatic dependency from the library
-# of the parent directory is added (commented out in the code below).
-
--include $(SUBDIR)libdepend.inc
-
-PARENTDIR:=$(patsubst %/,%,$(dir $(patsubst %/,%,$(SUBDIR))))
-$(eval $(call PKG_DEPEND_INT,$(PARENTDIR)))
-
-# ---------------------------
-# - objects in this directory
-#
-# the use of the variable $(OBJS) is not mandatory. it is mandatory however
-# to update $(ALL_OBJS) in a way that it contains the path and name of
-# all objects. otherwise we can not include the appropriate .d files.
-
-OBJS:=$(patsubst %.cpp,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.cpp))) \
-      $(patsubst %.C,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.C))) \
-      $(shell grep -ls Q_OBJECT $(SUBDIR)*.h | sed -e's@^@/@;s@.*/@$(OBJDIR)moc_@;s@\.h$$@.o@') \
-      $(patsubst %.c,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.c)))
-ALL_OBJS += $(OBJS)
-
-# ----------------------------
-# - binaries in this directory
-#
-# output of binaries in this directory. none of the variables has to be used.
-# but everything you add to $(ALL_LIBRARIES) and $(ALL_BINARIES) will be
-# compiled with `make all`. be sure again to add the files with full path.
-
-BINARIES:=$(patsubst %.o,$(BINDIR)%,$(filter-out moc_%,$(notdir $(OBJS))))
-ALL_BINARIES+=$(BINARIES)
-
-# ---------------------
-# - binary dependencies
-#
-# there is no way of determining the binary dependencies automatically, so we
-# follow conventions. each binary depends on the corresponding .o file and
-# on the libraries specified by the INTLIBS/EXTLIBS. these dependencies can be
-# specified manually or they are automatically stored in a .bd file.
-
-$(foreach head,$(wildcard $(SUBDIR)*.h),$(eval $(shell grep -q Q_OBJECT $(head) && echo $(head) | sed -e's@^@/@;s@.*/\(.*\)\.h$$@$(BINDIR)\1:$(OBJDIR)moc_\1.o@')))
--include $(OBJS:%.o=%.bd)
-
-# -------------------
-# - subdir management
-#
-# as the last step, always add this line to correctly recover the subdirectory
-# of the makefile including this one!
-
-SUBDIR:=$(SUBDIR_before_$(SUBDIR))
-

+ 0 - 88
math/mathbase/progs/testSparseVector.cpp

@@ -1,88 +0,0 @@
-/** 
-* @file testSparseVector.cpp
-// refactor-nice.pl: check this substitution
-// old: * @brief test sparse vector implementation
-* @brief test sparse std::vector implementation
-* @author Erik Rodner
-* @date 05/07/2008
-
-*/
-#include "core/vector/SparseVector.h"
-
-#include <iostream>
-
-using namespace NICE;
-
-
-using namespace std;
-
-void rndSparseVector ( SparseVector & v, int numIndex = 1000 )
-{
-    for ( uint k = 0 ; k < (uint)numIndex ; k++ )
-    {
-	if ( drand48() < 0.5 )
-	    v.insert ( pair<int, double> ( k, drand48() ) );
-    }
-}
-
-void calcIntegralSparseMap ( SparseVector *map, int xsize, int ysize )
-{
-    int k = xsize;
-    for ( int y = 1 ; y < ysize; y++, k+=xsize )
-    {
-        fprintf (stderr, "x %d y %d s %d\n", 0, y, (int)map[k].size() );
-	map[k].add ( (map[k-xsize]) );
-    }
-
-    k = 1;
-    for ( int x = 1 ; x < xsize; x++, k++ )
-	map[k].add ( (map[k-1]) );
-
-    k = xsize + 1;
-    for ( int y = 1 ; y < ysize ; y++,k++ )
-	for ( int x = 1 ; x < xsize ; x++,k++ )
-	{
-	    fprintf (stderr, "x %d y %d s %d\n", x, y, (int)map[k].size() );
-	    map[k].add ( (map[k-1]) );
-	    map[k].add ( (map[k-xsize]) );
-	    map[k].add ( (map[k-xsize-1]), -1.0 );
-	}
-
-
-}
-
-int main (int argc, char **argv)
-{   
-    std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
-    
-    SparseVector v;
-    SparseVector w;
-    
-    srand48(time(NULL));
-    srand(time(NULL));
-    
-    rndSparseVector ( v, 10 );
-    rndSparseVector ( w, 10 );
-
-    v.store ( cerr );
-    w.store ( cerr );
-
-    v.add(w);
-
-    v.store ( cerr );
-   
-    const int xsize = 100;
-    const int ysize = 100;
-    SparseVector *map = new SparseVector[xsize*ysize];
-
-    for ( int k = 0 ; k < xsize*ysize ; k++ )
-	rndSparseVector( map[k] );
-
-    map[xsize*ysize-1].store ( cerr );
-
-    calcIntegralSparseMap ( map, xsize, ysize );
-
-    map[xsize*ysize-1].store ( cerr );
-    
-    return 0;
-}