GPHIKRawClassifier.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /**
  2. * @file GPHIKRawClassifier.h
  3. * @brief ..
  4. * @author Erik Rodner
  5. * @date 16-09-2015 (dd-mm-yyyy)
  6. */
  7. #ifndef _NICE_GPHIKRAWCLASSIFIERINCLUDE
  8. #define _NICE_GPHIKRAWCLASSIFIERINCLUDE
  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. #include <core/vector/SparseVectorT.h>
  16. //
  17. namespace NICE {
  18. /**
  19. * @class GPHIKClassifier
  20. * @brief ...
  21. * @author Erik Rodner
  22. */
  23. class GPHIKRawClassifier //: public NICE::Persistent
  24. {
  25. protected:
  26. /////////////////////////
  27. /////////////////////////
  28. // PROTECTED VARIABLES //
  29. /////////////////////////
  30. /////////////////////////
  31. ///////////////////////////////////
  32. // output/debug related settings //
  33. ///////////////////////////////////
  34. /** verbose flag for useful output*/
  35. bool b_verbose;
  36. /** debug flag for several outputs useful for debugging*/
  37. bool b_debug;
  38. //////////////////////////////////////
  39. // general specifications //
  40. //////////////////////////////////////
  41. /** Header in configfile where variable settings are stored */
  42. std::string confSection;
  43. //////////////////////////////////////
  44. // classification related variables //
  45. //////////////////////////////////////
  46. /** memorize whether the classifier was already trained*/
  47. bool b_isTrained;
  48. /** Gaussian label noise for model regularization */
  49. double d_noise;
  50. /////////////////////////
  51. /////////////////////////
  52. // PROTECTED METHODS //
  53. /////////////////////////
  54. /////////////////////////
  55. public:
  56. /**
  57. * @brief default constructor
  58. */
  59. GPHIKRawClassifier( );
  60. /**
  61. * @brief standard constructor
  62. */
  63. GPHIKRawClassifier( const NICE::Config *_conf ,
  64. const std::string & s_confSection = "GPHIKClassifier"
  65. );
  66. /**
  67. * @brief simple destructor
  68. */
  69. ~GPHIKRawClassifier();
  70. /**
  71. * @brief Setup internal variables and objects used
  72. * @param conf Config file to specify variable settings
  73. * @param s_confSection
  74. */
  75. void initFromConfig(const NICE::Config *_conf,
  76. const std::string & s_confSection
  77. );
  78. ///////////////////// ///////////////////// /////////////////////
  79. // GET / SET
  80. ///////////////////// ///////////////////// /////////////////////
  81. /**
  82. * @brief Return currently known class numbers
  83. */
  84. std::set<uint> getKnownClassNumbers ( ) const;
  85. ///////////////////// ///////////////////// /////////////////////
  86. // CLASSIFIER STUFF
  87. ///////////////////// ///////////////////// /////////////////////
  88. /**
  89. * @brief classify a given example with the previously learned model
  90. * @author Alexander Freytag, Erik Rodner
  91. * @param example (SparseVector) to be classified given in a sparse representation
  92. * @param result (int) class number of most likely class
  93. * @param scores (SparseVector) classification scores for known classes
  94. */
  95. void classify ( const NICE::SparseVector * _example,
  96. uint & _result,
  97. NICE::SparseVector & _scores
  98. ) const;
  99. /**
  100. * @brief classify a given example with the previously learnt model
  101. * NOTE: whenever possible, you should the sparse version to obtain significantly smaller computation times*
  102. * @author Alexander Freytag, Erik Rodner
  103. * @param example (non-sparse Vector) to be classified given in a non-sparse representation
  104. * @param result (int) class number of most likely class
  105. * @param scores (SparseVector) classification scores for known classes
  106. */
  107. void classify ( const NICE::Vector * _example,
  108. uint & _result,
  109. NICE::SparseVector & _scores
  110. ) const;
  111. /**
  112. * @brief train this classifier using a given set of examples and a given set of binary label vectors
  113. * @date 18-10-2012 (dd-mm-yyyy)
  114. * @author Alexander Freytag, Erik Rodner
  115. * @param examples (std::vector< NICE::SparseVector *>) training data given in a sparse representation
  116. * @param labels (Vector) class labels (multi-class)
  117. */
  118. void train ( const std::vector< const NICE::SparseVector *> & _examples,
  119. const NICE::Vector & _labels
  120. );
  121. /**
  122. * @brief train this classifier using a given set of examples and a given set of binary label vectors
  123. * @author Alexander Freytag, Erik Rodner
  124. * @param examples examples to use given in a sparse data structure
  125. * @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)
  126. */
  127. void train ( const std::vector< const NICE::SparseVector *> & _examples,
  128. std::map<uint, NICE::Vector> & _binLabels
  129. );
  130. };
  131. }
  132. #endif