SLR.h 2.5 KB

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