KernelClassifier.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * @file KernelClassifier.h
  3. * @brief classifier interface for kernel based methods
  4. * @author Erik Rodner
  5. * @date 12/02/2009
  6. */
  7. #ifndef KERNELCLASSIFIERINCLUDE
  8. #define KERNELCLASSIFIERINCLUDE
  9. #include "vislearning/math/kernels/Kernel.h"
  10. #include "vislearning/math/kernels/KernelData.h"
  11. #include "core/vector/VVector.h"
  12. #include "vislearning/cbaselib/ClassificationResult.h"
  13. #include "vislearning/cbaselib/LabeledSet.h"
  14. #include "vislearning/classifier/classifierbase/VecClassifier.h"
  15. namespace OBJREC
  16. {
  17. /** classifier interface for kernel based methods */
  18. class KernelClassifier : public VecClassifier
  19. {
  20. public:
  21. enum
  22. {
  23. KERNELCLASSIFIER_NORMALIZATION_EUCLIDEAN = 0,
  24. KERNELCLASSIFIER_NORMALIZATION_NONE
  25. };
  26. protected:
  27. /** This variable might be NULL, if you do not specify a kernel function */
  28. Kernel *kernelFunction;
  29. /** This is the training set, if you specify a kernel function */
  30. NICE::VVector vecSet;
  31. /** These are the labels of the training set, if you specify a kernel function */
  32. NICE::Vector vecSetLabels;
  33. /** Maybe you want to normalize feature vectors before training */
  34. int normalizationType;
  35. /** stored config to initialize KernelData with noiseSigma, cholesky method etc. */
  36. NICE::Config conf;
  37. public:
  38. /** simple constructor */
  39. KernelClassifier() {};
  40. /** specify a kernel function which works on vectors and a normalization method ( use the enum defined in KernelClassifier ) */
  41. KernelClassifier ( const NICE::Config *conf, Kernel *kernelFunction = NULL, int normalizationType = KERNELCLASSIFIER_NORMALIZATION_EUCLIDEAN );
  42. /** copy constructor which you should also call in subclasses */
  43. KernelClassifier ( const KernelClassifier & src );
  44. /** simple destructor */
  45. virtual ~KernelClassifier();
  46. // interface function
  47. /** teach the classifier with a kernel matrix and the corresponding class labels @param y ! */
  48. virtual void teach ( KernelData *kernelData, const NICE::Vector & y ) = 0;
  49. /** classify an example by using its kernel values with the training set,
  50. be careful with the order in @param kernelVector */
  51. virtual ClassificationResult classifyKernel ( const NICE::Vector & kernelVector, double kernelSelf ) const = 0;
  52. // functions to build an interface to VecClassifier
  53. /** classify using simple vector, this works only if you specify a kernel function */
  54. ClassificationResult classify ( const NICE::Vector & x ) const;
  55. /** teach classifier with a labeled set of feature vectors, this works only if you specify a kernel function */
  56. virtual void teach ( const LabeledSetVector & teachSet );
  57. /** calculate classifier stuff as the last training step, pretty useless, deprecated */
  58. void finishTeaching() {};
  59. /** clone this object */
  60. KernelClassifier *clone ( void ) const
  61. {
  62. fthrow ( NICE::Exception, "clone() not yet implemented." );
  63. }
  64. Kernel *getKernelFunction () const
  65. {
  66. return kernelFunction;
  67. };
  68. virtual void restore ( std::istream&, int );
  69. virtual void store ( std::ostream&, int ) const;
  70. };
  71. }
  72. #endif