00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef IMPALGEBRA_EIGEN_ANALYSIS_H
00010 #define IMPALGEBRA_EIGEN_ANALYSIS_H
00011
00012 #include "IMP/algebra/Vector3D.h"
00013 #include <IMP/log.h>
00014
00015 IMPALGEBRA_BEGIN_NAMESPACE
00016
00017
00018 class IMPALGEBRAEXPORT PrincipalComponentAnalysis {
00019 public:
00020 PrincipalComponentAnalysis(){}
00021 PrincipalComponentAnalysis(const VectorD<3> &pc1,const VectorD<3> &pc2,
00022 const VectorD<3> &pc3,VectorD<3> values) : eigen_values_(values){
00023 eigen_vecs_.push_back(pc1);
00024 eigen_vecs_.push_back(pc2);
00025 eigen_vecs_.push_back(pc3);
00026 }
00027 void show(std::ostream& out = std::cout) const {
00028 out << "Eigen values: ";
00029 eigen_values_.show();
00030 out<<std::endl<<"First eigen vector : ";
00031 eigen_vecs_[0].show();
00032 out<<std::endl<<"Second eigen vector : ";
00033 eigen_vecs_[1].show();
00034 out<<std::endl<<"Third eigen vector : ";
00035 eigen_vecs_[2].show();
00036 }
00037 VectorD<3> get_principal_component(unsigned int i) const {
00038 IMP_INTERNAL_CHECK(i>=0 && i<3, "index is not between 0, 1 or 2");
00039 return eigen_vecs_[i];
00040 }
00041 double get_principal_value(unsigned int i) const {
00042 IMP_INTERNAL_CHECK(i>=0 && i<3, "index is not between 0, 1 or 2");
00043 return eigen_values_[i];
00044 }
00045 protected:
00046 std::vector<VectorD<3> > eigen_vecs_;
00047 VectorD<3> eigen_values_;
00048 };
00049
00050
00051 IMP_OUTPUT_OPERATOR(algebra::PrincipalComponentAnalysis);
00052
00053
00054
00055
00056 IMPALGEBRAEXPORT PrincipalComponentAnalysis get_principal_components(
00057 const std::vector<VectorD<3> > &ps);
00058
00059 IMPALGEBRA_END_NAMESPACE
00060 #endif