Просмотр исходного кода

removed annoying bug for test-set testing, still with debug outputs

Alexander Freytag 9 лет назад
Родитель
Сommit
0bfcd565d8
2 измененных файлов с 52 добавлено и 12 удалено
  1. 13 11
      GPHIKRawClassifier.cpp
  2. 39 1
      matlab/GPHIKRawClassifierMex.cpp

+ 13 - 11
GPHIKRawClassifier.cpp

@@ -9,6 +9,8 @@
 // STL includes
 #include <iostream>
 
+#include <unistd.h>
+
 // NICE-core includes
 #include <core/basics/numerictools.h>
 #include <core/basics/Timer.h>
@@ -430,9 +432,9 @@ void GPHIKRawClassifier::classify ( const NICE::SparseVector * _xstar,
 
 
 void GPHIKRawClassifier::classify ( const NICE::SparseVector * _xstar,
-                                 uint & _result,
-                                 Vector & _scores
-                               ) const
+                                    uint & _result,
+                                    Vector & _scores
+                                  ) const
 {
   if ( ! this->b_isTrained )
      fthrow(Exception, "Classifier not trained yet -- aborting!" );
@@ -561,7 +563,7 @@ void GPHIKRawClassifier::classify ( const std::vector< const NICE::SparseVector
                                     NICE::Matrix & _scores
                                   ) const
 {
-    _scores.resize( _examples.size(), this->knownClasses.size() );
+    _scores.resize( _examples.size(), * (this->knownClasses.rbegin()) +1 );
     _scores.set( 0.0 );
 
     _results.resize( _examples.size() );
@@ -569,24 +571,24 @@ void GPHIKRawClassifier::classify ( const std::vector< const NICE::SparseVector
 
 
     NICE::Vector::iterator resultsIt = _results.begin();
-    NICE::Vector scoresSingle( this->knownClasses.size(), 0.0);
 
 
     uint exCnt ( 0 );
+    uint resUI ( 0 );    
+    NICE::Vector scoresSingle( *(this->knownClasses.rbegin())+1, -std::numeric_limits<double>::max() );
+        
     for ( std::vector< const NICE::SparseVector *>::const_iterator exIt = _examples.begin();
           exIt != _examples.end();
           exIt++, resultsIt++, exCnt++
         )
     {
-      uint resUI;
         this->classify ( *exIt,
-                        resUI,
-                        scoresSingle
+                         resUI,
+                         scoresSingle
                        );
-
         *resultsIt = resUI;
         _scores.setRow( exCnt, scoresSingle );
-        scoresSingle.set( 0.0 );
+       scoresSingle.set( -std::numeric_limits<double>::max() );
     }
 }
 
@@ -758,7 +760,7 @@ void GPHIKRawClassifier::train ( const std::vector< const NICE::SparseVector *>
 
   t.stop();
   if ( this->b_verbose )
-    std::cerr << "Time used for setting up the fmk object: " << t.getLast() << std::endl;
+    std::cerr << "Time used for GPHIKRawClassifier::train: " << t.getLast() << std::endl;
 
   //indicate that we finished training successfully
   this->b_isTrained = true;

+ 39 - 1
matlab/GPHIKRawClassifierMex.cpp

@@ -274,7 +274,18 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
         yMultiTrain = MatlabConversion::convertDoubleVectorToNice(prhs[3]);
 
         //----------------- train our classifier -------------
+        NICE::Timer t;
+        t.start();	
+	
         classifier->train ( examplesTrain , yMultiTrain );
+	
+        t.stop();
+	
+	
+      FILE * pFile;
+      pFile = fopen ("/home/freytag/experiments/gphik/2015-08-28-gphik-classif/training_times_gphik_raw.txt","a");
+      fprintf (pFile, "GPHIKRaw-Mex -- Time for training without data conversion: %f \n",t.getLast());
+      fclose (pFile);	
 
         //----------------- clean up -------------
         for(int i=0;i<examplesTrain.size();i++)
@@ -303,8 +314,21 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
             
             //----------------- classification -------------
             NICE::Vector results;
-            NICE::Matrix scores;            
+            NICE::Matrix scores;
+
+
+            NICE::Timer t;
+            t.start();
+
             classifier->classify ( examplesTest,  results, scores );
+
+            t.stop();
+
+
+          FILE * pFile;
+          pFile = fopen ("/home/freytag/experiments/gphik/2015-08-28-gphik-classif/test_times_gphik_raw_quant.txt","a");
+          fprintf (pFile, "GPHIKRaw-Mex-Quant test time %f \n",t.getLast());
+          fclose (pFile);
             
             //----------------- clean up -------------
             for ( std::vector< const NICE::SparseVector *>::iterator exIt = examplesTest.begin();
@@ -333,8 +357,22 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
             //----------------- classification -------------
             uint result;
             NICE::SparseVector scores;
+
+
+            NICE::Timer t;
+            t.start();
+
+
             classifier->classify ( example,  result, scores );
 
+            t.stop();
+
+
+          FILE * pFile;
+          pFile = fopen ("/home/freytag/experiments/gphik/2015-08-28-gphik-classif/test_times_gphik_raw_quant.txt","a");
+          fprintf (pFile, "GPHIKRaw-Mex-Quant test time %f \n",t.getLast());
+          fclose (pFile);
+
             //----------------- clean up -------------
             delete example;