PCA.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #include "core/image/Filter.h"
  10. #include "core/vector/VectorT.h"
  11. #include "core/vector/MatrixT.h"
  12. #include "vislearning/math/ftransform/FTransform.h"
  13. namespace OBJREC {
  14. /** extract PCA features */
  15. class PCA: public FTransform
  16. {
  17. protected:
  18. NICE::Vector mean;
  19. NICE::Matrix basis;
  20. NICE::Matrix normbasis;
  21. NICE::Matrix normalization;
  22. uint targetDimension;
  23. uint maxiteration;
  24. double mindelta;
  25. void calculateMean ( const NICE::Matrix &features, NICE::Vector & mean );
  26. public:
  27. PCA (uint dim,uint maxiteration=100,double mindelta=1e-4);
  28. PCA (void);
  29. NICE::Matrix getBasis();
  30. NICE::Vector getMean();
  31. void restore (std::istream & is, int format = 0);
  32. void store (std::ostream & os, int format = 0) const;
  33. void clear ();
  34. /**
  35. * get Basis Vectors of PCA
  36. * @param features Input Features
  37. * @param dimension Dimension size / number of principal components
  38. * @return Basis Vectors
  39. */
  40. void calculateBasis(const NICE::Matrix &features,const uint targetDimension,const uint mode=0);
  41. void calculateBasis(const NICE::Matrix &features,const uint targetDimension,const bool adaptive,const double targetRatio=1.0);
  42. /**
  43. * returns the dimension of the transformed features
  44. * @return feature dim
  45. */
  46. int getTargetDim();
  47. /**
  48. * get Features in PCA Space
  49. * @param data input data
  50. * @param normalize normalisation switch
  51. * @return Features as Vector
  52. */
  53. NICE::Vector getFeatureVector(const NICE::Vector &data,const bool normalize=true);
  54. ~PCA();
  55. private:
  56. void init (uint dim=10,uint maxiteration=100,double mindelta=1e-4);
  57. };
  58. } // namespace
  59. #endif