Procházet zdrojové kódy

stable but unchecked version of matrix of test features for raw gphik

Alexander Freytag před 9 roky
rodič
revize
f693dadf31
2 změnil soubory, kde provedl 69 přidání a 27 odebrání
  1. 10 11
      GPHIKRawClassifier.cpp
  2. 59 16
      matlab/GPHIKRawClassifierMex.cpp

+ 10 - 11
GPHIKRawClassifier.cpp

@@ -532,9 +532,9 @@ void GPHIKRawClassifier::classify ( const NICE::SparseVector * _xstar,
   {
     uint class1 = *(this->knownClasses.begin());
     uint class2 = *(this->knownClasses.rbegin());
-    uint class_for_which_we_have_a_score = _scores.begin()->first;
-    uint class_for_which_we_dont_have_a_score = (class1 == class_for_which_we_have_a_score ? class2 : class1);
-
+    uint class_for_which_we_have_a_score = ( class1 < class2  ? class2 : class1 );
+    uint class_for_which_we_dont_have_a_score = ( class1 < class2  ? class1 : class2);
+    
     _scores[class_for_which_we_dont_have_a_score] = - _scores[class_for_which_we_have_a_score];
 
     _result = _scores[class_for_which_we_have_a_score] > 0.0 ? class_for_which_we_have_a_score : class_for_which_we_dont_have_a_score;
@@ -547,11 +547,9 @@ void GPHIKRawClassifier::classify ( const std::vector< const NICE::SparseVector
                                     NICE::Matrix & _scores
                                   ) const
 {
-    _scores.clear();
     _scores.resize( _examples.size(), this->knownClasses.size() );
     _scores.set( 0.0 );
 
-    _results.clear();
     _results.resize( _examples.size() );
     _results.set( 0.0 );
 
@@ -561,17 +559,18 @@ void GPHIKRawClassifier::classify ( const std::vector< const NICE::SparseVector
 
 
     uint exCnt ( 0 );
-    for ( std::vector< const NICE::SparseVector *> exIt = _examples.begin();
+    for ( std::vector< const NICE::SparseVector *>::const_iterator exIt = _examples.begin();
           exIt != _examples.end();
-          exIt++, resultsIt++
+          exIt++, resultsIt++, exCnt++
         )
     {
-        this->classify ( exIt,
-                        *resultsIt,
-                        scoresSingle,
-                         exCnt++
+      uint resUI;
+        this->classify ( *exIt,
+                        resUI,
+                        scoresSingle
                        );
 
+        *resultsIt = resUI;
         _scores.setRow( exCnt, scoresSingle );
         scoresSingle.set( 0.0 );
     }

+ 59 - 16
matlab/GPHIKRawClassifierMex.cpp

@@ -292,44 +292,87 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
             mexErrMsgTxt("Test: Unexpected arguments.");
         }
 
-        //------------- read the data --------------
-
-        uint result;
-        NICE::SparseVector scores;
-
         if ( mxIsSparse( prhs[2] ) )
         {
+          if ( isMatrix )
+          {
+            //----------------- conversion -------------
+            std::vector< const NICE::SparseVector *> examplesTest;
+            examplesTest = MatlabConversion::convertSparseMatrixToNice( prhs[2] );
+            
+            //----------------- classification -------------
+            NICE::Vector results;
+            NICE::Matrix scores;            
+            classifier->classify ( examplesTest,  results, scores );
+            
+            //----------------- clean up -------------
+            for ( std::vector< const NICE::SparseVector *>::iterator exIt = examplesTest.begin();
+                 exIt != examplesTest.end();
+                 exIt++
+            )
+            {
+              delete *exIt;
+            }
+            
+            //----------------- output -------------
+            plhs[0] = MatlabConversion::convertVectorFromNice( results );
+
+            if(nlhs >= 2)
+            {
+              plhs[1] = MatlabConversion::convertMatrixFromNice( scores );
+            }
+            return;            
+          }
+          else
+          { 
+            //----------------- conversion -------------
             NICE::SparseVector * example;
             example = new NICE::SparseVector ( MatlabConversion::convertSparseVectorToNice( prhs[2] ) );
+            
+            //----------------- classification -------------
+            uint result;
+            NICE::SparseVector scores;
             classifier->classify ( example,  result, scores );
 
             //----------------- clean up -------------
             delete example;
+            
+            //----------------- output -------------
+            plhs[0] = mxCreateDoubleScalar( result );
+
+            if(nlhs >= 2)
+            {
+              plhs[1] = MatlabConversion::convertSparseVectorFromNice( scores, true  /*b_adaptIndex*/);
+            }
+            return;            
+          }
         }
         else
         {
+            //----------------- conversion -------------          
             NICE::Vector * example;
             example = new NICE::Vector ( MatlabConversion::convertDoubleVectorToNice(prhs[2]) );
             NICE::SparseVector * svec  = new NICE::SparseVector( *example );
             delete example;
 
+            //----------------- classification -------------
+            uint result;
+            NICE::SparseVector scores;            
             classifier->classify ( svec,  result, scores );
 
             //----------------- clean up -------------
             delete svec;
+            
+            
+            //----------------- output -------------
+            plhs[0] = mxCreateDoubleScalar( result );
 
+            if(nlhs >= 2)
+            {
+              plhs[1] = MatlabConversion::convertSparseVectorFromNice( scores, true  /*b_adaptIndex*/);
+            }
+            return;
         }
-
-
-
-          // output
-          plhs[0] = mxCreateDoubleScalar( result );
-
-          if(nlhs >= 2)
-          {
-            plhs[1] = MatlabConversion::convertSparseVectorFromNice( scores, true  /*b_adaptIndex*/);
-          }
-          return;
     }