GMHIKernel.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * @file GMHIKernel.h
  3. * @author Erik Rodner, Alexander Freytag
  4. * @brief Fast multiplication with histogram intersection kernel matrices (Interface)
  5. * @date 01/02/2012
  6. */
  7. #ifndef _NICE_GMHIKERNELINCLUDE
  8. #define _NICE_GMHIKERNELINCLUDE
  9. #include <vector>
  10. #include <core/algebra/GenericMatrix.h>
  11. #include <core/algebra/PartialGenericMatrix.h>
  12. #include "ImplicitKernelMatrix.h"
  13. #include "FeatureMatrixT.h"
  14. #include "FastMinKernel.h"
  15. namespace NICE {
  16. /**
  17. * @class GMHIKernel
  18. * @brief Fast multiplication with histogram intersection kernel matrices
  19. * @author Erik Rodner, Alexander Freytag
  20. */
  21. class GMHIKernel : public ImplicitKernelMatrix, public PartialGenericMatrix
  22. {
  23. protected:
  24. FastMinKernel *fmk;
  25. const Quantization *q;
  26. ParameterizedFunction *pf;
  27. bool verbose;
  28. bool use_sparse_implementation;
  29. bool useOldPreparation;
  30. public:
  31. /** simple constructor */
  32. GMHIKernel( FastMinKernel *_fmk, ParameterizedFunction *_pf = NULL, const Quantization *_q = NULL );
  33. /** multiply with a vector: A*x = y */
  34. virtual void multiply (NICE::Vector & y, const NICE::Vector & x) const;
  35. /** multiply with a vector: A_subset * x = y */
  36. virtual void multiply (const PartialGenericMatrix::SetType & rowSet, const PartialGenericMatrix::SetType & columnSet, NICE::Vector & y, const NICE::Vector & x) const;
  37. /** get the number of rows in A */
  38. virtual uint rows () const;
  39. /** get the number of columns in A */
  40. virtual uint cols () const;
  41. /** simple destructor */
  42. virtual ~GMHIKernel();
  43. /** get the diagonal elements of the current matrix */
  44. virtual double getDiagonalElement ( uint i ) const;
  45. virtual void getDiagonalElements ( Vector & diagonalElements ) const;
  46. virtual void getFirstDiagonalElement ( double & diagonalElement ) const;
  47. uint getNumParameters() const;
  48. void getParameters(Vector & parameters) const;
  49. void setParameters(const Vector & parameters);
  50. bool outOfBounds(const Vector & parameters) const;
  51. Vector getParameterLowerBounds() const;
  52. Vector getParameterUpperBounds() const;
  53. void setVerbose( const bool & _verbose);
  54. void setUseOldPreparation( const bool & _useOldPreparation);
  55. virtual double approxFrobNorm() const;
  56. virtual void setApproximationScheme(const int & _approxScheme);
  57. void setFastMinKernel(NICE::FastMinKernel * _fmk){fmk = _fmk;};
  58. ///////////////////// INTERFACE PERSISTENT /////////////////////
  59. // interface specific methods for store and restore
  60. ///////////////////// INTERFACE PERSISTENT /////////////////////
  61. virtual void restore ( std::istream & is, int format = 0 ) {};//fmk->restore( is, format );};
  62. virtual void store ( std::ostream & os, int format = 0 ) const {};//fmk->store( os, format );};
  63. virtual void clear () {};
  64. ///////////////////// INTERFACE ONLINE LEARNABLE /////////////////////
  65. // interface specific methods for incremental extensions
  66. ///////////////////// INTERFACE ONLINE LEARNABLE /////////////////////
  67. virtual void addExample( const NICE::SparseVector * example,
  68. const double & label,
  69. const bool & performOptimizationAfterIncrement = true
  70. );
  71. virtual void addMultipleExamples( const std::vector< const NICE::SparseVector * > & newExamples,
  72. const NICE::Vector & newLabels,
  73. const bool & performOptimizationAfterIncrement = true
  74. );
  75. };
  76. }
  77. #endif