Fwd: [PCL-users] pcl::PCA eigenvectors/eigenvalues are computed with incorrect Cov matrix? (1.8)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Fwd: [PCL-users] pcl::PCA eigenvectors/eigenvalues are computed with incorrect Cov matrix? (1.8)

David Doria
Forwarding this to the developers list because it seems like a serious issue and it hasn't gotten any replies on the users list in a month.

Any thoughts?

David

---------- Forwarded message ----------
From: engin <[hidden email]>
Date: Fri, Mar 17, 2017 at 8:55 AM
Subject: [PCL-users] pcl::PCA eigenvectors/eigenvalues are computed with incorrect Cov matrix? (1.8)
To: [hidden email]


Hello,

Line 85-88 of:
https://github.com/PointCloudLibrary/pcl/blob/pcl-1.8.0/common/include/pcl/common/impl/pca.hpp
/*..*/
Eigen::Matrix3f alpha = static_cast<Eigen::Matrix3f>
(cloud_demean.topRows<3> () * cloud_demean.topRows<3> ().transpose ());

  // Compute eigen vectors and values
Eigen::SelfAdjointEigenSolver<Eigen::Matrix3f> evd (alpha);
/*..*/

alpha is presumably the covariance matrix as it is passed to
SelfAdjonitEigenSolver. But shouldn't that be:

alpha = 1/(N-1) * cloud_demean * cloud_demean.transpose()?

Not putting the 1/(N-1) makes the eigenvalues dependent on the number of
points you have in the cloud. Double the number of data points you have in
the exact same [x,y,z] interval you will get eigenvalues that are twice as
big. The eigenvectors may still be fine as they are also normalized. But it
still looks incorrect to me.

Here is an example, I replicated from
http://www.cs.otago.ac.nz/cosc453/student_tutorials/principal_components.pdf
<http://www.cs.otago.ac.nz/cosc453/student_tutorials/principal_components.pdf>
:

If cov is calculated as in the code, the eigenvalues you get will be:
[0.44354, 80.79646]'
their ratio: L1/L2 = 182.16

The correct values are:
[0.049083 , 1.284028]
L1/L2 = 26.160

Was there a reason to write it like this that I'm missing?

Engin



--
View this message in context: http://www.pcl-users.org/pcl-PCA-eigenvectors-eigenvalues-are-computed-with-incorrect-Cov-matrix-1-8-tp4044153.html
Sent from the Point Cloud Library (PCL) Users mailing list mailing list archive at Nabble.com.
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users


_______________________________________________
PCL-developers mailing list
[hidden email]
http://pointclouds.org/mailman/listinfo/pcl-developers
http://pointclouds.org
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: [PCL-users] pcl::PCA eigenvectors/eigenvalues are computed with incorrect Cov matrix? (1.8)

Jochen Sprickerhof
Administrator
Hi Nizar,

looks like this is your code in question:

https://github.com/PointCloudLibrary/pcl/commit/10796ed4b2ee3ae2c2badba630be139d2ed3e357

Can you comment or better, send a pull request?

@David thanks for pinging!

Cheers

Jochen

* David Doria <[hidden email]> [2017-04-27 09:45]:

> Forwarding this to the developers list because it seems like a serious
> issue and it hasn't gotten any replies on the users list in a month.
>
> Any thoughts?
>
> David
>
> ---------- Forwarded message ----------
> From: engin <[hidden email]>
> Date: Fri, Mar 17, 2017 at 8:55 AM
> Subject: [PCL-users] pcl::PCA eigenvectors/eigenvalues are computed with
> incorrect Cov matrix? (1.8)
> To: [hidden email]
>
>
> Hello,
>
> Line 85-88 of:
> https://github.com/PointCloudLibrary/pcl/blob/pcl-1.8.0/common/include/pcl/
> common/impl/pca.hpp
> /*..*/
> Eigen::Matrix3f alpha = static_cast<Eigen::Matrix3f>
> (cloud_demean.topRows<3> () * cloud_demean.topRows<3> ().transpose ());
>
>   // Compute eigen vectors and values
> Eigen::SelfAdjointEigenSolver<Eigen::Matrix3f> evd (alpha);
> /*..*/
>
> alpha is presumably the covariance matrix as it is passed to
> SelfAdjonitEigenSolver. But shouldn't that be:
>
> alpha = 1/(N-1) * cloud_demean * cloud_demean.transpose()?
>
> Not putting the 1/(N-1) makes the eigenvalues dependent on the number of
> points you have in the cloud. Double the number of data points you have in
> the exact same [x,y,z] interval you will get eigenvalues that are twice as
> big. The eigenvectors may still be fine as they are also normalized. But it
> still looks incorrect to me.
>
> Here is an example, I replicated from
> http://www.cs.otago.ac.nz/cosc453/student_tutorials/principal_components.pdf
> <http://www.cs.otago.ac.nz/cosc453/student_tutorials/
> principal_components.pdf>
> :
>
> If cov is calculated as in the code, the eigenvalues you get will be:
> [0.44354, 80.79646]'
> their ratio: L1/L2 = 182.16
>
> The correct values are:
> [0.049083 , 1.284028]
> L1/L2 = 26.160
>
> Was there a reason to write it like this that I'm missing?
>
> Engin
>
>
>
> --
> View this message in context: http://www.pcl-users.org/pcl-
> PCA-eigenvectors-eigenvalues-are-computed-with-incorrect-
> Cov-matrix-1-8-tp4044153.html
> Sent from the Point Cloud Library (PCL) Users mailing list mailing list
> archive at Nabble.com.
> _______________________________________________
> [hidden email] / http://pointclouds.org
> http://pointclouds.org/mailman/listinfo/pcl-users

> _______________________________________________
> PCL-developers mailing list
> [hidden email]
> http://pointclouds.org/mailman/listinfo/pcl-developers
> http://pointclouds.org


_______________________________________________
PCL-developers mailing list
[hidden email]
http://pointclouds.org/mailman/listinfo/pcl-developers
http://pointclouds.org

signature.asc (849 bytes) Download Attachment