PCA.h 1.8 KB

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