IntersectionKernelFunction.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * @file IntersectionKernelFunction.h
  3. * @brief The intersection kernel function as distance measure between two histograms interpreted as vectors (Interface)
  4. * @author Alexander Freytag
  5. * @date 08-12-2011 (dd-mm-yyyy)
  6. */
  7. #ifndef _NICE_INTERSECTIONKERNELFUNCTION
  8. #define _NICE_INTERSECTIONKERNELFUNCTION
  9. #include <iostream>
  10. #include <gp-hik-core/FeatureMatrixT.h>
  11. #include <core/vector/SparseVectorT.h>
  12. //TODO functions are not allowed to be virtual anymore due to the template usage - any idea how to treat this?
  13. //maybe using type erasure: http://www.artima.com/cppsource/type_erasure2.html ?
  14. namespace NICE {
  15. /**
  16. * @class IntersectionKernelFunction
  17. * @brief The intersection kernel function as distance measure between two histograms interpreted as vectors
  18. * @author Alexander Freytag
  19. */
  20. template<class T> class IntersectionKernelFunction
  21. {
  22. protected:
  23. public:
  24. /**
  25. * @brief Default constructor
  26. * @author Alexander Freytag
  27. * @date 23-12-2011 (dd-mm-yyyy)
  28. */
  29. IntersectionKernelFunction();
  30. /**
  31. * @brief Default desctructor
  32. * @author Alexander Freytag
  33. * @date 23-12-2011 (dd-mm-yyyy)
  34. */
  35. ~IntersectionKernelFunction();
  36. /**
  37. * @brief Measures the distance between tow vectors using the histogram intersection distance
  38. * @author Alexander Freytag
  39. * @date 23-12-2011 (dd-mm-yyyy)
  40. */
  41. double measureDistance ( const std::vector<T> & a, const std::vector<T> & b );
  42. double measureDistance ( const NICE::SparseVector & a, const NICE::SparseVector & b );
  43. /**
  44. * @brief Computes the symmetric and positive semi-definite kernel matrix K based on the given examples using the HIK distance
  45. * @author Alexander Freytag
  46. * @date 23-12-2011 (dd-mm-yyyy)
  47. */
  48. NICE::Matrix computeKernelMatrix ( const std::vector<std::vector<T> > & X );
  49. /**
  50. * @brief Computes the symmetric and positive semi-definite kernel matrix K based on the given examples using the HIK distance and add a given amount of noise on the main diagonal
  51. * @author Alexander Freytag
  52. * @date 23-12-2011 (dd-mm-yyyy)
  53. */
  54. NICE::Matrix computeKernelMatrix ( const std::vector<std::vector<T> > & X , const double & noise);
  55. /**
  56. * @brief Computes the symmetric and positive semi-definite kernel matrix K based on the given examples using the HIK distance and add a given amount of noise on the main diagonal
  57. * @author Alexander Freytag
  58. * @date 23-12-2011 (dd-mm-yyyy)
  59. */
  60. NICE::Matrix computeKernelMatrix ( const std::vector<NICE::SparseVector > & X , const double & noise);
  61. /**
  62. * @brief Computes the symmetric and positive semi-definite kernel matrix K based on the given examples using the HIK distance and add a given amount of noise on the main diagonal
  63. * @author Alexander Freytag
  64. * @date 03-02-2012 (dd-mm-yyyy)
  65. */
  66. NICE::Matrix computeKernelMatrix ( const NICE::FeatureMatrixT<T> & X , const double & noise);
  67. /**
  68. * @brief Computes the similarity between the data and a new vector using the HIK distance
  69. * @author Alexander Freytag
  70. * @date 23-12-2011 (dd-mm-yyyy)
  71. */
  72. std::vector<double> computeKernelVector ( const std::vector<std::vector<T> > & X , const std::vector<T> & xstar);
  73. NICE::Vector computeKernelVector ( const std::vector<NICE::SparseVector> & X , const NICE::SparseVector & xstar);
  74. /**
  75. * @brief Simply print the name of the class
  76. * @author Alexander Freytag
  77. * @date 23-12-2011 (dd-mm-yyyy)
  78. */
  79. void sayYourName();
  80. };
  81. //! default definition for a IntersectionKernelFunction
  82. typedef IntersectionKernelFunction<double> IntersectionKernelFunctionDouble;
  83. }
  84. #ifdef __GNUC__
  85. #include "gp-hik-core/kernels/IntersectionKernelFunction.tcc"
  86. #endif
  87. #endif