Skip to content

Conversation

@akenmorris
Copy link
Contributor

@akenmorris akenmorris commented Dec 17, 2025

Replace VNL eigensystem with Eigen SVD for PCA computation

Switch ParticleShapeStatistics::compute_modes() from VNL's vnl_symmetric_eigensystem to Eigen's BDCSVD algorithm. This provides:

  • Better numerical stability by computing SVD directly on the centered data matrix rather than forming the covariance matrix A^T*A first
  • Reduced dependency on legacy VNL library in favor of Eigen
  • Cleaner code using Eigen's built-in vector normalization

The SVD singular values squared equal the eigenvalues, and the left singular vectors (U) correspond to the eigenvectors in particle space. Results are reversed to maintain ascending eigenvalue order for backward compatibility.

Also add profiling instrumentation to compute_modes() and Studio main.

Profiling with a large dataset (1024 particles X 5,000 shapes) reduced PCA computation from 90 seconds to 19, about 4-5 times faster.

Switch ParticleShapeStatistics::compute_modes() from VNL's
vnl_symmetric_eigensystem to Eigen's BDCSVD algorithm. This provides:

- Better numerical stability by computing SVD directly on the centered
  data matrix rather than forming the covariance matrix A^T*A first
- Reduced dependency on legacy VNL library in favor of Eigen
- Cleaner code using Eigen's built-in vector normalization

The SVD singular values squared equal the eigenvalues, and the left
singular vectors (U) correspond to the eigenvectors in particle space.
Results are reversed to maintain ascending eigenvalue order for backward
compatibility.

Also add profiling instrumentation to compute_modes() and Studio main.
The switch from VNL's vnl_symmetric_eigensystem to Eigen's BDCSVD
introduced test failures due to eigenvector sign ambiguity. In PCA,
eigenvectors are only determined up to a sign (both v and -v are
valid), and different libraries may return either arbitrarily.

Add a consistent sign convention: make the first element of each
eigenvector positive. This ensures deterministic results regardless of
the underlying linear algebra implementation.

Update test baselines to match the new consistent sign convention.

This way if we switch to another implementation later, we can keep the
results consistent.
@akenmorris akenmorris merged commit 89986be into master Dec 17, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants