GPHIKRawClassifier.h 5.0 KB

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