SLR.h 2.7 KB

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