SparseVectorFeature.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <vislearning/nice.h>
  2. #include <iostream>
  3. #include "SparseVectorFeature.h"
  4. #include "vislearning/cbaselib/FeaturePool.h"
  5. using namespace OBJREC;
  6. using namespace std;
  7. // refactor-nice.pl: check this substitution
  8. // old: using namespace ice;
  9. using namespace NICE;
  10. /** simple destructor */
  11. SparseVectorFeature::~SparseVectorFeature()
  12. {
  13. }
  14. double SparseVectorFeature::val( const Example *example ) const
  15. {
  16. return example->svec->get(feature_index);
  17. }
  18. void SparseVectorFeature::explode ( FeaturePool & featurePool, bool variableWindow ) const
  19. {
  20. for ( int i = 0 ; i < dimension ; i++ )
  21. {
  22. SparseVectorFeature *f = new SparseVectorFeature ( dimension );
  23. f->feature_index = i;
  24. featurePool.addFeature(f, 1.0 / dimension);
  25. }
  26. }
  27. Feature *SparseVectorFeature::clone() const
  28. {
  29. SparseVectorFeature *f = new SparseVectorFeature( dimension );
  30. f->feature_index = feature_index;
  31. return f;
  32. }
  33. Feature *SparseVectorFeature::generateFirstParameter () const
  34. {
  35. return clone();
  36. }
  37. void SparseVectorFeature::restore (istream & is, int format)
  38. {
  39. is >> feature_index;
  40. }
  41. void SparseVectorFeature::store (ostream & os, int format) const
  42. {
  43. os << "SVECTORFEATURE "
  44. << feature_index;
  45. }
  46. void SparseVectorFeature::clear ()
  47. {
  48. }
  49. void SparseVectorFeature::getStump ( int & _feature_index, int & _dimension ) const
  50. {
  51. _feature_index = feature_index;
  52. _dimension = dimension;
  53. }