FullVector.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * @file FullVector.h
  3. * @brief non sparse vector
  4. * @author Erik Rodner
  5. * @date 05/11/2008
  6. */
  7. #ifndef FullVectorINCLUDE
  8. #define FullVectorINCLUDE
  9. #include <vector>
  10. #include <map>
  11. #include <iostream>
  12. #include "core/basics/Persistent.h"
  13. namespace OBJREC {
  14. /** non sparse vector */
  15. class FullVector : public NICE::Persistent
  16. {
  17. protected:
  18. public:
  19. double *data;
  20. int length;
  21. FullVector ( const std::map<int, double> & mymap );
  22. FullVector ( const std::map<short, double> & mymap );
  23. /**
  24. * Creates a vector with specified size (values will be randomized initialized)
  25. * @param length
  26. */
  27. FullVector ( int length );
  28. FullVector ();
  29. FullVector ( const FullVector & v );
  30. ~FullVector ();
  31. void set ( double val );
  32. void add ( const FullVector & v );
  33. void add ( const FullVector & v, double lambda );
  34. void add ( double beta );
  35. void addMap ( const std::map<int, int> & v, double lambda = 1.0 );
  36. void addMap ( const std::map<int, double> & v, double lambda = 1.0 );
  37. void normalize ();
  38. void reinit ( int length );
  39. void restore ( std::istream & is, int format = 0 );
  40. void store ( std::ostream & os, int format = 0 ) const;
  41. void clear ();
  42. double entropy () const;
  43. void multiply ( const FullVector & v );
  44. void multiply ( double val );
  45. void divide ( const FullVector & v );
  46. double sum () const;
  47. double max () const;
  48. double min () const;
  49. int maxElement () const;
  50. int maxElementExclusive ( int key ) const;
  51. void getSortedIndices ( std::vector<int> & indizes ) const;
  52. double get ( size_t i ) const;
  53. inline int size() const {
  54. return length;
  55. };
  56. inline bool empty() {
  57. return length == 0;
  58. };
  59. double & operator[] ( int i );
  60. void operator= ( const FullVector & v );
  61. const double & operator[] ( int i ) const;
  62. };
  63. } // namespace
  64. #endif