GPHIKRawClassifier.h 5.3 KB

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