8 #ifndef IMPALGEBRA_EIGEN_ANALYSIS_H
9 #define IMPALGEBRA_EIGEN_ANALYSIS_H
14 #include "IMP/algebra/internal/utility.h"
16 #include <IMP/algebra/internal/jama_svd.h>
19 IMPALGEBRA_BEGIN_NAMESPACE
30 eigen_values_(values), centroid_(centroid){
34 "The PCA was not initialized");
37 VectorD<D> get_principal_component(
unsigned int i)
const {
39 "The PCA was not initialized");
40 return eigen_vecs_[i];
44 "The PCA was not initialized");
47 double get_principal_value(
unsigned int i)
const {
49 "The PCA was not initialized");
50 return eigen_values_[i];
57 "The PCA was not initialized");
66 "Cannot compare against anything other than the default"
67 " PrincipalComponentAnalysis");
68 if (eigen_vecs_.empty() && eigen_vecs_.empty()) {
88 PrincipalComponentAnalysis1Ds;
90 PrincipalComponentAnalysis2Ds;
92 PrincipalComponentAnalysis3Ds;
94 PrincipalComponentAnalysis4Ds;
96 PrincipalComponentAnalysis5Ds;
98 PrincipalComponentAnalysis6Ds;
100 PrincipalComponentAnalysisKDs;
104 if (eigen_vecs_.empty()) {
108 out <<
"vectors: " << eigen_vecs_ <<
" weights: " << eigen_values_
109 <<
" centroid: " << centroid_ << std::endl;
121 unsigned int dim=ps[0].get_dimension();
122 VectorD<D> m = std::accumulate(ps.begin(), ps.end(),
124 internal::TNT::Array2D<double> cov = internal::get_covariance_matrix(ps,m);
126 internal::JAMA::SVD<double> svd(cov);
127 internal::TNT::Array2D<double> V(dim, dim);
128 internal::TNT::Array1D<double> SV;
132 svd.getSingularValues(SV);
135 for (
unsigned int i=0; i< dim; ++i) {
137 for (
unsigned int j=0; j< dim; ++j) {
138 vectors[i][j]= V[j][i];
149 const PrincipalComponentAnalysisD<3> &pca1,
150 const PrincipalComponentAnalysisD<3> &pca2);
153 typedef PrincipalComponentAnalysisD<3> PrincipalComponentAnalysis;
156 IMPALGEBRA_END_NAMESPACE