Skip to content

Conversation

@Alexandr-Solovev
Copy link
Contributor

@Alexandr-Solovev Alexandr-Solovev commented Mar 5, 2025

Changes Summary

  1. Added noise_variance computation
    Implemented calculation of noise variance as part of the PCA result options. This allows better estimation of the unexplained variance in the dataset.

  2. Added syevr-based eigen decomposition function
    Introduced a new function utilizing LAPACK's syevr routine to improve the performance of eigenvector and eigenvalue computations for symmetric matrices.


PR should start as a draft, then move to ready for review state after CI is passed and all applicable checkboxes are closed.
This approach ensures that reviewers don't spend extra time asking for regular requirements.

You can remove a checkbox as not applicable only if it doesn't relate to this PR in any way.
For example, PR with docs update doesn't require checkboxes for performance while PR with any change in actual code should have checkboxes and justify how this code change is expected to affect performance (or justification should be self-evident).

Checklist to comply with before moving PR from draft:

PR completeness and readability

  • I have reviewed my changes thoroughly before submitting this pull request.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation to reflect the changes or created a separate PR with update and provided its number in the description, if necessary.
  • Git commit message contains an appropriate signed-off-by string (see CONTRIBUTING.md for details).
  • I have added a respective label(s) to PR if I have a permission for that.
  • I have resolved any merge conflicts that might occur with the base branch.

Testing

  • I have run it locally and tested the changes extensively.
  • All CI jobs are green or I have provided justification why they aren't.
  • I have extended testing suite if new functionality was introduced in this PR.

Performance

  • I have measured performance for affected algorithms using scikit-learn_bench and provided at least summary table with measured data, if performance change is expected.
  • I have provided justification why performance has changed or why changes are not expected.
  • I have provided justification why quality metrics have changed or why changes are not expected.
  • I have extended benchmarking suite and provided corresponding scikit-learn_bench PR if new measurable functionality was introduced in this PR.

@Alexandr-Solovev Alexandr-Solovev added the dpc++ Issue/PR related to DPC++ functionality label Jun 19, 2025
@Alexandr-Solovev
Copy link
Contributor Author

/intelci: run

// SYEVR branch
// In this case, we compute only nComponents eigenvectors and then sort them in descending order
// inside the 'computeEigenvectorsInplaceSyevr' function
if (nComponents < nFeatures)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it also limit the components by the number of rows in the data by this point? Is that info available here?

eigenvalues[i] = temp_eigenvalues[idx];
for (size_t j = 0; j < nFeatures; ++j)
{
eigenvectors[j + i * nFeatures] = temp_eigenvectors[j + idx * nFeatures];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a dedicated lapack function to reorder columns:
https://www.netlib.org/lapack/explore-3.2.1-html/dlapmt.f.html

Plus there's C++ 'reverse' for vectors:
https://en.cppreference.com/w/cpp/algorithm/reverse.html


Float max_val = row[0];
Float abs_max = std::abs(row[0]);
for (std::int64_t j = 1; j < column_count; j++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it perhaps be faster to use idamax from blas?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add a todo for investigation. For now looks like makes the pr bigger

auto explained_variances_ratio_ptr = explained_variances_ratio.get_mutable_data();

Float sum = 0;
for (std::int64_t i = 0; i < column_count; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could oneDPL be used for this kind of things?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add a todo mark, but may be done in next pr

auto eigvals_ptr = eigenvalues.get_data();
auto singular_values_ptr = singular_values.get_mutable_data();

const Float factor = row_count - 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why '-1' here? Wouldn't this make the result not meet the necessary property that $(\mathbf{X} \mathbf{Z})^T (\mathbf{X} \mathbf{Z}) = \mathbf{I}$

auto compute_event = queue.submit([&](sycl::handler& h) {
h.depends_on(deps);
h.parallel_for(sycl::range<1>(component_count), [=](sycl::id<1> i) {
singular_values_ptr[i] = sycl::sqrt(factor * eigvals_ptr[i]);
Copy link
Contributor

@david-cortes-intel david-cortes-intel Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syevr only generates results that are valid up to numerical tolerance. So a very small eigenvalue that should in theory be positive or zero could still end up as a very small negative number.

@syakov-intel
Copy link

@Alexandr-Solovev please rebase

@Alexandr-Solovev
Copy link
Contributor Author

/intelci: run

@Alexandr-Solovev
Copy link
Contributor Author

/intelci: run

@Alexandr-Solovev
Copy link
Contributor Author

/intelci: run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dpc++ Issue/PR related to DPC++ functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants