Created
August 5, 2016 12:14
-
-
Save dojeda/d0333a62b7959590184782fecc1d75a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <Eigen/Dense> | |
int main(int argc, char *argv[]) { | |
Eigen::MatrixXd X = Eigen::MatrixXd::Random(3, 3); | |
// PCA = EVD of the covariance matrix | |
Eigen::SelfAdjointEigenSolver < Eigen::MatrixXd > solver(X.selfadjointView<Eigen::Lower>()); | |
Eigen::MatrixXd V = solver.eigenvectors(); // eigenvectors (in columns) | |
Eigen::VectorXd D = solver.eigenvalues(); | |
std::cout << "X=\n" << X << std::endl; | |
std::cout << "V=\n" << V << std::endl; | |
std::cout << "D=\n" << D << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment