Pārlūkot izejas kodu

matio problem solved

Bjoern Froehlich 12 gadi atpakaļ
vecāks
revīzija
3597546c18

+ 98 - 98
classifier/vclassifier/VCSimpleGaussian.cpp

@@ -14,155 +14,155 @@ using namespace std;
 
 using namespace NICE;
 
-VCSimpleGaussian::VCSimpleGaussian( const Config *conf ) 
+VCSimpleGaussian::VCSimpleGaussian( const Config *conf )
 {
 }
 
 VCSimpleGaussian::~VCSimpleGaussian()
 {
-    clear();
+  clear();
 }
 
 double VCSimpleGaussian::calcNLogDensity ( int classno, const NICE::Vector & x ) const
 {
-    std::map<int, PDF *>::const_iterator im = pdfs.find(classno);
-    if ( im == pdfs.end() ) {
-	fprintf (stderr, "VCSimpleGaussian: classno %d not trained !!\n", classno);
-	exit(-1);
-    }
-    PDF *pdf = im->second;
-    double result = pdf->getNLogDensity ( x );
+  std::map<int, PDF *>::const_iterator im = pdfs.find(classno);
+  if ( im == pdfs.end() ) {
+    fprintf (stderr, "VCSimpleGaussian: classno %d not trained !!\n", classno);
+    exit(-1);
+  }
+  PDF *pdf = im->second;
+  double result = pdf->getNLogDensity ( x );
 
-    return result;
+  return result;
 }
 
 /** classify using simple vector */
 
 ClassificationResult VCSimpleGaussian::classify ( const NICE::Vector & x ) const
 {
-     double min_nlogdensity = std::numeric_limits<double>::max();
-     int min_class = -1;
-     FullVector scores ( maxClassNo+1 );
-     
-     for ( map<int, ice::Statistics *>::const_iterator i  = statistics.begin();
-           i != statistics.end();
-           i++ )
-     {
-          double nlogdensity = calcNLogDensity ( i->first, x );
-          scores[i->first] = - nlogdensity;
-          if ( nlogdensity < min_nlogdensity )
-          {
-               min_nlogdensity = nlogdensity;
-               min_class = i->first;
-          }
-     }
-     
-     return ClassificationResult ( min_class, scores );
+  double min_nlogdensity = std::numeric_limits<double>::max();
+  int min_class = -1;
+  FullVector scores ( maxClassNo + 1 );
+
+  for ( map<int, ice::Statistics *>::const_iterator i  = statistics.begin();
+        i != statistics.end();
+        i++ )
+  {
+    double nlogdensity = calcNLogDensity ( i->first, x );
+    scores[i->first] = - nlogdensity;
+    if ( nlogdensity < min_nlogdensity )
+    {
+      min_nlogdensity = nlogdensity;
+      min_class = i->first;
+    }
+  }
+
+  return ClassificationResult ( min_class, scores );
 }
 
-void VCSimpleGaussian::getVotings ( const NICE::Vector & x, 
-    std::map<int, double> & votings ) const
+void VCSimpleGaussian::getVotings ( const NICE::Vector & x,
+                                    std::map<int, double> & votings ) const
 {
-     for ( map<int, ice::Statistics *>::const_iterator i  = statistics.begin();
-					          i != statistics.end();
-					          i++ )
-     {
-	double nlogdensity = calcNLogDensity ( i->first, x );
-	votings[ i->first ] = nlogdensity;
-     }
+  for ( map<int, ice::Statistics *>::const_iterator i  = statistics.begin();
+        i != statistics.end();
+        i++ )
+  {
+    double nlogdensity = calcNLogDensity ( i->first, x );
+    votings[ i->first ] = nlogdensity;
+  }
 }
 
 PDF *VCSimpleGaussian::getPDF(int classno) const
 {
-     std::map<int, PDF*>::const_iterator im = pdfs.find(classno);
-     if ( im == pdfs.end() ) {
-          fprintf (stderr, "VCSimpleGaussian: classno %d not trained !!\n", classno);
-          exit(-1);
-     }
-     PDF *pdf = im->second;
-     return pdf;
+  std::map<int, PDF*>::const_iterator im = pdfs.find(classno);
+  if ( im == pdfs.end() ) {
+    fprintf (stderr, "VCSimpleGaussian: classno %d not trained !!\n", classno);
+    exit(-1);
+  }
+  PDF *pdf = im->second;
+  return pdf;
 }
 
 /** classify using a simple vector */
 void VCSimpleGaussian::teach ( const LabeledSetVector & _teachSet )
 {
-    maxClassNo = _teachSet.getMaxClassno();
-    LOOP_ALL(_teachSet)
-    {
-	EACH(classno,x);
-	teach ( classno, x );
-    }
+  maxClassNo = _teachSet.getMaxClassno();
+  LOOP_ALL(_teachSet)
+  {
+    EACH(classno, x);
+    teach ( classno, x );
+  }
 }
 
 void VCSimpleGaussian::teach ( int classno, const NICE::Vector & x )
 {
-   if ( classno > maxClassNo ) maxClassNo = classno;
+  if ( classno > maxClassNo ) maxClassNo = classno;
 
-   std::map<int, ice::Statistics *>::iterator i = statistics.find(classno);
-   
-   if ( i == statistics.end() )
-   {
-       statistics[classno] = new ice::Statistics(x.size());
-       i = statistics.find(classno); // FIXME
-   }
+  std::map<int, ice::Statistics *>::iterator i = statistics.find(classno);
 
-   ice::Statistics *s = i->second;
+  if ( i == statistics.end() )
+  {
+    statistics[classno] = new ice::Statistics(x.size());
+    i = statistics.find(classno); // FIXME
+  }
 
-   Put( *s, NICE::makeIceVectorT(x) );
+  ice::Statistics *s = i->second;
+
+  Put( *s, NICE::makeIceVectorT(x) );
 }
 
 void VCSimpleGaussian::finishTeaching()
 {
-    for ( map<int, ice::Statistics *>::iterator i  = statistics.begin();
-					   i != statistics.end();
-					   i++ )
-    {
-	NICE::Matrix covariance;
-	NICE::Vector mean;
-
-	ice::Statistics *s = i->second;
-	
-	mean = NICE::makeEVector<double>(Mean(*s));
-	covariance = NICE::makeDoubleMatrix( Covariance(*s) );
-    
-	PDF *pdf = new PDFGaussian ( covariance, mean );
-	
-	pdfs[i->first] = pdf;
-    }
+  for ( map<int, ice::Statistics *>::iterator i  = statistics.begin();
+        i != statistics.end();
+        i++ )
+  {
+    NICE::Matrix covariance;
+    NICE::Vector mean;
+
+    ice::Statistics *s = i->second;
+
+    mean = NICE::makeEVector<double>(Mean(*s));
+    covariance = NICE::makeDoubleMatrix( Covariance(*s) );
+
+    PDF *pdf = new PDFGaussian ( covariance, mean );
+
+    pdfs[i->first] = pdf;
+  }
 }
 
 void VCSimpleGaussian::clear ()
 {
-    for ( map<int, ice::Statistics *>::iterator i  = statistics.begin();
-					   i != statistics.end();
-					   i++ )
-    {
-	ice::Statistics *s = i->second;
-	delete s;
-    }   
-    
-    for ( map<int, PDF *>::iterator i  = pdfs.begin();
-				    i != pdfs.end();
-				    i++ )
-    {
-	PDF *p = i->second;
-	delete p;
-    }   
-
-    pdfs.clear();
-    statistics.clear();
+  for ( map<int, ice::Statistics *>::iterator i  = statistics.begin();
+        i != statistics.end();
+        i++ )
+  {
+    ice::Statistics *s = i->second;
+    delete s;
+  }
+
+  for ( map<int, PDF *>::iterator i  = pdfs.begin();
+        i != pdfs.end();
+        i++ )
+  {
+    PDF *p = i->second;
+    delete p;
+  }
+
+  pdfs.clear();
+  statistics.clear();
 }
 
 void VCSimpleGaussian::store ( std::ostream & os, int format ) const
 {
-    fprintf (stderr, "NOT YET IMPLEMENTED\n");
-    exit(-1);
+  fprintf (stderr, "NOT YET IMPLEMENTED\n");
+  exit(-1);
 }
 
 void VCSimpleGaussian::restore ( std::istream & is, int format )
 {
-    fprintf (stderr, "NOT YET IMPLEMENTED\n");
-    exit(-1);
+  fprintf (stderr, "NOT YET IMPLEMENTED\n");
+  exit(-1);
 }
 
 #endif

+ 39 - 39
math/pdf/PDFGaussian.cpp

@@ -24,27 +24,27 @@ using namespace NICE;
 
 PDFGaussian::PDFGaussian(int dimension) : mean(dimension)
 {
-	constant = dimension * log(2 * M_PI);
-	covariance.resize ( dimension, dimension );
-	covariance.setIdentity();
-	mean.resize ( dimension );
-	mean.set(0.0);
-	covCholesky = covariance;
-	ldet = 0.0;
+  constant = dimension * log(2 * M_PI);
+  covariance.resize ( dimension, dimension );
+  covariance.setIdentity();
+  mean.resize ( dimension );
+  mean.set(0.0);
+  covCholesky = covariance;
+  ldet = 0.0;
 }
 
 PDFGaussian::PDFGaussian(const NICE::Matrix & _covariance, const NICE::Vector & _mean)
 {
-	covariance = _covariance;
-	
-	CholeskyRobustAuto cr ( true, regEPS, - std::numeric_limits<double>::max(), true );
-	ldet = cr.robustChol ( covariance, covCholesky );
-
-	mean = _mean;
-	constant = mean.size() * log(2 * M_PI);
-	constant = 0.0;
-	
-	ldet=0.0;
+  covariance = _covariance;
+
+  CholeskyRobustAuto cr ( true, regEPS, - std::numeric_limits<double>::max(), true );
+  ldet = cr.robustChol ( covariance, covCholesky );
+
+  mean = _mean;
+  constant = mean.size() * log(2 * M_PI);
+  constant = 0.0;
+
+  ldet = 0.0;
 }
 
 PDFGaussian::~PDFGaussian()
@@ -53,43 +53,43 @@ PDFGaussian::~PDFGaussian()
 
 double PDFGaussian::getNLogDensity(const NICE::Vector & x) const
 {
-	// (x-mean)
-	Vector diff ( x-mean );
-	// covInvX = covariance^-1 (x-mean)
-	Vector covInvX;
-	choleskySolve ( covCholesky, diff, covInvX );
-	double result = constant + ldet + diff.scalarProduct( covInvX );
-	return result;
+  // (x-mean)
+  Vector diff ( x - mean );
+  // covInvX = covariance^-1 (x-mean)
+  Vector covInvX;
+  choleskySolve ( covCholesky, diff, covInvX );
+  double result = constant + ldet + diff.scalarProduct( covInvX );
+  return result;
 }
 
 int PDFGaussian::getDimension() const
 {
-	return mean.size();
+  return mean.size();
 }
 
 NICE::Vector PDFGaussian::getMean()
 {
-	return mean;
+  return mean;
 }
 
 
 NICE::Matrix PDFGaussian::getCovariance()
 {
-	if (covariance.rows() == 0 || covariance.cols() == 0)
-		fthrow(Exception, "No covariance initialized, use other constructor !!");
-	return covariance;
+  if (covariance.rows() == 0 || covariance.cols() == 0)
+    fthrow(Exception, "No covariance initialized, use other constructor !!");
+  return covariance;
 }
 
 void PDFGaussian::sample(VVector & samples, int count) const
 {
-	for (int i = 0 ; i < count ; i++)
-	{
-		NICE::Vector x(mean.size());
-		NICE::Vector tmp(mean.size());
-
-		tmp = NICE::VectorT<double>::GaussRandom(mean.size(), 0.0, 1.0);
-		// cholesky decomposed covariance matrix * gauss vector
-		x = mean + covCholesky * tmp;
-		samples.push_back(x);
-	}
+  for (int i = 0 ; i < count ; i++)
+  {
+    NICE::Vector x(mean.size());
+    NICE::Vector tmp(mean.size());
+
+    tmp = NICE::VectorT<double>::GaussRandom(mean.size(), 0.0, 1.0);
+    // cholesky decomposed covariance matrix * gauss vector
+    x = mean + covCholesky * tmp;
+    samples.push_back(x);
+  }
 }

+ 5 - 0
matlabAccessHighLevel/ImageNetData.cpp

@@ -5,6 +5,9 @@
 * @date 02/03/2012
 
 */
+
+#ifdef NICE_USELIB_MATIO
+
 #include <iostream>
 #include <vector>
 
@@ -141,3 +144,5 @@ void ImageNetData::loadExternalLabels ( const string & fn, int n )
   if ( (XPreload.size() > 0) && (yPreload.size() != XPreload.size()) )
     fthrow(Exception, "Size of the label vector and the size of the data structure do not match.");
 }
+
+#endif

+ 3 - 0
matlabAccessHighLevel/ImageNetData.h

@@ -7,6 +7,8 @@
 #ifndef _NICE_IMAGENETDATAINCLUDE
 #define _NICE_IMAGENETDATAINCLUDE
 
+#ifdef NICE_USELIB_MATIO
+
 #include <string>
 
 #include <core/vector/VectorT.h>
@@ -106,5 +108,6 @@ class ImageNetData
 };
 
 }
+#endif
 
 #endif

+ 0 - 88
matlabAccessHighLevel/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))
-

+ 4 - 0
progs/testImageNetBinaryBruteForce.cpp

@@ -5,6 +5,8 @@
 * @date 23-05-2012 (dd-mm-yyyy)
 */
 
+#ifdef NICE_USELIB_MATIO
+
 #include <ctime>
 #include <time.h>
 
@@ -1773,3 +1775,5 @@ int main (int argc, char **argv)
   
   return 0;
 }
+
+#endif