GMHIKernelRaw.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #include "quantization/Quantization.h"
  11. namespace NICE {
  12. /**
  13. * @class GMHIKernelRaw
  14. * @brief Fast multiplication with histogram intersection kernel matrices
  15. * @author Erik Rodner, Alexander Freytag
  16. */
  17. class GMHIKernelRaw : public GenericMatrix
  18. {
  19. public:
  20. typedef struct sparseVectorElement {
  21. uint example_index;
  22. double value;
  23. bool operator< (const sparseVectorElement & a) const
  24. {
  25. return value < a.value;
  26. }
  27. } sparseVectorElement;
  28. protected:
  29. sparseVectorElement **examples_raw;
  30. double **table_A;
  31. double **table_B;
  32. double *table_T;
  33. NICE::Vector diagonalElements;
  34. uint *nnz_per_dimension;
  35. uint num_dimension;
  36. uint num_examples;
  37. double d_noise;
  38. /** object performing feature quantization */
  39. NICE::Quantization *q;
  40. /////////////////////////
  41. /////////////////////////
  42. // PROTECTED METHODS //
  43. /////////////////////////
  44. /////////////////////////
  45. void initData ( const std::vector< const NICE::SparseVector *> & examples );
  46. void cleanupData ();
  47. double** allocateTableAorB() const;
  48. double* allocateTableT() const;
  49. void copyTableAorB(double **src, double **dst) const;
  50. void copyTableT(double *src, double *dst) const;
  51. void clearTablesAandB();
  52. void clearTablesT();
  53. double * computeTableT ( const NICE::Vector & _alpha
  54. );
  55. /////////////////////////
  56. /////////////////////////
  57. // PUBLIC METHODS //
  58. /////////////////////////
  59. /////////////////////////
  60. public:
  61. /** simple constructor */
  62. GMHIKernelRaw( const std::vector< const NICE::SparseVector *> & _examples,
  63. const double _d_noise = 0.1,
  64. NICE::Quantization * _q = NULL
  65. );
  66. /** multiply with a vector: A*x = y; this is not really const anymore!! */
  67. virtual void multiply ( NICE::Vector & y,
  68. const NICE::Vector & x
  69. ) const;
  70. /** get the number of rows in A */
  71. virtual uint rows () const;
  72. /** get the number of columns in A */
  73. virtual uint cols () const;
  74. double **getTableA() const;
  75. double **getTableB() const;
  76. double *getTableT() const;
  77. uint *getNNZPerDimension() const;
  78. uint getNumberOfDimensions() const;
  79. /** simple destructor */
  80. virtual ~GMHIKernelRaw();
  81. sparseVectorElement **getDataMatrix() const { return examples_raw; };
  82. void updateTablesAandB ( const NICE::Vector _x ) const;
  83. void updateTableT ( const NICE::Vector _x ) const;
  84. /** get the diagonal elements of the current matrix */
  85. void getDiagonalElements ( NICE::Vector & _diagonalElements ) const;
  86. NICE::Vector getLargestValuePerDimension ( ) const;
  87. };
  88. }
  89. #endif