Browse Source

SparseVectorT changes

Bjoern Froehlich 13 years ago
parent
commit
9fe82f90bc

+ 1 - 1
cbaselib/CachedExample.h

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

+ 1 - 1
cbaselib/ClassificationResult.h

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

+ 1 - 1
features/fpfeatures/SparseVectorFeature.h

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

+ 55 - 39
features/simplefeatures/Codebook.h

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file Codebook.h
 * @file Codebook.h
 * @brief feature codebook
 * @brief feature codebook
 * @author Erik Rodner
 * @author Erik Rodner
@@ -16,7 +16,7 @@
 #include <string>
 #include <string>
 
 
 #include "core/basics/Persistent.h"
 #include "core/basics/Persistent.h"
-#include "core/vector/SparseVector.h"
+#include "core/vector/SparseVectorT.h"
 
 
 
 
 namespace OBJREC {
 namespace OBJREC {
@@ -24,43 +24,59 @@ namespace OBJREC {
 /** feature codebook */
 /** feature codebook */
 class Codebook : public NICE::Persistent
 class Codebook : public NICE::Persistent
 {
 {
-    protected:
+protected:
-	NICE::Vector thresholds;
+    NICE::Vector thresholds;
-	NICE::Vector informativeMeasure;
+    NICE::Vector informativeMeasure;
-	NICE::VectorT<int> classnos;
+    NICE::VectorT<int> classnos;
-
+
-    public:
+public:
-	
+
-	/** simple destructor */
+    /** simple destructor */
-	virtual ~Codebook() {};
+    virtual ~Codebook() {};
-    
+
-	virtual void vote ( const NICE::Vector & feature, int & codebookEntry, 
+    virtual void vote ( const NICE::Vector & feature, int & codebookEntry,
-			      double & weight, double & distance ) const = 0;
+                        double & weight, double & distance ) const = 0;
-
+
-	virtual void vote ( const NICE::Vector & feature, NICE::Vector & histogram, int & codebookEntry, 
+    virtual void vote ( const NICE::Vector & feature, NICE::Vector & histogram, int & codebookEntry,
-			      double & weight, double & distance ) const;
+                        double & weight, double & distance ) const;
-
+
-	virtual void vote ( const NICE::Vector & feature, NICE::SparseVector & votes ) const;
+    virtual void vote ( const NICE::Vector & feature, NICE::SparseVector & votes ) const;
-    	
+
-	virtual bool allowsMultipleVoting () { return false; };	
+    virtual bool allowsMultipleVoting () {
-	virtual void add ( const Codebook *codebook ) = 0;
+        return false;
-	virtual void copy ( const Codebook *codebook );
+    };
-	virtual Codebook *clone () const = 0;
+    virtual void add ( const Codebook *codebook ) = 0;
-
+    virtual void copy ( const Codebook *codebook );
-	size_t getCodebookSize() const { return informativeMeasure.size(); };
+    virtual Codebook *clone () const = 0;
-	void reinit ( int numCodebookEntries );
+
-
+    size_t getCodebookSize() const {
-	const NICE::Vector & getThresholds () const { return thresholds; };
+        return informativeMeasure.size();
-	const NICE::Vector & getInformativeMeasure () const { return informativeMeasure; };
+    };
-	const NICE::VectorT<int> & getClassNos () const { return classnos; };
+    void reinit ( int numCodebookEntries );
-	
+
-	void setThresholds ( const NICE::Vector & _thresholds ) { thresholds = _thresholds; };
+    const NICE::Vector & getThresholds () const {
-	void setInformativeMeasure ( const NICE::Vector & _informativeMeasure ) { informativeMeasure = _informativeMeasure; };
+        return thresholds;
-	void setClassNos ( const NICE::VectorT<int> & _classnos ) { classnos = _classnos; };
+    };
-
+    const NICE::Vector & getInformativeMeasure () const {
-	virtual void clear ();
+        return informativeMeasure;
-	virtual void restore ( std::istream & is, int format );
+    };
-	virtual void store ( std::ostream & os, int format ) const;
+    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 NICE;
 using namespace std;
 using namespace std;
 
 
-FeatureType::FeatureType(const FeatureType &_ft)
+FeatureType::FeatureType ( const FeatureType &_ft )
 {
 {
-	sv = _ft.sv;
+  sv = _ft.sv;
-	v = _ft.v;
+  v = _ft.v;
-	ft = _ft.ft;
+  ft = _ft.ft;
 }
 }
 
 
-FeatureType::FeatureType(int f, int dim)
+FeatureType::FeatureType ( int f, int dim )
 {
 {
-	ft = f;
+  ft = f;
-	setDim(dim);
+  setDim ( dim );
 }
 }
 
 
-FeatureType::FeatureType(SparseVector &tsv) : sv(tsv)
+FeatureType::FeatureType ( SparseVector &tsv ) : sv ( tsv )
 {
 {
-	sv = tsv;
+  sv = tsv;
-	ft = SPARSEVECTORFEATURE;
+  ft = SPARSEVECTORFEATURE;
-	v.clear();
+  v.clear();
 }
 }
 
 
-FeatureType::FeatureType(Vector &tv) //: v(tv)
+FeatureType::FeatureType ( Vector &tv ) //: v(tv)
 {
 {
-	v.resize(tv.size());
+  v.resize ( tv.size() );
-	for(int i = 0; i < v.size(); i++)
+  for ( int i = 0; i < v.size(); i++ )
-	{
+  {
-		v[i] = tv[i];
+    v[i] = tv[i];
-	}
+  }
-	ft = VECTORFEATURE;
+  ft = VECTORFEATURE;
-	sv.clear();
+  sv.clear();
 }
 }
-					
+
-void FeatureType::setDim(int dim)
+void FeatureType::setDim ( int dim )
 {
 {
-	if(ft == SPARSEVECTORFEATURE)
+  if ( ft == SPARSEVECTORFEATURE )
-	{
+  {
-		sv.setDim(dim);
+    sv.setDim ( dim );
-	}
+  }
-	else
+  else
-	{
+  {
-		v.resize(dim);
+    v.resize ( dim );
-	}
+  }
 }
 }
-					
+
-double FeatureType::get(int pos) const
+double FeatureType::get ( int pos ) const
 {
 {
-	assert(pos < getDim());
+  assert ( pos < getDim() );
-	if(ft == SPARSEVECTORFEATURE)
+  if ( ft == SPARSEVECTORFEATURE )
-	{
+  {
-		return sv.get(pos);
+    return sv.get ( pos );
-	}
+  }
-	else
+  else
-	{
+  {
-		return v[pos];
+    return v[pos];
-	}
+  }
 }
 }
-					
+
 int FeatureType::getType()
 int FeatureType::getType()
 {
 {
-	return ft;
+  return ft;
 }
 }
 
 
 int FeatureType::getDim() const
 int FeatureType::getDim() const
 {
 {
-	if(ft == SPARSEVECTORFEATURE)
+  if ( ft == SPARSEVECTORFEATURE )
-	{
+  {
-		return sv.getDim();
+    return sv.getDim();
-	}
+  }
-	else
+  else
-	{
+  {
-		return (int)v.size();
+    return ( int ) v.size();
-	}
+  }
 }
 }
-		
+
 const NICE::Vector& FeatureType::getVec() const
 const NICE::Vector& FeatureType::getVec() const
 {
 {
-	return v;
+  return v;
 }
 }
 
 
 const SparseVector& FeatureType::getSVec() const
 const SparseVector& FeatureType::getSVec() const
 {
 {
-	return sv;
+  return sv;
 }
 }

+ 73 - 73
math/mathbase/Featuretype.h

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

+ 257 - 257
math/mathbase/FullVector.cpp

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

+ 47 - 43
math/mathbase/FullVector.h

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