8 #ifndef IMPALGEBRA_EIGEN_ANALYSIS_H
9 #define IMPALGEBRA_EIGEN_ANALYSIS_H
14 #include "IMP/algebra/internal/utility.h"
19 IMPALGEBRA_BEGIN_NAMESPACE
28 : eigen_vecs_(pcs), eigen_values_(values), centroid_(centroid) {}
33 VectorD<D> get_principal_component(
unsigned int i)
const {
35 return eigen_vecs_[i];
41 double get_principal_value(
unsigned int i)
const {
43 return eigen_values_[i];
56 "Cannot compare against anything other than the default"
57 " PrincipalComponentAnalysis");
58 if (eigen_vecs_.empty() && o.eigen_vecs_.empty()) {
78 PrincipalComponentAnalysis1Ds;
80 PrincipalComponentAnalysis2Ds;
82 PrincipalComponentAnalysis3Ds;
84 PrincipalComponentAnalysis4Ds;
86 PrincipalComponentAnalysis5Ds;
88 PrincipalComponentAnalysis6Ds;
90 PrincipalComponentAnalysisKDs;
94 if (eigen_vecs_.empty()) {
98 out <<
"vectors: " << eigen_vecs_ <<
" weights: " << eigen_values_
99 <<
" centroid: " << centroid_ << std::endl;
111 unsigned int dim = ps[0].get_dimension();
115 Eigen::MatrixXd cov = internal::get_covariance_matrix(ps, m);
118 Eigen::JacobiSVD<Eigen::MatrixXd> svd = cov.jacobiSvd(Eigen::ComputeFullV);
119 Eigen::MatrixXd V = svd.matrixV();
120 Eigen::VectorXd SV = svd.singularValues();
125 for (
unsigned int i = 0; i < dim; ++i) {
127 for (
unsigned int j = 0; j < dim; ++j) {
128 vectors[i][j] = V(j, i);
138 const PrincipalComponentAnalysisD<3> &pca1,
139 const PrincipalComponentAnalysisD<3> &pca2);
142 typedef PrincipalComponentAnalysisD<3> PrincipalComponentAnalysis;
145 IMPALGEBRA_END_NAMESPACE
Base class for geometric types.
VectorD< D > get_zero_vector_kd(int Di)
Return a dynamically sized vector of zeros.
#define IMP_SHOWABLE(Name)
#define IMP_COMPARISONS(Name)
Implement comparison in a class using a compare function.
#define IMP_LOG_VERBOSE(expr)
A more IMP-like version of the std::vector.
Represent an eigen analysis of some data.
Base class for geometric types.
A Cartesian vector in D-dimensions.
int compare(const VectorD< D > &a, const VectorD< D > &b)
lexicographic comparison of two vectors
Logging and error reporting support.
Transformation3Ds get_alignments_from_first_to_second(const PrincipalComponentAnalysisD< 3 > &pca1, const PrincipalComponentAnalysisD< 3 > &pca2)
Get all alignments of the first principal component system to the second one.
PrincipalComponentAnalysisD< D > get_principal_components(const Vector< VectorD< D > > &ps)
Perform principal components analysis on a set of vectors.
Vector3D get_centroid(const Vector3Ds &ps)
Return the centroid of a set of vectors.
std::ostream & show(Hierarchy h, std::ostream &out=std::cout)
Print the hierarchy using a given decorator to display each node.
IMP::Vector< Transformation3D > Transformation3Ds
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Logging and error reporting support.