This forum has been archived. All content is frozen. Please use KDE Discuss instead.

PCA Selfadjointeigensolver with 2D points

Tags: None
(comma "," separated)
akalo
Registered Member
Posts
1
Karma
0
Hello,

I have a set of 2D points, let us say 10 2D points. Then I save this points in a matrix, like:
Code: Select all
Eigen::Matrix2Xf matrix;
matrix.resize(2, 10);

for(size_t i = 0; i<10; ++i){
     matrix.col(i) = Eigen::Vector2f(point(i).x, point(i).y);
}

Then I followed the instructions from ggael. (viewtopic.php?f=9&t=110265#p260370)
Code: Select all
Eigen::Matrix2Xf centered    = matrix.rowwise() - matrix.colwise().mean();
Eigen::MatrixXf  covariance = centered.adjoint() * centered;
Eigen::SelfAdjointEigenSolver<Eigen::MatrixXf> pca(covariance, Eigen::ComputeEigenvectors);

I assumed that I get after the PCA a 2x2 matrix, but here I get then a 10x10 matrix.
Unfortunately I didn´t find another tutorials/examples, where I get the 2 Eigenvectors for a 2D point scene.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Your data matrix is stored the other way round compared to the code you borrowed, so you have to adapt the code to your storage order (and use a Matrix2f for speed):

Code: Select all
Eigen::Matrix2Xf centered    = matrix.colwise() - matrix.rowwise().mean();
Eigen::Matrix2f  covariance = centered * centered.adjoint();
Eigen::SelfAdjointEigenSolver<Eigen::Matrix2f> pca(covariance);


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], q.ignora, watchstar