GPHIKClassifierNICE.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**
  2. * @file GPHIKClassifierNICE.h
  3. * @author Alexander Freytag, Erik Rodner
  4. * @date 02/01/2012
  5. */
  6. #ifndef _NICE_GPHIKCLASSIFIERNICEINCLUDE
  7. #define _NICE_GPHIKCLASSIFIERNICEINCLUDE
  8. // STL includes
  9. #include <string>
  10. // NICE-core includes
  11. #include <core/basics/Config.h>
  12. // NICE-vislearning includes
  13. #include <vislearning/classifier/classifierbase/FeaturePoolClassifier.h>
  14. // NICE-gp-hik-core includes
  15. #include <gp-hik-core/GPHIKClassifier.h>
  16. #include <gp-hik-core/FMKGPHyperparameterOptimization.h>
  17. #include <gp-hik-core/parameterizedFunctions/ParameterizedFunction.h>
  18. namespace OBJREC {
  19. /** @class GPHIKClassifierNICE
  20. * Wrapper class (feature pool interface) for our GP HIK classifier
  21. *
  22. * @author Alexander Freytag, Erik Rodner
  23. */
  24. class GPHIKClassifierNICE : public FeaturePoolClassifier
  25. {
  26. protected:
  27. /////////////////////////
  28. /////////////////////////
  29. // PROTECTED VARIABLES //
  30. /////////////////////////
  31. /////////////////////////
  32. NICE::GPHIKClassifier * classifier;
  33. /** verbose flag for useful output*/
  34. bool verbose;
  35. /** a simple balancing strategy: use only that many examples of each class, as the smallest class provides*/
  36. bool useSimpleBalancing;
  37. int minSamples;
  38. /** When adding new examples, do we want to run a whole optimization of all involved hyperparameters? default: true*/
  39. bool performOptimizationAfterIncrement;
  40. /////////////////////////
  41. /////////////////////////
  42. // PROTECTED METHODS //
  43. /////////////////////////
  44. /////////////////////////
  45. /**
  46. * @brief Setup internal variables and objects used
  47. * @author Alexander Freytag
  48. * @param conf Config file to specify variable settings
  49. * @param s_confSection
  50. */
  51. void init ( const NICE::Config *conf, const std::string & s_confSection = "GPHIKClassifier" );
  52. public:
  53. /** simple constructor */
  54. GPHIKClassifierNICE( );
  55. /** default constructor */
  56. GPHIKClassifierNICE( const NICE::Config *conf, const std::string & confSection = "GPHIKClassifier" );
  57. /** simple destructor */
  58. virtual ~GPHIKClassifierNICE();
  59. /**
  60. * @brief classify a given example with the previously learnt model
  61. * @param pe example to be classified given in a sparse representation
  62. */
  63. virtual ClassificationResult classify ( OBJREC::Example & pe );
  64. /**
  65. * @brief classify a given example with the previously learnt model
  66. * @date 19-06-2012 (dd-mm-yyyy)
  67. * @author Alexander Freytag
  68. * @param examples example to be classified given in a sparse representation
  69. */
  70. ClassificationResult classify ( const NICE::SparseVector * example );
  71. /** training process */
  72. virtual void train ( OBJREC::FeaturePool & fp, OBJREC::Examples & examples );
  73. /**
  74. * @brief train this classifier using a given set of examples and a given set of binary label vectors
  75. * @date 19-06-2012 (dd-mm-yyyy)
  76. * @author Alexander Freytag
  77. * @param examples examples to use given in a sparse data structure
  78. * @param binLabels corresponding binary labels with class no. There is no need here that every examples has only on positive entry in this set (1,-1)
  79. */
  80. void train ( const std::vector< const NICE::SparseVector *> & examples, std::map<int, NICE::Vector> & binLabels );
  81. ///////////////////// INTERFACE PERSISTENT /////////////////////
  82. // interface specific methods for store and restore
  83. ///////////////////// INTERFACE PERSISTENT /////////////////////
  84. virtual void restore ( std::istream & is, int format = 0 );
  85. virtual void store ( std::ostream & os, int format = 0 ) const;
  86. virtual void clear ();
  87. virtual FeaturePoolClassifier *clone () const;
  88. /**
  89. * @brief prediction of classification uncertainty
  90. * @date 19-06-2012 (dd-mm-yyyy)
  91. * @author Alexander Freytag
  92. * @param examples example for which the classification uncertainty shall be predicted, given in a sparse representation
  93. * @param uncertainty contains the resulting classification uncertainty
  94. */
  95. void predictUncertainty( OBJREC::Example & pe, double & uncertainty );
  96. /**
  97. * @brief prediction of classification uncertainty
  98. * @date 19-06-2012 (dd-mm-yyyy)
  99. * @author Alexander Freytag
  100. * @param examples example for which the classification uncertainty shall be predicted, given in a sparse representation
  101. * @param uncertainty contains the resulting classification uncertainty
  102. */
  103. void predictUncertainty( const NICE::SparseVector * example, double & uncertainty );
  104. ///////////////////// INTERFACE ONLINE LEARNABLE (SIMILAR) /////////////////////
  105. // interface specific methods for incremental extensions
  106. ///////////////////// INTERFACE ONLINE LEARNABLE (SIMILAR) /////////////////////
  107. void addExample( const OBJREC::Example & pe, const double & label);
  108. virtual void addMultipleExamples( OBJREC::Examples & newExamples);
  109. };
  110. }
  111. #endif