Skip to content

[FIX] ProteomicsLFQ: actually shuffle the quant-score SVM training sample - #9982

Merged
timosachsenberg merged 1 commit into
developfrom
fix/9981-proteomicslfq-shuffle-quant-svm-training
Aug 28, 2026
Merged

timosachsenberg merged 1 commit into
developfrom
fix/9981-proteomicslfq-shuffle-quant-svm-training

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #9981

Problem

In ProteomicsLFQ's quantification-score SVM filter, Math::RandomShuffler shuffler; was constructed but never called. randomized_indices was iota-filled and then iterated in FeatureMap order:

Math::RandomShuffler shuffler;                 // no call site
std::vector<size_t> randomized_indices(fm.size());
std::iota(randomized_indices.begin(), randomized_indices.end(), 0);

for (auto& i : randomized_indices) { ... }

The loop caps the SVM training set at 1000 targets and 1000 decoys, so without the shuffle those were simply the first 1000 of each in FeatureMap (RT) order, biasing training towards early-eluting features instead of a random subsample.

Fix

Shuffle the index vector before use, with an explicit fixed seed:

Math::RandomShuffler shuffler(42);
std::vector<size_t> randomized_indices(fm.size());
std::iota(randomized_indices.begin(), randomized_indices.end(), 0);
shuffler.portable_random_shuffle(randomized_indices.begin(), randomized_indices.end());

Same pattern as FFIDAlgoExternalIDHandler::getRandomSample_, which does exactly this for its SVM training selection.

On determinism

The issue flagged that fixing this could make the path non-deterministic. It does not: RandomShuffler's default ctor is = default, so rng_ was already a default-seeded boost::mt19937_64. Passing 42 explicitly just documents that (cf. ProSEAlgorithm.cpp:1123) and keeps the selection reproducible across runs.

Index consistency

The shuffle permutes both sides consistently, so there is no row/feature desync:

  • predictors and labels rows are filled while iterating randomized_indices;
  • SimpleSVM::predict(predictions) with an empty index list returns one prediction per observation in row order (src/openms/source/ML/SVM/SimpleSVM.cpp);
  • the write-back loop iterates the same randomized_indices.

So row i of predictors/labels/predictions always refers to fm[randomized_indices[i]]. A comment in the code records this invariant.

Test impact

None. The path is gated on filter_by_quant_scores, i.e. -feature_with_id_min_score > 0 (default 0.0). No test or .ini under src/tests/ or share/ sets feature_with_id_min_score or feature_without_id_min_score, so all existing reference outputs are produced with this branch disabled.

Verified to compile cleanly (-fsyntax-only with the target's real build flags).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Made training-example selection reproducible across runs while preserving randomized sampling.
    • Reduced potential bias from selecting examples solely according to retention-time order.

…mple

The `Math::RandomShuffler` in the quantification-score filter was
constructed but never called, so `randomized_indices` was `iota`-filled
and iterated in FeatureMap order. The loop caps the SVM training set at
1000 targets and 1000 decoys, which therefore picked the first 1000 of
each in RT order rather than a random subsample, biasing training
towards early-eluting features.

Shuffle the index vector before use. The seed is fixed (42) so the
selection stays reproducible across runs -- the previously default-
constructed shuffler was already deterministic, this just makes it
explicit (same pattern as ProSEAlgorithm).

The shuffle is consistent on both sides: predictor/label rows are filled
while iterating `randomized_indices`, `SimpleSVM::predict` returns one
prediction per observation in row order, and the write-back iterates the
same index vector, so row i always maps to fm[randomized_indices[i]].

No test impact: the path is gated on `-feature_with_id_min_score > 0`
(default 0.0) and no test or ini enables it.

Fixes #9981

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1071c330-abf9-4a2c-9d0f-c6c05608a4f0

📥 Commits

Reviewing files that changed from the base of the PR and between 700d16b and 710d03b.

📒 Files selected for processing (1)
  • src/topp/ProteomicsLFQ.cpp

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

Changes

Quantification-score training selection

Layer / File(s) Summary
Seeded training-example shuffle
src/topp/ProteomicsLFQ.cpp
Math::RandomShuffler now uses seed 42 when shuffling feature indices for target and decoy SVM training examples. The selection remains limited to 1000 examples per class and becomes reproducible.

Suggested reviewers: cbielow, copilot, pjones

Poem

A rabbit shuffled rows with care
With seed forty-two tucked there
Targets and decoys found their place
The same crisp order in every race
SVM training hops along
Reproducible, neat, and strong

Merge Risk: ⚪ Minimal · up to 710d0

The change uses a fixed seed to select a randomized subset for quantification-score SVM training while preserving reproducibility and existing interfaces. No actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: shuffling the ProteomicsLFQ quant-score SVM training sample.
Linked Issues check ✅ Passed The change satisfies issue #9981 by shuffling the training-sample indices with a reproducible seed before selecting capped target and decoy samples.
Out of Scope Changes check ✅ Passed The changes are limited to the quant-score SVM training-sample selection and directly support the linked issue objective.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/9981-proteomicslfq-shuffle-quant-svm-training

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@timosachsenberg
timosachsenberg merged commit 877465f into develop Aug 28, 2026
36 checks passed
@timosachsenberg
timosachsenberg deleted the fix/9981-proteomicslfq-shuffle-quant-svm-training branch August 28, 2026 15:46
pull Bot pushed a commit to bgruening/OpenMS that referenced this pull request Aug 29, 2026
…fix entry

The median-FWHM entry added by OpenMS#9985 was missing its own PR citation.
The quant-score SVM training shuffle fix (OpenMS#9981/OpenMS#9982) had no entry at all.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011BcssmGej97WFDdDWW7LhW
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.

[TOPP] ProteomicsLFQ: Math::RandomShuffler in the quantification-score filter is constructed but never used

1 participant