GPHIKRawClassifier.h 5.0 KB

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