SLR.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /**
  2. * @file SLR.h
  3. * @brief implementation of Sparse Logistic Regression (SMLR) Classififier (one vs. all)
  4. * @author Björn Fröhlich
  5. * @date 06/23/2009
  6. */
  7. #ifndef SLRDEF
  8. #define SLRDEF
  9. #include "core/vector/VectorT.h"
  10. #include "core/vector/MatrixT.h"
  11. #include "core/image/ImageT.h"
  12. #include "core/imagedisplay/ImageDisplay.h"
  13. #include "vislearning/classifier/classifierbase/FeaturePoolClassifier.h"
  14. #include "vislearning/cbaselib/FeaturePool.h"
  15. #include "core/algebra/GMSparseVectorMatrix.h"
  16. namespace OBJREC {
  17. class SLR : public NICE::Persistent
  18. {
  19. //protected:
  20. public:
  21. //! the configuration file
  22. const NICE::Config *conf;
  23. //! section in the configfile
  24. std::string confsection;
  25. //! weight vectors
  26. NICE::SparseVector weight;
  27. //! the featurepool
  28. FeaturePool fp;
  29. //! maximum number of iterations
  30. int maxiter;
  31. //! Decay rate in the probability of resampling a zero weight.1.0 will immediately decrease to the min_resamp from 1.0, 0.0 will never decrease from 1.0.
  32. double resamp_decay;
  33. //! convergence criterium for stepwise regression
  34. double convergence_tol;
  35. //! Minimum resampling probability for zeroed weights"
  36. double min_resamp;
  37. //! Feature Dimension
  38. int fdim;
  39. //! The penalty term lambda. Larger values will give rise to more sparsification
  40. double lambda;
  41. //! how many samples per class should be used
  42. double samplesperclass;
  43. //! for normalization
  44. std::vector<double> minval, maxval;
  45. public:
  46. /**
  47. * standard constructor
  48. * @param conf configfile
  49. * @param section section name in configfile for classifier
  50. */
  51. SLR ( const NICE::Config *conf, std::string section = "SMLR" );
  52. /**
  53. * simple constructor -> does nothing
  54. */
  55. SLR ();
  56. /**
  57. * simple destructor
  58. */
  59. ~SLR();
  60. /**
  61. * main classification function
  62. * @param pce input feature
  63. * @return a classification result
  64. */
  65. double classify ( Example & pce );
  66. /**
  67. * start training
  68. * @param fp a featurepool (how to handle which features...)
  69. * @param classno which class should be learned
  70. * @param examples input features
  71. */
  72. void train ( FeaturePool & _fp, Examples & examples, int classno = 1 );
  73. /**
  74. * clone this object
  75. * @return a copy of this object
  76. */
  77. FeaturePoolClassifier *clone () const;
  78. /**
  79. * perform the stepwise regression
  80. * @param x input features
  81. * @param classno which class should be learned
  82. * @return number of iterations
  83. */
  84. int stepwise_regression ( Examples &x, int classno = 1 );
  85. /** IO functions */
  86. void restore ( std::istream & is, int format = 0 );
  87. void store ( std::ostream & os, int format = 0 ) const;
  88. void clear ();
  89. };
  90. } // namespace
  91. #endif