PCA.h 2.0 KB

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