Skip to content

Validate PCA whitening rank against input dimension - #7962

Open
svick wants to merge 1 commit into
dotnet:mainfrom
svick:fix/vector-whitening-rank
Open

svick wants to merge 1 commit into
dotnet:mainfrom
svick:fix/vector-whitening-rank

Conversation

@svick

@svick svick commented Nov 26, 2026

Copy link
Copy Markdown
Member

PCA whitening accepts a rank larger than the input dimension, which can read past the learned matrix during scoring. Validate the rank before training and when binding a transformer, including one loaded from an older model. ZCA continues to ignore the rank.

Note

This description was generated by Copilot.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 07346522-64e9-4d8c-b1fa-70c33b60a349
@svick
svick marked this pull request as ready for review November 26, 2026 16:59
@svick
svick requested a balanced review from Copilot November 26, 2026 16:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the PCA rank-validation change.

No open issues 🎉

What changed in this PR

This PR prevents PCA whitening from accepting a rank larger than the input dimension, avoiding out-of-bounds reads during scoring in ML.NET.

Changes:

  • Validates PCA rank before training and when binding a transformer, including loaded models.
  • Preserves ZCA behavior, which ignores rank.
  • Adds regression tests for oversized ranks, valid boundary values, and invalid ranks in loaded models.
File Description
test/​Microsoft.ML.Tests/​Transformers/​NormalizerTests.cs Adds rank-validation and model-loading regression tests.
src/​Microsoft.ML.Mkl.Components/​VectorWhitening.cs Adds a shared PCA rank check to training and transformer binding.

Review effort: Balanced

@codecov

codecov Bot commented Nov 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.89%. Comparing base (f603ac3) to head (5a20c21).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7962   +/-   ##
=======================================
  Coverage   70.89%   70.89%           
=======================================
  Files        1421     1421           
  Lines      280133   280167   +34     
  Branches    27601    27602    +1     
=======================================
+ Hits       198591   198638   +47     
+ Misses      73407    73391   -16     
- Partials     8135     8138    +3     
Flag Coverage Δ
Debug 70.89% <100.00%> (+<0.01%) ⬆️
production 64.34% <100.00%> (+<0.01%) ⬆️
test 90.74% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/Microsoft.ML.Mkl.Components/VectorWhitening.cs 81.79% <100.00%> (+0.90%) ⬆️
...Microsoft.ML.Tests/Transformers/NormalizerTests.cs 99.57% <100.00%> (+0.01%) ⬆️

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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