8 #ifndef IMPALGEBRA_EIGEN_ANALYSIS_H
9 #define IMPALGEBRA_EIGEN_ANALYSIS_H
14 #include "IMP/algebra/internal/utility.h"
18 #include <cereal/access.hpp>
20 IMPALGEBRA_BEGIN_NAMESPACE
29 : eigen_vecs_(pcs), eigen_values_(values), centroid_(centroid) {}
34 VectorD<D> get_principal_component(
unsigned int i)
const {
36 return eigen_vecs_[i];
42 double get_principal_value(
unsigned int i)
const {
44 return eigen_values_[i];
57 "Cannot compare against anything other than the default"
58 " PrincipalComponentAnalysis");
59 if (eigen_vecs_.empty() && o.eigen_vecs_.empty()) {
69 friend class cereal::access;
71 template<
class Archive>
void serialize(Archive &ar) {
72 ar(eigen_vecs_, eigen_values_, centroid_);
85 PrincipalComponentAnalysis1Ds;
87 PrincipalComponentAnalysis2Ds;
89 PrincipalComponentAnalysis3Ds;
91 PrincipalComponentAnalysis4Ds;
93 PrincipalComponentAnalysis5Ds;
95 PrincipalComponentAnalysis6Ds;
97 PrincipalComponentAnalysisKDs;
101 if (eigen_vecs_.empty()) {
105 out <<
"vectors: " << eigen_vecs_ <<
" weights: " << eigen_values_
106 <<
" centroid: " << centroid_ << std::endl;
118 unsigned int dim = ps[0].get_dimension();
122 Eigen::MatrixXd cov = internal::get_covariance_matrix(ps, m);
125 #if EIGEN_MAJOR_VERSION >= 5
126 auto svd = cov.jacobiSvd<Eigen::ComputeFullV>();
128 Eigen::JacobiSVD<Eigen::MatrixXd> svd = cov.jacobiSvd(Eigen::ComputeFullV);
130 Eigen::MatrixXd V = svd.matrixV();
131 Eigen::VectorXd SV = svd.singularValues();
136 for (
unsigned int i = 0; i < dim; ++i) {
138 for (
unsigned int j = 0; j < dim; ++j) {
139 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
Base class for geometric types.
A Cartesian vector in D-dimensions.
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)
algebra::Vector3D get_centroid(const XYZs &ps)
Get the centroid.
A more IMP-like version of the std::vector.
Represent an eigen analysis of some data.
Logging and error reporting support.
Base class for geometric types.
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.
int compare(const VectorD< D > &a, const VectorD< D > &b)
lexicographic comparison of two 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.