FPCGPHIK.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * @file FPCGPHIK.h
  3. * @author Alexander Freytag, Erik Rodner
  4. * @date 02/01/2012
  5. */
  6. #ifndef _NICE_FPCGPHIKCLASSIFIERNICEINCLUDE
  7. #define _NICE_FPCGPHIKCLASSIFIERNICEINCLUDE
  8. // STL includes
  9. #include <string>
  10. // NICE-core includes
  11. #include <core/basics/Config.h>
  12. // NICE-gp-hik-core includes
  13. #include <gp-hik-core/GPHIKClassifier.h>
  14. #include <gp-hik-core/FMKGPHyperparameterOptimization.h>
  15. #include <gp-hik-core/parameterizedFunctions/ParameterizedFunction.h>
  16. // NICE-vislearning includes
  17. #include "vislearning/classifier/classifierbase/FeaturePoolClassifier.h"
  18. namespace OBJREC {
  19. /** @class FPCGPHIK
  20. * Wrapper class (feature pool interface) for our GP HIK classifier
  21. *
  22. * @author Alexander Freytag, Erik Rodner
  23. */
  24. class FPCGPHIK : 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. FPCGPHIK( const NICE::Config *conf, const std::string & confSection = "GPHIKClassifier" );
  38. /** simple destructor */
  39. virtual ~FPCGPHIK();
  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. /** prediction of classification uncertainty */
  70. void predictUncertainty( OBJREC::Example & pe, double & uncertainty );
  71. /**
  72. * @brief prediction of classification uncertainty
  73. * @date 19-06-2012 (dd-mm-yyyy)
  74. * @author Alexander Freytag
  75. * @param examples example for which the classification uncertainty shall be predicted, given in a sparse representation
  76. * @param uncertainties contains the resulting classification uncertainties (1 entry for standard setting, m entries for binary-balanced setting)
  77. */
  78. void predictUncertainty( const NICE::SparseVector * example, double & uncertainty );
  79. ///////////////////// INTERFACE ONLINE LEARNABLE (SIMILAR) /////////////////////
  80. // interface specific methods for incremental extensions
  81. ///////////////////// INTERFACE ONLINE LEARNABLE (SIMILAR) /////////////////////
  82. void addExample( const OBJREC::Example & pe, const double & label);
  83. virtual void addMultipleExamples( OBJREC::Examples & newExamples);
  84. };
  85. }
  86. #endif