GPHIKClassifier.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. // STL includes
  10. #include <string>
  11. #include <limits>
  12. // NICE-core includes
  13. #include <core/basics/Config.h>
  14. #include <core/basics/Persistent.h>
  15. //
  16. #include <core/vector/SparseVectorT.h>
  17. // gp-hik-core includes
  18. #include "FMKGPHyperparameterOptimization.h"
  19. #include "gp-hik-core/parameterizedFunctions/ParameterizedFunction.h"
  20. namespace NICE {
  21. /**
  22. * @class GPHIKClassifier
  23. * @brief Main interface for our GP HIK classifier (similar to the feature pool classifier interface in vislearning)
  24. * @author Erik Rodner, Alexander Freytag
  25. */
  26. class GPHIKClassifier : NICE::Persistent
  27. {
  28. protected:
  29. std::string confSection;
  30. double noise;
  31. enum VarianceApproximation{
  32. APPROXIMATE_ROUGH,
  33. APPROXIMATE_FINE,
  34. EXACT,
  35. NONE
  36. };
  37. VarianceApproximation varianceApproximation;
  38. /**compute the uncertainty prediction during classification?*/
  39. bool uncertaintyPredictionForClassification;
  40. NICE::Config *confCopy;
  41. NICE::ParameterizedFunction *pf;
  42. NICE::FMKGPHyperparameterOptimization *gphyper;
  43. /** verbose flag for useful output*/
  44. bool verbose;
  45. /** debug flag for several outputs useful for debugging*/
  46. bool debug;
  47. /**
  48. * @brief classify a given example with the previously learnt model
  49. * @param pe example to be classified given in a sparse representation
  50. */
  51. void init(const NICE::Config *conf, const std::string & s_confSection);
  52. public:
  53. /** simple constructor */
  54. GPHIKClassifier( const NICE::Config *conf = NULL, const std::string & s_confSection = "GPHIKClassifier" );
  55. /** simple destructor */
  56. ~GPHIKClassifier();
  57. /**
  58. * @brief classify a given example with the previously learnt model
  59. * @date 19-06-2012 (dd-mm-yyyy)
  60. * @author Alexander Freytag
  61. * @param example (SparseVector) to be classified given in a sparse representation
  62. * @param result (int) class number of most likely class
  63. * @param scores (SparseVector) classification scores for known classes
  64. */
  65. void classify ( const NICE::SparseVector * example, int & result, NICE::SparseVector & scores );
  66. /**
  67. * @brief classify a given example with the previously learnt model
  68. * @date 19-06-2012 (dd-mm-yyyy)
  69. * @author Alexander Freytag
  70. * @param example (SparseVector) to be classified given in a sparse representation
  71. * @param result (int) class number of most likely class
  72. * @param scores (SparseVector) classification scores for known classes
  73. * @param uncertainty (double*) predictive variance of the classification result, if computed
  74. */
  75. void classify ( const NICE::SparseVector * example, int & result, NICE::SparseVector & scores, double & uncertainty );
  76. /**
  77. * @brief classify a given example with the previously learnt model
  78. * NOTE: whenever possible, you should the sparse version to obtain significantly smaller computation times*
  79. * @date 18-06-2013 (dd-mm-yyyy)
  80. * @author Alexander Freytag
  81. * @param example (non-sparse Vector) to be classified given in a non-sparse representation
  82. * @param result (int) class number of most likely class
  83. * @param scores (SparseVector) classification scores for known classes
  84. */
  85. void classify ( const NICE::Vector * example, int & result, NICE::SparseVector & scores );
  86. /**
  87. * @brief classify a given example with the previously learnt model
  88. * NOTE: whenever possible, you should the sparse version to obtain significantly smaller computation times
  89. * @date 18-06-2013 (dd-mm-yyyy)
  90. * @author Alexander Freytag
  91. * @param example (non-sparse Vector) to be classified given in a non-sparse representation
  92. * @param result (int) class number of most likely class
  93. * @param scores (SparseVector) classification scores for known classes
  94. * @param uncertainty (double) predictive variance of the classification result, if computed
  95. */
  96. void classify ( const NICE::Vector * example, int & result, NICE::SparseVector & scores, double & uncertainty );
  97. /**
  98. * @brief train this classifier using a given set of examples and a given set of binary label vectors
  99. * @date 18-10-2012 (dd-mm-yyyy)
  100. * @author Alexander Freytag
  101. * @param examples (std::vector< NICE::SparseVector *>) training data given in a sparse representation
  102. * @param labels (Vector) class labels (multi-class)
  103. */
  104. void train ( const std::vector< NICE::SparseVector *> & examples, const NICE::Vector & labels );
  105. /**
  106. * @brief train this classifier using a given set of examples and a given set of binary label vectors
  107. * @date 19-06-2012 (dd-mm-yyyy)
  108. * @author Alexander Freytag
  109. * @param examples examples to use given in a sparse data structure
  110. * @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)
  111. */
  112. void train ( const std::vector< NICE::SparseVector *> & examples, std::map<int, NICE::Vector> & binLabels );
  113. /** Persistent interface */
  114. void restore ( std::istream & is, int format = 0 );
  115. void store ( std::ostream & os, int format = 0 ) const;
  116. void clear ();
  117. GPHIKClassifier *clone () const;
  118. /**
  119. * @brief prediction of classification uncertainty
  120. * @date 19-06-2012 (dd-mm-yyyy)
  121. * @author Alexander Freytag
  122. * @param examples example for which the classification uncertainty shall be predicted, given in a sparse representation
  123. * @param uncertainty contains the resulting classification uncertainty
  124. */
  125. void predictUncertainty( const NICE::SparseVector * example, double & uncertainty );
  126. /**
  127. * @brief prediction of classification uncertainty
  128. * @date 19-12-2013 (dd-mm-yyyy)
  129. * @author Alexander Freytag
  130. * @param examples example for which the classification uncertainty shall be predicted, given in a non-sparse representation
  131. * @param uncertainty contains the resulting classification uncertainty
  132. */
  133. void predictUncertainty( const NICE::Vector * example, double & uncertainty );
  134. std::set<int> getKnownClassNumbers ( ) const;
  135. };
  136. }
  137. #endif