KernelClassifier.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. /** classifier interface for kernel based methods */
  17. class KernelClassifier : public VecClassifier
  18. {
  19. public:
  20. enum {
  21. KERNELCLASSIFIER_NORMALIZATION_EUCLIDEAN = 0,
  22. KERNELCLASSIFIER_NORMALIZATION_NONE
  23. };
  24. protected:
  25. /** This variable might be NULL, if you do not specify a kernel function */
  26. Kernel *kernelFunction;
  27. /** This is the training set, if you specify a kernel function */
  28. NICE::VVector vecSet;
  29. /** These are the labels of the training set, if you specify a kernel function */
  30. NICE::Vector vecSetLabels;
  31. /** Maybe you want to normalize feature vectors before training */
  32. int normalizationType;
  33. /** stored config to initialize KernelData with noiseSigma, cholesky method etc. */
  34. NICE::Config conf;
  35. public:
  36. /** simple constructor */
  37. KernelClassifier(){};
  38. /** specify a kernel function which works on vectors and a normalization method ( use the enum defined in KernelClassifier ) */
  39. KernelClassifier( const NICE::Config *conf, Kernel *kernelFunction = NULL, int normalizationType = KERNELCLASSIFIER_NORMALIZATION_EUCLIDEAN );
  40. /** copy constructor which you should also call in subclasses */
  41. KernelClassifier ( const KernelClassifier & src );
  42. /** simple destructor */
  43. virtual ~KernelClassifier();
  44. // interface function
  45. /** teach the classifier with a kernel matrix and the corresponding class labels @param y ! */
  46. virtual void teach ( KernelData *kernelData, const NICE::Vector & y ) = 0;
  47. /** classify an example by using its kernel values with the training set,
  48. be careful with the order in @param kernelVector */
  49. virtual ClassificationResult classifyKernel ( const NICE::Vector & kernelVector, double kernelSelf ) const = 0;
  50. // functions to build an interface to VecClassifier
  51. /** classify using simple vector, this works only if you specify a kernel function */
  52. ClassificationResult classify ( const NICE::Vector & x ) const;
  53. /** teach classifier with a labeled set of feature vectors, this works only if you specify a kernel function */
  54. virtual void teach ( const LabeledSetVector & teachSet );
  55. /** calculate classifier stuff as the last training step, pretty useless, deprecated */
  56. void finishTeaching() {};
  57. /** clone this object */
  58. KernelClassifier *clone(void) const {
  59. fthrow(Exception, "clone() not yet implemented.");
  60. }
  61. Kernel *getKernelFunction () const { return kernelFunction; };
  62. virtual void restore(std::istream&, int);
  63. virtual void store(std::ostream&, int) const;
  64. };
  65. }
  66. #endif