GPHIKClassifierNICE.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. NICE::GPHIKClassifier * classifier;
  28. /** verbose flag for useful output*/
  29. bool verbose;
  30. /** a simple balancing strategy: use only that many examples of each class, as the smallest class provides*/
  31. bool useSimpleBalancing;
  32. int minSamples;
  33. /** When adding new examples, do we want to run a whole optimization of all involved hyperparameters? default: true*/
  34. bool performOptimizationAfterIncrement;
  35. public:
  36. /** simple constructor */
  37. GPHIKClassifierNICE( const NICE::Config *conf, const std::string & confSection = "GPHIKClassifier" );
  38. /** simple destructor */
  39. virtual ~GPHIKClassifierNICE();
  40. /**
  41. * @brief classify a given example with the previously learnt model
  42. * @param pe example to be classified given in a sparse representation
  43. */
  44. virtual ClassificationResult classify ( OBJREC::Example & pe );
  45. /**
  46. * @brief classify a given example with the previously learnt model
  47. * @date 19-06-2012 (dd-mm-yyyy)
  48. * @author Alexander Freytag
  49. * @param examples example to be classified given in a sparse representation
  50. */
  51. ClassificationResult classify ( const NICE::SparseVector * example );
  52. /** training process */
  53. virtual void train ( OBJREC::FeaturePool & fp, OBJREC::Examples & examples );
  54. /**
  55. * @brief train this classifier using a given set of examples and a given set of binary label vectors
  56. * @date 19-06-2012 (dd-mm-yyyy)
  57. * @author Alexander Freytag
  58. * @param examples examples to use given in a sparse data structure
  59. * @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)
  60. */
  61. void train ( const std::vector< const NICE::SparseVector *> & examples, std::map<int, NICE::Vector> & binLabels );
  62. ///////////////////// INTERFACE PERSISTENT /////////////////////
  63. // interface specific methods for store and restore
  64. ///////////////////// INTERFACE PERSISTENT /////////////////////
  65. virtual void restore ( std::istream & is, int format = 0 );
  66. virtual void store ( std::ostream & os, int format = 0 ) const;
  67. virtual void clear ();
  68. virtual FeaturePoolClassifier *clone () const;
  69. /**
  70. * @brief prediction of classification uncertainty
  71. * @date 19-06-2012 (dd-mm-yyyy)
  72. * @author Alexander Freytag
  73. * @param examples example for which the classification uncertainty shall be predicted, given in a sparse representation
  74. * @param uncertainty contains the resulting classification uncertainty
  75. */
  76. void predictUncertainty( OBJREC::Example & pe, double & uncertainty );
  77. /**
  78. * @brief prediction of classification uncertainty
  79. * @date 19-06-2012 (dd-mm-yyyy)
  80. * @author Alexander Freytag
  81. * @param examples example for which the classification uncertainty shall be predicted, given in a sparse representation
  82. * @param uncertainty contains the resulting classification uncertainty
  83. */
  84. void predictUncertainty( const NICE::SparseVector * example, double & uncertainty );
  85. ///////////////////// INTERFACE ONLINE LEARNABLE (SIMILAR) /////////////////////
  86. // interface specific methods for incremental extensions
  87. ///////////////////// INTERFACE ONLINE LEARNABLE (SIMILAR) /////////////////////
  88. void addExample( const OBJREC::Example & pe, const double & label);
  89. virtual void addMultipleExamples( OBJREC::Examples & newExamples);
  90. };
  91. }
  92. #endif