GMHIKernelRaw.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * @file GMHIKernelRaw.h
  3. * @author Erik Rodner, Alexander Freytag
  4. * @brief Fast multiplication with histogram intersection kernel matrices (Interface)
  5. */
  6. #ifndef _NICE_GMHIKERNELRAWINCLUDE
  7. #define _NICE_GMHIKERNELRAWINCLUDE
  8. #include <vector>
  9. #include <core/algebra/GenericMatrix.h>
  10. namespace NICE {
  11. /**
  12. * @class GMHIKernel
  13. * @brief Fast multiplication with histogram intersection kernel matrices
  14. * @author Erik Rodner, Alexander Freytag
  15. */
  16. class GMHIKernelRaw : public GenericMatrix
  17. {
  18. public:
  19. typedef struct sparseVectorElement {
  20. uint example_index;
  21. double value;
  22. bool operator< (const sparseVectorElement & a) const
  23. {
  24. return value < a.value;
  25. }
  26. } sparseVectorElement;
  27. protected:
  28. sparseVectorElement **examples_raw;
  29. double **table_A;
  30. double **table_B;
  31. NICE::Vector diagonalElements;
  32. uint *nnz_per_dimension;
  33. uint num_dimension;
  34. uint num_examples;
  35. double d_noise;
  36. void initData ( const std::vector< const NICE::SparseVector *> & examples );
  37. void cleanupData ();
  38. double **allocateTable() const;
  39. void copyTable(double **src, double **dst) const;
  40. public:
  41. /** simple constructor */
  42. GMHIKernelRaw( const std::vector< const NICE::SparseVector *> & examples, const double d_noise = 0.1 );
  43. /** multiply with a vector: A*x = y; this is not really const anymore!! */
  44. virtual void multiply (NICE::Vector & y, const NICE::Vector & x) const;
  45. /** get the number of rows in A */
  46. virtual uint rows () const;
  47. /** get the number of columns in A */
  48. virtual uint cols () const;
  49. double **getTableA() const;
  50. double **getTableB() const;
  51. uint *getNNZPerDimension() const;
  52. /** simple destructor */
  53. virtual ~GMHIKernelRaw();
  54. sparseVectorElement **getDataMatrix() const { return examples_raw; };
  55. void updateTables ( const NICE::Vector _x ) const;
  56. /** get the diagonal elements of the current matrix */
  57. void getDiagonalElements ( NICE::Vector & _diagonalElements ) const;
  58. };
  59. }
  60. #endif