GPHIKClassifier.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. /**
  2. * @file GPHIKClassifier.cpp
  3. * @brief Main interface for our GP HIK classifier (similar to the feature pool classifier interface in vislearning) (Implementation)
  4. * @author Erik Rodner, Alexander Freytag
  5. * @date 02/01/2012
  6. */
  7. // STL includes
  8. #include <iostream>
  9. // NICE-core includes
  10. #include <core/basics/numerictools.h>
  11. #include <core/basics/Timer.h>
  12. // gp-hik-core includes
  13. #include "GPHIKClassifier.h"
  14. #include "gp-hik-core/parameterizedFunctions/PFAbsExp.h"
  15. #include "gp-hik-core/parameterizedFunctions/PFExp.h"
  16. #include "gp-hik-core/parameterizedFunctions/PFMKL.h"
  17. using namespace std;
  18. using namespace NICE;
  19. /////////////////////////////////////////////////////
  20. /////////////////////////////////////////////////////
  21. // PROTECTED METHODS
  22. /////////////////////////////////////////////////////
  23. /////////////////////////////////////////////////////
  24. void GPHIKClassifier::init(const Config *conf, const string & s_confSection)
  25. {
  26. //copy the given config to have it accessible lateron
  27. if ( this->confCopy != conf )
  28. {
  29. if ( this->confCopy != NULL )
  30. delete this->confCopy;
  31. this->confCopy = new Config ( *conf );
  32. //we do not want to read until end of file for restoring
  33. this->confCopy->setIoUntilEndOfFile(false);
  34. }
  35. double parameterUpperBound = confCopy->gD(confSection, "parameter_upper_bound", 5.0 );
  36. double parameterLowerBound = confCopy->gD(confSection, "parameter_lower_bound", 1.0 );
  37. this->noise = confCopy->gD(confSection, "noise", 0.01);
  38. string transform = confCopy->gS(confSection, "transform", "absexp" );
  39. if (pf == NULL)
  40. {
  41. if ( transform == "absexp" )
  42. {
  43. this->pf = new PFAbsExp( 1.0, parameterLowerBound, parameterUpperBound );
  44. } else if ( transform == "exp" ) {
  45. this->pf = new PFExp( 1.0, parameterLowerBound, parameterUpperBound );
  46. }else if ( transform == "MKL" ) {
  47. //TODO generic, please :) load from a separate file or something like this!
  48. std::set<int> steps; steps.insert(4000); steps.insert(6000); //specific for VISAPP
  49. this->pf = new PFMKL( steps, parameterLowerBound, parameterUpperBound );
  50. } else {
  51. fthrow(Exception, "Transformation type is unknown " << transform);
  52. }
  53. }
  54. else
  55. {
  56. //we already know the pf from the restore-function
  57. }
  58. this->confSection = confSection;
  59. this->verbose = confCopy->gB(confSection, "verbose", false);
  60. this->debug = confCopy->gB(confSection, "debug", false);
  61. this->uncertaintyPredictionForClassification = confCopy->gB( confSection, "uncertaintyPredictionForClassification", false );
  62. //how do we approximate the predictive variance for classification uncertainty?
  63. string s_varianceApproximation = confCopy->gS(confSection, "varianceApproximation", "approximate_fine"); //default: fine approximative uncertainty prediction
  64. if ( (s_varianceApproximation.compare("approximate_rough") == 0) || ((s_varianceApproximation.compare("1") == 0)) )
  65. {
  66. this->varianceApproximation = APPROXIMATE_ROUGH;
  67. //no additional eigenvalue is needed here at all.
  68. this->confCopy->sI ( confSection, "nrOfEigenvaluesToConsiderForVarApprox", 0 );
  69. }
  70. else if ( (s_varianceApproximation.compare("approximate_fine") == 0) || ((s_varianceApproximation.compare("2") == 0)) )
  71. {
  72. this->varianceApproximation = APPROXIMATE_FINE;
  73. //security check - compute at least one eigenvalue for this approximation strategy
  74. this->confCopy->sI ( confSection, "nrOfEigenvaluesToConsiderForVarApprox", std::max( confCopy->gI(confSection, "nrOfEigenvaluesToConsiderForVarApprox", 1 ), 1) );
  75. }
  76. else if ( (s_varianceApproximation.compare("exact") == 0) || ((s_varianceApproximation.compare("3") == 0)) )
  77. {
  78. this->varianceApproximation = EXACT;
  79. //no additional eigenvalue is needed here at all.
  80. this->confCopy->sI ( confSection, "nrOfEigenvaluesToConsiderForVarApprox", 1 );
  81. }
  82. else
  83. {
  84. this->varianceApproximation = NONE;
  85. //no additional eigenvalue is needed here at all.
  86. this->confCopy->sI ( confSection, "nrOfEigenvaluesToConsiderForVarApprox", 1 );
  87. }
  88. if ( this->verbose )
  89. std::cerr << "varianceApproximationStrategy: " << s_varianceApproximation << std::endl;
  90. }
  91. /////////////////////////////////////////////////////
  92. /////////////////////////////////////////////////////
  93. // PUBLIC METHODS
  94. /////////////////////////////////////////////////////
  95. /////////////////////////////////////////////////////
  96. GPHIKClassifier::GPHIKClassifier( const Config *conf, const string & s_confSection )
  97. {
  98. //default settings, may be overwritten lateron
  99. gphyper = NULL;
  100. pf = NULL;
  101. confCopy = NULL;
  102. //just a default value
  103. uncertaintyPredictionForClassification = false;
  104. this->confSection = s_confSection;
  105. // if no config file was given, we either restore the classifier from an external file, or run ::init with
  106. // an emtpy config (using default values thereby) when calling the train-method
  107. if ( conf != NULL )
  108. {
  109. this->init(conf, confSection);
  110. }
  111. }
  112. GPHIKClassifier::~GPHIKClassifier()
  113. {
  114. if ( gphyper != NULL )
  115. delete gphyper;
  116. if (pf != NULL)
  117. delete pf;
  118. if ( confCopy != NULL )
  119. delete confCopy;
  120. }
  121. ///////////////////// ///////////////////// /////////////////////
  122. // GET / SET
  123. ///////////////////// ///////////////////// /////////////////////
  124. std::set<int> GPHIKClassifier::getKnownClassNumbers ( ) const
  125. {
  126. if (gphyper == NULL)
  127. fthrow(Exception, "Classifier not trained yet -- aborting!" );
  128. return gphyper->getKnownClassNumbers();
  129. }
  130. ///////////////////// ///////////////////// /////////////////////
  131. // CLASSIFIER STUFF
  132. ///////////////////// ///////////////////// /////////////////////
  133. void GPHIKClassifier::classify ( const SparseVector * example, int & result, SparseVector & scores ) const
  134. {
  135. double tmpUncertainty;
  136. this->classify( example, result, scores, tmpUncertainty );
  137. }
  138. void GPHIKClassifier::classify ( const NICE::Vector * example, int & result, SparseVector & scores ) const
  139. {
  140. double tmpUncertainty;
  141. this->classify( example, result, scores, tmpUncertainty );
  142. }
  143. void GPHIKClassifier::classify ( const SparseVector * example, int & result, SparseVector & scores, double & uncertainty ) const
  144. {
  145. if (gphyper == NULL)
  146. fthrow(Exception, "Classifier not trained yet -- aborting!" );
  147. scores.clear();
  148. result = gphyper->classify ( *example, scores );
  149. if ( scores.size() == 0 ) {
  150. fthrow(Exception, "Zero scores, something is likely to be wrong here: svec.size() = " << example->size() );
  151. }
  152. if (uncertaintyPredictionForClassification)
  153. {
  154. if (varianceApproximation != NONE)
  155. {
  156. this->predictUncertainty( example, uncertainty );
  157. }
  158. else
  159. {
  160. //do nothing
  161. uncertainty = std::numeric_limits<double>::max();
  162. }
  163. }
  164. else
  165. {
  166. //do nothing
  167. uncertainty = std::numeric_limits<double>::max();
  168. }
  169. }
  170. void GPHIKClassifier::classify ( const NICE::Vector * example, int & result, SparseVector & scores, double & uncertainty ) const
  171. {
  172. if (gphyper == NULL)
  173. fthrow(Exception, "Classifier not trained yet -- aborting!" );
  174. scores.clear();
  175. result = gphyper->classify ( *example, scores );
  176. if ( scores.size() == 0 ) {
  177. fthrow(Exception, "Zero scores, something is likely to be wrong here: svec.size() = " << example->size() );
  178. }
  179. if (uncertaintyPredictionForClassification)
  180. {
  181. if (varianceApproximation != NONE)
  182. {
  183. this->predictUncertainty( example, uncertainty );
  184. }
  185. else
  186. {
  187. //do nothing
  188. uncertainty = std::numeric_limits<double>::max();
  189. }
  190. }
  191. else
  192. {
  193. //do nothing
  194. uncertainty = std::numeric_limits<double>::max();
  195. }
  196. }
  197. /** training process */
  198. void GPHIKClassifier::train ( const std::vector< const NICE::SparseVector *> & examples, const NICE::Vector & labels )
  199. {
  200. // security-check: examples and labels have to be of same size
  201. if ( examples.size() != labels.size() )
  202. {
  203. fthrow(Exception, "Given examples do not match label vector in size -- aborting!" );
  204. }
  205. if (verbose)
  206. {
  207. std::cerr << "GPHIKClassifier::train" << std::endl;
  208. }
  209. if ( this->confCopy == NULL )
  210. {
  211. std::cerr << "WARNING -- No config used so far, initialize values with empty config file now..." << std::endl;
  212. NICE::Config tmpConfEmpty ;
  213. this->init ( &tmpConfEmpty, this->confSection );
  214. }
  215. Timer t;
  216. t.start();
  217. FastMinKernel *fmk = new FastMinKernel ( examples, noise, this->debug );
  218. t.stop();
  219. if (verbose)
  220. std::cerr << "Time used for setting up the fmk object: " << t.getLast() << std::endl;
  221. if (gphyper != NULL)
  222. delete gphyper;
  223. if ( ( varianceApproximation != APPROXIMATE_FINE) )
  224. confCopy->sI ( confSection, "nrOfEigenvaluesToConsiderForVarApprox", 0);
  225. gphyper = new FMKGPHyperparameterOptimization ( confCopy, pf, fmk, confSection );
  226. if (verbose)
  227. cerr << "Learning ..." << endl;
  228. // go go go
  229. gphyper->optimize ( labels );
  230. if (verbose)
  231. std::cerr << "optimization done" << std::endl;
  232. if ( ( varianceApproximation != NONE ) )
  233. {
  234. switch (varianceApproximation)
  235. {
  236. case APPROXIMATE_ROUGH:
  237. {
  238. gphyper->prepareVarianceApproximationRough();
  239. break;
  240. }
  241. case APPROXIMATE_FINE:
  242. {
  243. gphyper->prepareVarianceApproximationFine();
  244. break;
  245. }
  246. case EXACT:
  247. {
  248. //nothing to prepare
  249. break;
  250. }
  251. default:
  252. {
  253. //nothing to prepare
  254. }
  255. }
  256. }
  257. // clean up all examples ??
  258. if (verbose)
  259. std::cerr << "Learning finished" << std::endl;
  260. }
  261. /** training process */
  262. void GPHIKClassifier::train ( const std::vector< const NICE::SparseVector *> & examples, std::map<int, NICE::Vector> & binLabels )
  263. {
  264. // security-check: examples and labels have to be of same size
  265. for ( std::map< int, NICE::Vector >::const_iterator binLabIt = binLabels.begin();
  266. binLabIt != binLabels.end();
  267. binLabIt++
  268. )
  269. {
  270. if ( examples.size() != binLabIt->second.size() )
  271. {
  272. fthrow(Exception, "Given examples do not match label vector in size -- aborting!" );
  273. }
  274. }
  275. if (verbose)
  276. std::cerr << "GPHIKClassifier::train" << std::endl;
  277. if ( this->confCopy == NULL )
  278. {
  279. std::cerr << "WARNING -- No config used so far, initialize values with empty config file now..." << std::endl;
  280. NICE::Config tmpConfEmpty ;
  281. this->init ( &tmpConfEmpty, this->confSection );
  282. }
  283. Timer t;
  284. t.start();
  285. FastMinKernel *fmk = new FastMinKernel ( examples, noise, this->debug );
  286. t.stop();
  287. if (verbose)
  288. std::cerr << "Time used for setting up the fmk object: " << t.getLast() << std::endl;
  289. if (gphyper != NULL)
  290. delete gphyper;
  291. gphyper = new FMKGPHyperparameterOptimization ( confCopy, pf, fmk, confSection );
  292. if (verbose)
  293. cerr << "Learning ..." << endl;
  294. // go go go
  295. gphyper->optimize ( binLabels );
  296. if (verbose)
  297. std::cerr << "optimization done, now prepare for the uncertainty prediction" << std::endl;
  298. if ( ( varianceApproximation != NONE ) )
  299. {
  300. switch (varianceApproximation)
  301. {
  302. case APPROXIMATE_ROUGH:
  303. {
  304. gphyper->prepareVarianceApproximationRough();
  305. break;
  306. }
  307. case APPROXIMATE_FINE:
  308. {
  309. gphyper->prepareVarianceApproximationFine();
  310. break;
  311. }
  312. case EXACT:
  313. {
  314. //nothing to prepare
  315. break;
  316. }
  317. default:
  318. {
  319. //nothing to prepare
  320. }
  321. }
  322. }
  323. // clean up all examples ??
  324. if (verbose)
  325. std::cerr << "Learning finished" << std::endl;
  326. }
  327. GPHIKClassifier *GPHIKClassifier::clone () const
  328. {
  329. fthrow(Exception, "GPHIKClassifier: clone() not yet implemented" );
  330. return NULL;
  331. }
  332. void GPHIKClassifier::predictUncertainty( const NICE::SparseVector * example, double & uncertainty ) const
  333. {
  334. if (gphyper == NULL)
  335. fthrow(Exception, "Classifier not trained yet -- aborting!" );
  336. //we directly store the predictive variances in the vector, that contains the classification uncertainties lateron to save storage
  337. switch (varianceApproximation)
  338. {
  339. case APPROXIMATE_ROUGH:
  340. {
  341. gphyper->computePredictiveVarianceApproximateRough( *example, uncertainty );
  342. break;
  343. }
  344. case APPROXIMATE_FINE:
  345. {
  346. std::cerr << "predict uncertainty fine" << std::endl;
  347. gphyper->computePredictiveVarianceApproximateFine( *example, uncertainty );
  348. break;
  349. }
  350. case EXACT:
  351. {
  352. gphyper->computePredictiveVarianceExact( *example, uncertainty );
  353. break;
  354. }
  355. default:
  356. {
  357. fthrow(Exception, "GPHIKClassifier - your settings disabled the variance approximation needed for uncertainty prediction.");
  358. // uncertainty = numeric_limits<double>::max();
  359. // break;
  360. }
  361. }
  362. }
  363. void GPHIKClassifier::predictUncertainty( const NICE::Vector * example, double & uncertainty ) const
  364. {
  365. if (gphyper == NULL)
  366. fthrow(Exception, "Classifier not trained yet -- aborting!" );
  367. //we directly store the predictive variances in the vector, that contains the classification uncertainties lateron to save storage
  368. switch (varianceApproximation)
  369. {
  370. case APPROXIMATE_ROUGH:
  371. {
  372. gphyper->computePredictiveVarianceApproximateRough( *example, uncertainty );
  373. break;
  374. }
  375. case APPROXIMATE_FINE:
  376. {
  377. gphyper->computePredictiveVarianceApproximateFine( *example, uncertainty );
  378. break;
  379. }
  380. case EXACT:
  381. {
  382. gphyper->computePredictiveVarianceExact( *example, uncertainty );
  383. break;
  384. }
  385. default:
  386. {
  387. fthrow(Exception, "GPHIKClassifier - your settings disabled the variance approximation needed for uncertainty prediction.");
  388. // uncertainty = numeric_limits<double>::max();
  389. // break;
  390. }
  391. }
  392. }
  393. ///////////////////// INTERFACE PERSISTENT /////////////////////
  394. // interface specific methods for store and restore
  395. ///////////////////// INTERFACE PERSISTENT /////////////////////
  396. void GPHIKClassifier::restore ( std::istream & is, int format )
  397. {
  398. //delete everything we knew so far...
  399. this->clear();
  400. bool b_restoreVerbose ( false );
  401. #ifdef B_RESTOREVERBOSE
  402. b_restoreVerbose = true;
  403. #endif
  404. if ( is.good() )
  405. {
  406. if ( b_restoreVerbose )
  407. std::cerr << " restore GPHIKClassifier" << std::endl;
  408. std::string tmp;
  409. is >> tmp; //class name
  410. if ( ! this->isStartTag( tmp, "GPHIKClassifier" ) )
  411. {
  412. std::cerr << " WARNING - attempt to restore GPHIKClassifier, but start flag " << tmp << " does not match! Aborting... " << std::endl;
  413. throw;
  414. }
  415. if (pf != NULL)
  416. {
  417. delete pf;
  418. pf = NULL;
  419. }
  420. if ( confCopy != NULL )
  421. {
  422. delete confCopy;
  423. confCopy = NULL;
  424. }
  425. if (gphyper != NULL)
  426. {
  427. delete gphyper;
  428. gphyper = NULL;
  429. }
  430. is.precision (numeric_limits<double>::digits10 + 1);
  431. bool b_endOfBlock ( false ) ;
  432. while ( !b_endOfBlock )
  433. {
  434. is >> tmp; // start of block
  435. if ( this->isEndTag( tmp, "GPHIKClassifier" ) )
  436. {
  437. b_endOfBlock = true;
  438. continue;
  439. }
  440. tmp = this->removeStartTag ( tmp );
  441. if ( b_restoreVerbose )
  442. std::cerr << " currently restore section " << tmp << " in GPHIKClassifier" << std::endl;
  443. if ( tmp.compare("confSection") == 0 )
  444. {
  445. is >> confSection;
  446. is >> tmp; // end of block
  447. tmp = this->removeEndTag ( tmp );
  448. }
  449. else if ( tmp.compare("pf") == 0 )
  450. {
  451. is >> tmp; // start of block
  452. if ( this->isEndTag( tmp, "pf" ) )
  453. {
  454. std::cerr << " ParameterizedFunction object can not be restored. Aborting..." << std::endl;
  455. throw;
  456. }
  457. std::string transform = this->removeStartTag ( tmp );
  458. if ( transform == "PFAbsExp" )
  459. {
  460. this->pf = new PFAbsExp ();
  461. } else if ( transform == "PFExp" ) {
  462. this->pf = new PFExp ();
  463. } else {
  464. fthrow(Exception, "Transformation type is unknown " << transform);
  465. }
  466. pf->restore(is, format);
  467. is >> tmp; // end of block
  468. tmp = this->removeEndTag ( tmp );
  469. }
  470. else if ( tmp.compare("ConfigCopy") == 0 )
  471. {
  472. // possibly obsolete safety checks
  473. if ( confCopy == NULL )
  474. confCopy = new Config;
  475. confCopy->clear();
  476. //we do not want to read until the end of the file
  477. confCopy->setIoUntilEndOfFile( false );
  478. //load every options we determined explicitely
  479. confCopy->restore(is, format);
  480. is >> tmp; // end of block
  481. tmp = this->removeEndTag ( tmp );
  482. }
  483. else if ( tmp.compare("gphyper") == 0 )
  484. {
  485. if ( gphyper == NULL )
  486. gphyper = new NICE::FMKGPHyperparameterOptimization();
  487. //then, load everything that we stored explicitely,
  488. // including precomputed matrices, LUTs, eigenvalues, ... and all that stuff
  489. gphyper->restore(is, format);
  490. is >> tmp; // end of block
  491. tmp = this->removeEndTag ( tmp );
  492. }
  493. else
  494. {
  495. std::cerr << "WARNING -- unexpected GPHIKClassifier object -- " << tmp << " -- for restoration... aborting" << std::endl;
  496. throw;
  497. }
  498. }
  499. //load every settings as well as default options
  500. std::cerr << "run this->init" << std::endl;
  501. this->init(confCopy, confSection);
  502. std::cerr << "run gphyper->initialize" << std::endl;
  503. gphyper->initialize ( confCopy, pf, NULL, confSection );
  504. }
  505. else
  506. {
  507. std::cerr << "GPHIKClassifier::restore -- InStream not initialized - restoring not possible!" << std::endl;
  508. throw;
  509. }
  510. }
  511. void GPHIKClassifier::store ( std::ostream & os, int format ) const
  512. {
  513. if (gphyper == NULL)
  514. fthrow(Exception, "Classifier not trained yet -- aborting!" );
  515. if (os.good())
  516. {
  517. // show starting point
  518. os << this->createStartTag( "GPHIKClassifier" ) << std::endl;
  519. os.precision (numeric_limits<double>::digits10 + 1);
  520. os << this->createStartTag( "confSection" ) << std::endl;
  521. os << confSection << std::endl;
  522. os << this->createEndTag( "confSection" ) << std::endl;
  523. os << this->createStartTag( "pf" ) << std::endl;
  524. pf->store(os, format);
  525. os << this->createEndTag( "pf" ) << std::endl;
  526. os << this->createStartTag( "ConfigCopy" ) << std::endl;
  527. //we do not want to read until end of file for restoring
  528. confCopy->setIoUntilEndOfFile(false);
  529. confCopy->store(os,format);
  530. os << this->createEndTag( "ConfigCopy" ) << std::endl;
  531. os << this->createStartTag( "gphyper" ) << std::endl;
  532. //store the underlying data
  533. //will be done in gphyper->store(of,format)
  534. //store the optimized parameter values and all that stuff
  535. gphyper->store(os, format);
  536. os << this->createEndTag( "gphyper" ) << std::endl;
  537. // done
  538. os << this->createEndTag( "GPHIKClassifier" ) << std::endl;
  539. }
  540. else
  541. {
  542. std::cerr << "OutStream not initialized - storing not possible!" << std::endl;
  543. }
  544. }
  545. void GPHIKClassifier::clear ()
  546. {
  547. if ( gphyper != NULL )
  548. {
  549. delete gphyper;
  550. gphyper = NULL;
  551. }
  552. if (pf != NULL)
  553. {
  554. delete pf;
  555. pf = NULL;
  556. }
  557. if ( confCopy != NULL )
  558. {
  559. delete confCopy;
  560. confCopy = NULL;
  561. }
  562. }
  563. ///////////////////// INTERFACE ONLINE LEARNABLE /////////////////////
  564. // interface specific methods for incremental extensions
  565. ///////////////////// INTERFACE ONLINE LEARNABLE /////////////////////
  566. void GPHIKClassifier::addExample( const NICE::SparseVector * example,
  567. const double & label,
  568. const bool & performOptimizationAfterIncrement
  569. )
  570. {
  571. if ( this->gphyper == NULL )
  572. {
  573. //call train method instead
  574. std::cerr << "Classifier not initially trained yet -- run initial training instead of incremental extension!" << std::endl;
  575. std::vector< const NICE::SparseVector *> examplesVec;
  576. examplesVec.push_back ( example );
  577. NICE::Vector labelsVec ( 1 , label );
  578. this->train ( examplesVec, labelsVec );
  579. }
  580. else
  581. {
  582. this->gphyper->addExample( example, label, performOptimizationAfterIncrement );
  583. }
  584. }
  585. void GPHIKClassifier::addMultipleExamples( const std::vector< const NICE::SparseVector * > & newExamples,
  586. const NICE::Vector & newLabels,
  587. const bool & performOptimizationAfterIncrement
  588. )
  589. {
  590. //are new examples available? If not, nothing has to be done
  591. if ( newExamples.size() < 1)
  592. return;
  593. if ( this->gphyper == NULL )
  594. {
  595. //call train method instead
  596. std::cerr << "Classifier not initially trained yet -- run initial training instead of incremental extension!" << std::endl;
  597. this->train ( newExamples, newLabels );
  598. }
  599. else
  600. {
  601. this->gphyper->addMultipleExamples( newExamples, newLabels, performOptimizationAfterIncrement );
  602. }
  603. }