KCNullSpaceNovelty.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * @file KCNullSpaceNovelty.h
  3. * @author Paul Bodesheim
  4. * @date 26/11/2012
  5. */
  6. #ifndef _NICE_OBJREC_KCNULLSPACENOVELTYINCLUDE
  7. #define _NICE_OBJREC_KCNULLSPACENOVELTYINCLUDE
  8. #include "vislearning/math/mathbase/FullVector.h"
  9. #include "vislearning/classifier/classifierbase/KernelClassifier.h"
  10. #include <vector>
  11. #include "core/vector/VVector.h"
  12. #include "core/vector/Eigen.h"
  13. namespace OBJREC
  14. {
  15. /** @class KCNullSpaceNovelty
  16. * Novelty detection with kernel null space methods (Kernel Null Foley Sammon Transform - KNFST)
  17. *
  18. * @author Paul Bodesheim
  19. */
  20. class KCNullSpaceNovelty : public KernelClassifier
  21. {
  22. protected:
  23. /** tell us something about what you are doing */
  24. bool verbose;
  25. /** Kernel PCA basisvectors as columns of a matrix */
  26. NICE::Matrix eigenBasis;
  27. /** store class labels and corresponding number of samples in this map: <classLabel,numClassSamples> */
  28. std::map<int, int> trainingSetStatistic;
  29. /** null projection directions in columns of a matrix */
  30. NICE::Matrix nullProjectionDirections;
  31. /** target points in the null space represented as NICE::Vector's within a std::vector */
  32. NICE::VVector targetPoints;
  33. /** dimension of the null space */
  34. int dimNullSpace;
  35. /** one-class novelty detection? */
  36. bool oneClassSetting;
  37. /** count how many training samples are in each class */
  38. void computeTrainingSetStatistic(const NICE::Vector & y);
  39. /** compute null projection directions using kernel data and labels */
  40. void computeNullProjectionDirections(const KernelData *kernelData, const NICE::Vector & y);
  41. /** compute target points of training data */
  42. void computeTargetPoints(const KernelData *kernelData, const NICE::Vector & y);
  43. /** compute Kernel PCA basisvectors as columns of a matrix */
  44. void computeBasisUsingKernelPCA(const KernelData *kernelData);
  45. /** center kernel matrix such that data in kernel feature space has zero mean */
  46. void centerKernelMatrix(NICE::Matrix & kernelMatrix);
  47. public:
  48. /** simplest constructor */
  49. KCNullSpaceNovelty() {};
  50. /** simple constructor */
  51. KCNullSpaceNovelty ( const NICE::Config *conf, Kernel *kernelFunction = NULL, const std::string & section = "KCNullSpaceNovelty" );
  52. /** copy constructor */
  53. KCNullSpaceNovelty ( const KCNullSpaceNovelty &vcova );
  54. /** simple destructor */
  55. virtual ~KCNullSpaceNovelty();
  56. /** teach the classifier with a kernel matrix and the corresponding class labels @param y ! */
  57. void teach ( KernelData *kernelData, const NICE::Vector & y );
  58. void teach ( KernelData *kernelData, const std::vector<double> & y );
  59. /** classify an example by using its kernel values with the training set,
  60. be careful with the order in @param kernelVector */
  61. ClassificationResult classifyKernel ( const NICE::Vector & kernelVector, double kernelSelf ) const;
  62. /** return class labels and corresponding number of class samples */
  63. std::map<int,int> getTrainingSetStatistic();
  64. /** return null projection directions in columns of a matrix */
  65. NICE::Matrix getNullProjectionDirections();
  66. /** return target points as NICE::Vector's within a std::vector */
  67. NICE::VVector getTargetPoints();
  68. /** true if it is a one-class setting */
  69. bool isOneClass();
  70. /** return dimension of the null space */
  71. int getNullSpaceDimension();
  72. void restore ( std::istream&, int );
  73. void store ( std::ostream&, int ) const;
  74. void clear();
  75. /** clone this object */
  76. virtual KCNullSpaceNovelty *clone ( void ) const;
  77. };
  78. }
  79. #endif