SparseVectorFeature.cpp 1.3 KB

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