PCA.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * @file PCA.h
  3. * @brief extract fourier domain value
  4. * @author Michael Koch
  5. * @date 5/27/2008
  6. */
  7. #ifndef PCAINCLUDE
  8. #define PCAINCLUDE
  9. #ifdef NOVISUAL
  10. #include <vislearning/nice_nonvis.h>
  11. #else
  12. #include <vislearning/nice.h>
  13. #endif
  14. #include "vislearning/math/ftransform/FTransform.h"
  15. namespace OBJREC {
  16. /** extract PCA features */
  17. class PCA: public FTransform
  18. {
  19. protected:
  20. NICE::Vector mean;
  21. NICE::Matrix basis;
  22. NICE::Matrix normbasis;
  23. NICE::Matrix normalization;
  24. uint targetDimension;
  25. uint maxiteration;
  26. double mindelta;
  27. public:
  28. PCA (uint dim,uint maxiteration=100,double mindelta=1e-4);
  29. PCA (void);
  30. NICE::Matrix getBasis();
  31. NICE::Vector getMean();
  32. void restore (std::istream & is, int format = 0);
  33. void store (std::ostream & os, int format = 0) const;
  34. void clear ();
  35. /**
  36. * get Basis Vectors of PCA
  37. * @param features Input Features
  38. * @param dimension Dimension size / number of principal components
  39. * @param mode Algorithm mode 0=SVD 1=Arnoldi
  40. * @return Basis Vectors
  41. */
  42. void calculateBasis(const NICE::Matrix &features,const uint targetDimension,const uint mode=0);
  43. void calculateBasis(const NICE::Matrix &features,const uint targetDimension,const uint mode,const bool adaptive,const double targetRatio=1.0);
  44. /**
  45. * returns the dimension of the transformed features
  46. * @return feature dim
  47. */
  48. int getTargetDim();
  49. /**
  50. * get Features in PCA Space
  51. * @param data input data
  52. * @param normalize normalisation switch
  53. * @return Features as Vector
  54. */
  55. NICE::Vector getFeatureVector(const NICE::Vector &data,const bool normalize=true);
  56. ~PCA();
  57. private:
  58. void init (uint dim=10,uint maxiteration=100,double mindelta=1e-4);
  59. };
  60. } // namespace
  61. #endif