GeneralizedIntersectionKernelFunction.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * @file GeneralizedIntersectionKernelFunction.h
  3. * @brief The generalized intersection kernel function as distance measure between two histograms interpreted as vectors (Interface)
  4. * @author Alexander Freytag
  5. * @date 23-12-2011 (dd-mm-yyyy)
  6. */
  7. #ifndef _NICE_GENERALIZEDINTERSECTIONKERNELFUNCTION
  8. #define _NICE_GENERALIZEDINTERSECTIONKERNELFUNCTION
  9. #include <iostream>
  10. #include <core/vector/MatrixT.h>
  11. #include <gp-hik-core/FeatureMatrixT.h>
  12. namespace NICE {
  13. /**
  14. * @class GeneralizedIntersectionKernelFunction
  15. * @brief The generalized intersection kernel function as distance measure between two histograms interpreted as vectors
  16. * @author Alexander Freytag
  17. */
  18. template<class T> class GeneralizedIntersectionKernelFunction
  19. {
  20. protected:
  21. //TODO one could also use a separate function here, such as pow(,a) - this would be much more generalized but only power the inputs.
  22. double exponent;
  23. public:
  24. /**
  25. * @brief Default constructor
  26. * @author Alexander Freytag
  27. * @date 23-12-2011 (dd-mm-yyyy)
  28. */
  29. GeneralizedIntersectionKernelFunction();
  30. /**
  31. * @brief Recommended constructor
  32. * @author Alexander Freytag
  33. * @date 23-12-2011 (dd-mm-yyyy)
  34. */
  35. GeneralizedIntersectionKernelFunction(const double & _exponent);
  36. /**
  37. * @brief Default desctructor
  38. * @author Alexander Freytag
  39. * @date 23-12-2011 (dd-mm-yyyy)
  40. */
  41. ~GeneralizedIntersectionKernelFunction();
  42. /**
  43. * @brief Set exponent to specified value
  44. * @author Alexander Freytag
  45. * @date 23-12-2011 (dd-mm-yyyy)
  46. */
  47. void set_exponent(const double & _exponent);
  48. /**
  49. * @brief Return currently used exponent
  50. * @author Alexander Freytag
  51. * @date 23-12-2011 (dd-mm-yyyy)
  52. */
  53. double get_exponent();
  54. /**
  55. * @brief Measures the distance between tow vectors using the generalized histogram intersection distance
  56. * @author Alexander Freytag
  57. * @date 23-12-2011 (dd-mm-yyyy)
  58. */
  59. double measureDistance ( const std::vector<T> & a, const std::vector<T> & b );
  60. /**
  61. * @brief Computes the symmetric and positive semi-definite kernel matrix K based on the given examples using the g-HIK distance
  62. * @author Alexander Freytag
  63. * @date 23-12-2011 (dd-mm-yyyy)
  64. */
  65. NICE::Matrix computeKernelMatrix ( const std::vector<std::vector<T> > & X );
  66. /**
  67. * @brief Computes the symmetric and positive semi-definite kernel matrix K based on the given examples using the g-HIK distance and add a given amount of noise on the main diagonal
  68. * @author Alexander Freytag
  69. * @date 23-12-2011 (dd-mm-yyyy)
  70. */
  71. NICE::Matrix computeKernelMatrix ( const std::vector<std::vector<T> > & X , const double & noise);
  72. /**
  73. * @brief Computes the symmetric and positive semi-definite kernel matrix K based on the given examples using the g-HIK distance and add a given amount of noise on the main diagonal
  74. * @author Alexander Freytag
  75. * @date 03-02-2012 (dd-mm-yyyy)
  76. */
  77. NICE::Matrix computeKernelMatrix ( const NICE::FeatureMatrixT<T> & X , const double & noise);
  78. /**
  79. * @brief Computes the similarity between the data and a new vector using the g-HIK distance
  80. * @author Alexander Freytag
  81. * @date 23-12-2011 (dd-mm-yyyy)
  82. */
  83. std::vector<double> computeKernelVector ( const std::vector<std::vector<T> > & X , const std::vector<T> & xstar);
  84. /**
  85. * @brief Simply print the name of the class
  86. * @author Alexander Freytag
  87. * @date 23-12-2011 (dd-mm-yyyy)
  88. */
  89. void sayYourName();
  90. };
  91. //! default definition for a GeneralizedIntersectionKernelFunction
  92. typedef GeneralizedIntersectionKernelFunction<double> GeneralizedIntersectionKernelFunctionDouble;
  93. }
  94. #ifdef __GNUC__
  95. #include "gp-hik-core/kernels/GeneralizedIntersectionKernelFunction.tcc"
  96. #endif
  97. #endif