GPHIKClassifier.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  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. gphyper->computePredictiveVarianceApproximateFine( *example, uncertainty );
  347. break;
  348. }
  349. case EXACT:
  350. {
  351. gphyper->computePredictiveVarianceExact( *example, uncertainty );
  352. break;
  353. }
  354. default:
  355. {
  356. fthrow(Exception, "GPHIKClassifier - your settings disabled the variance approximation needed for uncertainty prediction.");
  357. // uncertainty = numeric_limits<double>::max();
  358. // break;
  359. }
  360. }
  361. }
  362. void GPHIKClassifier::predictUncertainty( const NICE::Vector * example, double & uncertainty ) const
  363. {
  364. if (gphyper == NULL)
  365. fthrow(Exception, "Classifier not trained yet -- aborting!" );
  366. //we directly store the predictive variances in the vector, that contains the classification uncertainties lateron to save storage
  367. switch (varianceApproximation)
  368. {
  369. case APPROXIMATE_ROUGH:
  370. {
  371. gphyper->computePredictiveVarianceApproximateRough( *example, uncertainty );
  372. break;
  373. }
  374. case APPROXIMATE_FINE:
  375. {
  376. gphyper->computePredictiveVarianceApproximateFine( *example, uncertainty );
  377. break;
  378. }
  379. case EXACT:
  380. {
  381. gphyper->computePredictiveVarianceExact( *example, uncertainty );
  382. break;
  383. }
  384. default:
  385. {
  386. fthrow(Exception, "GPHIKClassifier - your settings disabled the variance approximation needed for uncertainty prediction.");
  387. // uncertainty = numeric_limits<double>::max();
  388. // break;
  389. }
  390. }
  391. }
  392. ///////////////////// INTERFACE PERSISTENT /////////////////////
  393. // interface specific methods for store and restore
  394. ///////////////////// INTERFACE PERSISTENT /////////////////////
  395. void GPHIKClassifier::restore ( std::istream & is, int format )
  396. {
  397. //delete everything we knew so far...
  398. this->clear();
  399. bool b_restoreVerbose ( false );
  400. #ifdef B_RESTOREVERBOSE
  401. b_restoreVerbose = true;
  402. #endif
  403. if ( is.good() )
  404. {
  405. if ( b_restoreVerbose )
  406. std::cerr << " restore GPHIKClassifier" << std::endl;
  407. std::string tmp;
  408. is >> tmp; //class name
  409. if ( ! this->isStartTag( tmp, "GPHIKClassifier" ) )
  410. {
  411. std::cerr << " WARNING - attempt to restore GPHIKClassifier, but start flag " << tmp << " does not match! Aborting... " << std::endl;
  412. throw;
  413. }
  414. if (pf != NULL)
  415. {
  416. delete pf;
  417. pf = NULL;
  418. }
  419. if ( confCopy != NULL )
  420. {
  421. delete confCopy;
  422. confCopy = NULL;
  423. }
  424. if (gphyper != NULL)
  425. {
  426. delete gphyper;
  427. gphyper = NULL;
  428. }
  429. is.precision (numeric_limits<double>::digits10 + 1);
  430. bool b_endOfBlock ( false ) ;
  431. while ( !b_endOfBlock )
  432. {
  433. is >> tmp; // start of block
  434. if ( this->isEndTag( tmp, "GPHIKClassifier" ) )
  435. {
  436. b_endOfBlock = true;
  437. continue;
  438. }
  439. tmp = this->removeStartTag ( tmp );
  440. if ( b_restoreVerbose )
  441. std::cerr << " currently restore section " << tmp << " in GPHIKClassifier" << std::endl;
  442. if ( tmp.compare("confSection") == 0 )
  443. {
  444. is >> confSection;
  445. is >> tmp; // end of block
  446. tmp = this->removeEndTag ( tmp );
  447. }
  448. else if ( tmp.compare("pf") == 0 )
  449. {
  450. is >> tmp; // start of block
  451. if ( this->isEndTag( tmp, "pf" ) )
  452. {
  453. std::cerr << " ParameterizedFunction object can not be restored. Aborting..." << std::endl;
  454. throw;
  455. }
  456. std::string transform = this->removeStartTag ( tmp );
  457. if ( transform == "PFAbsExp" )
  458. {
  459. this->pf = new PFAbsExp ();
  460. } else if ( transform == "PFExp" ) {
  461. this->pf = new PFExp ();
  462. } else {
  463. fthrow(Exception, "Transformation type is unknown " << transform);
  464. }
  465. pf->restore(is, format);
  466. is >> tmp; // end of block
  467. tmp = this->removeEndTag ( tmp );
  468. }
  469. else if ( tmp.compare("ConfigCopy") == 0 )
  470. {
  471. // possibly obsolete safety checks
  472. if ( confCopy == NULL )
  473. confCopy = new Config;
  474. confCopy->clear();
  475. //we do not want to read until the end of the file
  476. confCopy->setIoUntilEndOfFile( false );
  477. //load every options we determined explicitely
  478. confCopy->restore(is, format);
  479. is >> tmp; // end of block
  480. tmp = this->removeEndTag ( tmp );
  481. }
  482. else if ( tmp.compare("gphyper") == 0 )
  483. {
  484. if ( gphyper == NULL )
  485. gphyper = new NICE::FMKGPHyperparameterOptimization();
  486. //then, load everything that we stored explicitely,
  487. // including precomputed matrices, LUTs, eigenvalues, ... and all that stuff
  488. gphyper->restore(is, format);
  489. is >> tmp; // end of block
  490. tmp = this->removeEndTag ( tmp );
  491. }
  492. else
  493. {
  494. std::cerr << "WARNING -- unexpected GPHIKClassifier object -- " << tmp << " -- for restoration... aborting" << std::endl;
  495. throw;
  496. }
  497. }
  498. //load every settings as well as default options
  499. std::cerr << "run this->init" << std::endl;
  500. this->init(confCopy, confSection);
  501. std::cerr << "run gphyper->initialize" << std::endl;
  502. gphyper->initialize ( confCopy, pf, NULL, confSection );
  503. }
  504. else
  505. {
  506. std::cerr << "GPHIKClassifier::restore -- InStream not initialized - restoring not possible!" << std::endl;
  507. throw;
  508. }
  509. }
  510. void GPHIKClassifier::store ( std::ostream & os, int format ) const
  511. {
  512. if (gphyper == NULL)
  513. fthrow(Exception, "Classifier not trained yet -- aborting!" );
  514. if (os.good())
  515. {
  516. // show starting point
  517. os << this->createStartTag( "GPHIKClassifier" ) << std::endl;
  518. os.precision (numeric_limits<double>::digits10 + 1);
  519. os << this->createStartTag( "confSection" ) << std::endl;
  520. os << confSection << std::endl;
  521. os << this->createEndTag( "confSection" ) << std::endl;
  522. os << this->createStartTag( "pf" ) << std::endl;
  523. pf->store(os, format);
  524. os << this->createEndTag( "pf" ) << std::endl;
  525. os << this->createStartTag( "ConfigCopy" ) << std::endl;
  526. //we do not want to read until end of file for restoring
  527. confCopy->setIoUntilEndOfFile(false);
  528. confCopy->store(os,format);
  529. os << this->createEndTag( "ConfigCopy" ) << std::endl;
  530. os << this->createStartTag( "gphyper" ) << std::endl;
  531. //store the underlying data
  532. //will be done in gphyper->store(of,format)
  533. //store the optimized parameter values and all that stuff
  534. gphyper->store(os, format);
  535. os << this->createEndTag( "gphyper" ) << std::endl;
  536. // done
  537. os << this->createEndTag( "GPHIKClassifier" ) << std::endl;
  538. }
  539. else
  540. {
  541. std::cerr << "OutStream not initialized - storing not possible!" << std::endl;
  542. }
  543. }
  544. void GPHIKClassifier::clear ()
  545. {
  546. if ( gphyper != NULL )
  547. {
  548. delete gphyper;
  549. gphyper = NULL;
  550. }
  551. if (pf != NULL)
  552. {
  553. delete pf;
  554. pf = NULL;
  555. }
  556. if ( confCopy != NULL )
  557. {
  558. delete confCopy;
  559. confCopy = NULL;
  560. }
  561. }
  562. ///////////////////// INTERFACE ONLINE LEARNABLE /////////////////////
  563. // interface specific methods for incremental extensions
  564. ///////////////////// INTERFACE ONLINE LEARNABLE /////////////////////
  565. void GPHIKClassifier::addExample( const NICE::SparseVector * example,
  566. const double & label,
  567. const bool & performOptimizationAfterIncrement
  568. )
  569. {
  570. if ( this->gphyper == NULL )
  571. {
  572. //call train method instead
  573. std::cerr << "Classifier not initially trained yet -- run initial training instead of incremental extension!" << std::endl;
  574. std::vector< const NICE::SparseVector *> examplesVec;
  575. examplesVec.push_back ( example );
  576. NICE::Vector labelsVec ( 1 , label );
  577. this->train ( examplesVec, labelsVec );
  578. }
  579. else
  580. {
  581. this->gphyper->addExample( example, label, performOptimizationAfterIncrement );
  582. }
  583. }
  584. void GPHIKClassifier::addMultipleExamples( const std::vector< const NICE::SparseVector * > & newExamples,
  585. const NICE::Vector & newLabels,
  586. const bool & performOptimizationAfterIncrement
  587. )
  588. {
  589. //are new examples available? If not, nothing has to be done
  590. if ( newExamples.size() < 1)
  591. return;
  592. if ( this->gphyper == NULL )
  593. {
  594. //call train method instead
  595. std::cerr << "Classifier not initially trained yet -- run initial training instead of incremental extension!" << std::endl;
  596. this->train ( newExamples, newLabels );
  597. }
  598. else
  599. {
  600. this->gphyper->addMultipleExamples( newExamples, newLabels, performOptimizationAfterIncrement );
  601. }
  602. }