GPHIKClassifier.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. * @file GPHIKClassifier.h
  3. * @author Erik Rodner, Alexander Freytag
  4. * @brief Main interface for our GP HIK classifier (similar to the feature pool classifier interface in vislearning) (Interface)
  5. * @date 02/01/2012
  6. */
  7. #ifndef _NICE_GPHIKCLASSIFIERINCLUDE
  8. #define _NICE_GPHIKCLASSIFIERINCLUDE
  9. #include <string>
  10. #include <limits>
  11. #include <core/basics/Config.h>
  12. #include <core/vector/SparseVectorT.h>
  13. #include "FMKGPHyperparameterOptimization.h"
  14. #include "gp-hik-core/parameterizedFunctions/ParameterizedFunction.h"
  15. namespace NICE {
  16. /**
  17. * @class GPHIKClassifier
  18. * @brief Main interface for our GP HIK classifier (similar to the feature pool classifier interface in vislearning)
  19. * @author Erik Rodner, Alexander Freytag
  20. */
  21. class GPHIKClassifier
  22. {
  23. protected:
  24. std::string confSection;
  25. double noise;
  26. enum VarianceApproximation{
  27. APPROXIMATE_ROUGH,
  28. APPROXIMATE_FINE,
  29. EXACT,
  30. NONE
  31. };
  32. VarianceApproximation varianceApproximation;
  33. /**compute the uncertainty prediction during classification?*/
  34. bool uncertaintyPredictionForClassification;
  35. NICE::Config *confCopy;
  36. NICE::ParameterizedFunction *pf;
  37. NICE::FMKGPHyperparameterOptimization *gphyper;
  38. /** verbose flag for useful output*/
  39. bool verbose;
  40. /** debug flag for several outputs useful for debugging*/
  41. bool debug;
  42. /**
  43. * @brief classify a given example with the previously learnt model
  44. * @param pe example to be classified given in a sparse representation
  45. */
  46. void init(const NICE::Config *conf, const std::string & confSection);
  47. public:
  48. /** simple constructor */
  49. GPHIKClassifier( const NICE::Config *conf, const std::string & confSection = "GPHIKClassifier" );
  50. /** simple destructor */
  51. ~GPHIKClassifier();
  52. /**
  53. * @brief classify a given example with the previously learnt model
  54. * @date 19-06-2012 (dd-mm-yyyy)
  55. * @author Alexander Freytag
  56. * @param example (SparseVector) to be classified given in a sparse representation
  57. * @param result (int) class number of most likely class
  58. * @param scores (SparseVector) classification scores for known classes
  59. */
  60. void classify ( const NICE::SparseVector * example, int & result, NICE::SparseVector & scores );
  61. /**
  62. * @brief classify a given example with the previously learnt model
  63. * @date 19-06-2012 (dd-mm-yyyy)
  64. * @author Alexander Freytag
  65. * @param example (SparseVector) to be classified given in a sparse representation
  66. * @param result (int) class number of most likely class
  67. * @param scores (SparseVector) classification scores for known classes
  68. * @param uncertainty (double*) predictive variance of the classification result, if computed
  69. */
  70. void classify ( const NICE::SparseVector * example, int & result, NICE::SparseVector & scores, double & uncertainty );
  71. /**
  72. * @brief train this classifier using a given set of examples and a given set of binary label vectors
  73. * @date 18-10-2012 (dd-mm-yyyy)
  74. * @author Alexander Freytag
  75. * @param examples (std::vector< NICE::SparseVector *>) training data given in a sparse representation
  76. * @param labels (Vector) class labels (multi-class)
  77. */
  78. void train ( const std::vector< NICE::SparseVector *> & examples, const NICE::Vector & labels );
  79. /**
  80. * @brief train this classifier using a given set of examples and a given set of binary label vectors
  81. * @date 19-06-2012 (dd-mm-yyyy)
  82. * @author Alexander Freytag
  83. * @param examples examples to use given in a sparse data structure
  84. * @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)
  85. */
  86. void train ( const std::vector< NICE::SparseVector *> & examples, std::map<int, NICE::Vector> & binLabels );
  87. /** Persistent interface */
  88. void restore ( std::istream & is, int format = 0 );
  89. void store ( std::ostream & os, int format = 0 ) const;
  90. void clear ();
  91. GPHIKClassifier *clone () const;
  92. /**
  93. * @brief prediction of classification uncertainty
  94. * @date 19-06-2012 (dd-mm-yyyy)
  95. * @author Alexander Freytag
  96. * @param examples example for which the classification uncertainty shall be predicted, given in a sparse representation
  97. * @param uncertainties contains the resulting classification uncertainties (1 entry for standard setting, m entries for binary-balanced setting)
  98. */
  99. void predictUncertainty( const NICE::SparseVector * example, NICE::Vector & uncertainties );
  100. void addExample( const NICE::SparseVector * example, const double & label, const bool & performOptimizationAfterIncrement = true);
  101. void addMultipleExamples( const std::vector< const NICE::SparseVector * > & newExamples, const NICE::Vector & newLabels, const bool & performOptimizationAfterIncrement = true);
  102. };
  103. }
  104. #endif