IKMLinearCombination.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * @file IKMLinearCombination.h
  3. * @brief Combination of several (implicit) kernel matrices, such as noise matrix and gp-hik kernel matrix (Interface)
  4. * @author Erik Rodner, Alexander Freytag
  5. * @date 02/14/2012
  6. */
  7. #ifndef _NICE_IKMLINEARCOMBINATIONINCLUDE
  8. #define _NICE_IKMLINEARCOMBINATIONINCLUDE
  9. // STL includes
  10. #include <vector>
  11. // gp-hik-core includes
  12. #include "gp-hik-core/ImplicitKernelMatrix.h"
  13. #include "gp-hik-core/OnlineLearnable.h"
  14. namespace NICE {
  15. /**
  16. * @class IKMLinearCombination
  17. * @brief Combination of several (implicit) kernel matrices, such as noise matrix and gp-hik kernel matrix
  18. * @author Erik Rodner, Alexander Freytag
  19. */
  20. class IKMLinearCombination : public ImplicitKernelMatrix
  21. {
  22. protected:
  23. std::vector< ImplicitKernelMatrix * > matrices;
  24. std::vector<int> parameterRanges;
  25. bool verbose;
  26. void updateParameterRanges();
  27. public:
  28. /** simple constructor */
  29. IKMLinearCombination();
  30. /** simple destructor */
  31. virtual ~IKMLinearCombination();
  32. virtual void getDiagonalElements ( Vector & diagonalElements ) const;
  33. virtual void getFirstDiagonalElement ( double & diagonalElement ) const;
  34. virtual uint getNumParameters() const;
  35. virtual void getParameters(Vector & parameters) const;
  36. virtual void setParameters(const Vector & parameters);
  37. virtual bool outOfBounds(const Vector & parameters) const;
  38. void setVerbose(const bool & _verbose);
  39. virtual Vector getParameterLowerBounds() const;
  40. virtual Vector getParameterUpperBounds() const;
  41. void addModel ( ImplicitKernelMatrix *ikm );
  42. /** multiply with a vector: A*x = y */
  43. virtual void multiply (NICE::Vector & y, const NICE::Vector & x) const;
  44. /** get the number of rows in A */
  45. virtual uint rows () const;
  46. /** get the number of columns in A */
  47. virtual uint cols () const;
  48. virtual double approxFrobNorm() const;
  49. virtual void setApproximationScheme(const int & _approxScheme);
  50. ImplicitKernelMatrix * getModel(const uint & idx) const;
  51. inline int getNumberOfModels(){return matrices.size();};
  52. ///////////////////// INTERFACE PERSISTENT /////////////////////
  53. // interface specific methods for store and restore
  54. ///////////////////// INTERFACE PERSISTENT /////////////////////
  55. virtual void restore ( std::istream & is, int format = 0 ) ;
  56. virtual void store ( std::ostream & os, int format = 0 ) const;
  57. virtual void clear () {};
  58. ///////////////////// INTERFACE ONLINE LEARNABLE /////////////////////
  59. // interface specific methods for incremental extensions
  60. ///////////////////// INTERFACE ONLINE LEARNABLE /////////////////////
  61. virtual void addExample( const NICE::SparseVector * example,
  62. const double & label,
  63. const bool & performOptimizationAfterIncrement = true
  64. );
  65. virtual void addMultipleExamples( const std::vector< const NICE::SparseVector * > & newExamples,
  66. const NICE::Vector & newLabels,
  67. const bool & performOptimizationAfterIncrement = true
  68. );
  69. };
  70. }
  71. #endif