GPHIKClassifier.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 classify a given example with the previously learnt model
  73. * NOTE: whenever possible, you should the sparse version to obtain significantly smaller computation times*
  74. * @date 18-06-2013 (dd-mm-yyyy)
  75. * @author Alexander Freytag
  76. * @param example (non-sparse Vector) to be classified given in a non-sparse representation
  77. * @param result (int) class number of most likely class
  78. * @param scores (SparseVector) classification scores for known classes
  79. */
  80. void classify ( const NICE::Vector * example, int & result, NICE::SparseVector & scores );
  81. /**
  82. * @brief classify a given example with the previously learnt model
  83. * NOTE: whenever possible, you should the sparse version to obtain significantly smaller computation times
  84. * @date 18-06-2013 (dd-mm-yyyy)
  85. * @author Alexander Freytag
  86. * @param example (non-sparse Vector) to be classified given in a non-sparse representation
  87. * @param result (int) class number of most likely class
  88. * @param scores (SparseVector) classification scores for known classes
  89. * @param uncertainty (double*) predictive variance of the classification result, if computed
  90. */
  91. void classify ( const NICE::Vector * example, int & result, NICE::SparseVector & scores, double & uncertainty );
  92. /**
  93. * @brief train this classifier using a given set of examples and a given set of binary label vectors
  94. * @date 18-10-2012 (dd-mm-yyyy)
  95. * @author Alexander Freytag
  96. * @param examples (std::vector< NICE::SparseVector *>) training data given in a sparse representation
  97. * @param labels (Vector) class labels (multi-class)
  98. */
  99. void train ( const std::vector< NICE::SparseVector *> & examples, const NICE::Vector & labels );
  100. /**
  101. * @brief train this classifier using a given set of examples and a given set of binary label vectors
  102. * @date 19-06-2012 (dd-mm-yyyy)
  103. * @author Alexander Freytag
  104. * @param examples examples to use given in a sparse data structure
  105. * @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)
  106. */
  107. void train ( const std::vector< NICE::SparseVector *> & examples, std::map<int, NICE::Vector> & binLabels );
  108. /** Persistent interface */
  109. void restore ( std::istream & is, int format = 0 );
  110. void store ( std::ostream & os, int format = 0 ) const;
  111. void clear ();
  112. GPHIKClassifier *clone () const;
  113. /**
  114. * @brief prediction of classification uncertainty
  115. * @date 19-06-2012 (dd-mm-yyyy)
  116. * @author Alexander Freytag
  117. * @param examples example for which the classification uncertainty shall be predicted, given in a sparse representation
  118. * @param uncertainties contains the resulting classification uncertainties (1 entry for standard setting, m entries for binary-balanced setting)
  119. */
  120. void predictUncertainty( const NICE::SparseVector * example, NICE::Vector & uncertainties );
  121. void addExample( const NICE::SparseVector * example, const double & label, const bool & performOptimizationAfterIncrement = true);
  122. void addMultipleExamples( const std::vector< const NICE::SparseVector * > & newExamples, const NICE::Vector & newLabels, const bool & performOptimizationAfterIncrement = true);
  123. };
  124. }
  125. #endif