SparseVectorFeature.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * @file SparseVectorFeature.h
  3. * @brief feature class to use in Examples stored sparse features
  4. * @author Björn Fröhlich
  5. * @date 05/25/2009
  6. */
  7. #ifndef SparseVectorFeatureINCLUDE
  8. #define SparseVectorFeatureINCLUDE
  9. #include <vislearning/nice.h>
  10. #include "core/basics/Config.h"
  11. #include "vislearning/cbaselib/Feature.h"
  12. #include "core/vector/SparseVector.h"
  13. namespace OBJREC {
  14. class SparseVectorFeature : public Feature
  15. {
  16. protected:
  17. //! feature dimension
  18. int dimension;
  19. //! index of the feature
  20. int feature_index;
  21. public:
  22. /**
  23. * internally used by SparseVectorFeature::explode
  24. * @param _dimension new dimension
  25. * @param _feature_index new featureindex
  26. */
  27. SparseVectorFeature ( int _dimension, int _feature_index = 0 ) { dimension = _dimension; feature_index = _feature_index; };
  28. /**
  29. * simple destructor
  30. */
  31. virtual ~SparseVectorFeature();
  32. /**
  33. * returns the value of the sparse feature stored in example
  34. * @param example input example
  35. * @return feature value
  36. */
  37. double val( const Example *example ) const;
  38. /**
  39. * creates for each feature a own SparseVectorFeature in featurepool
  40. * @param featurePool the feature pool
  41. * @param variableWindow
  42. */
  43. void explode ( FeaturePool & featurePool, bool variableWindow = true ) const;
  44. Feature *clone() const;
  45. Feature *generateFirstParameter () const;
  46. /**
  47. * store the data
  48. * @param is input stream
  49. * @param format
  50. */
  51. void restore (std::istream & is, int format = 0);
  52. /**
  53. * read the data
  54. * @param os
  55. * @param format
  56. */
  57. void store (std::ostream & os, int format = 0) const;
  58. /**
  59. * does nothing
  60. */
  61. void clear ();
  62. /**
  63. * returns the feature index and the dimension
  64. * @param feature_index
  65. * @param dimension
  66. */
  67. void getStump ( int & feature_index, int & dimension ) const;
  68. };
  69. } // namespace
  70. #endif