KCNullSpace.h 3.9 KB

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