Skip to content

[FIX] ROCCurve::cutoffNeg iterates negatives to match its denominator (#9488 ML-21) - #9617

Merged
timosachsenberg merged 2 commits into
OpenMS:developfrom
timosachsenberg:fix/9488-roccurve-cutoffneg
Jul 14, 2026
Merged

timosachsenberg merged 2 commits into
OpenMS:developfrom
timosachsenberg:fix/9488-roccurve-cutoffneg

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Part of #9488 (POLS high-severity checklist — MATH / ML / COMPARISON).

[ML-21] ROCCurve::cutoffNeg — iterated positives but divided by the negative count

cutoffNeg() walked only the positive samples (if (cit->second)) while dividing the running count by neg_ (the number of negatives), so the returned cutoff was wrong (it mirrored the positive-side logic of cutoffPos).

Fix: iterate over negative samples (if (!cit->second)) to match the neg_ denominator, consistent with the sibling cutoffPos.

ABI: none (function body only).
Test: ROCCurve_test — cutoffNeg now returns a cutoff drawn from the negative score range.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Corrected the negative cutoff calculation so it now considers only negative samples, improving the accuracy of results.
    • Added clarifying notes to help explain the fix.
  • Tests

    • Added a deterministic test to confirm the negative cutoff returns a value from the negative-score range.

…OpenMS#9488 ML-21)

Part of OpenMS#9488 (POLS high-severity checklist — **MATH / ML / COMPARISON**).

### [ML-21] `ROCCurve::cutoffNeg` — iterated positives but divided by the negative count
`cutoffNeg()` walked only the **positive** samples (`if (cit->second)`) while dividing the running count by `neg_` (the number of negatives), so the returned cutoff was wrong (it mirrored the positive-side logic of `cutoffPos`).

**Fix:** iterate over **negative** samples (`if (!cit->second)`) to match the `neg_` denominator, consistent with the sibling `cutoffPos`.

**ABI:** none (function body only).
**Test:** `ROCCurve_test` — `cutoffNeg` now returns a cutoff drawn from the negative score range.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Fixed a logic bug in ROCCurve::cutoffNeg where the loop incorrectly filtered positive samples instead of negative samples, causing a mismatch with the neg_ denominator used in cutoff computation. Added a deterministic regression test verifying the corrected behavior.

Changes

cutoffNeg Bug Fix

Layer / File(s) Summary
Fix sample filter condition and validate with test
src/openms/source/ML/ROCCURVE/ROCCurve.cpp, src/tests/class_tests/openms/source/ROCCurve_test.cpp
Corrected the loop condition in cutoffNeg to select negative samples (!cit->second) instead of positive samples, matching the neg_ denominator, with inline comments explaining the fix; added a deterministic test constructing known negative/positive score data and asserting cutoffNeg(0.95) returns a value within the negative-score range.

Poem

A rabbit hopped through code so neat,
Found a bug where signs would cheat,
Flipped the guard from true to !,
Now negatives get their due, you see! 🐇
Tested well, the cutoff's tight,
Hop away — the fix is right! ✨

🚥 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%. 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 and accurately summarizes the main fix: cutoffNeg now iterates negatives to match its denominator.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown
Contributor Author

Adversarial review result: no blocking behavioral issue found in this pass.

Required source cleanup before merge: the added implementation/test comments include tracker references. Please remove those references from source comments and keep the comments focused on the negative-sample iteration contract. I did not run the tests locally.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/openms/source/ML/ROCCURVE/ROCCurve.cpp`:
- Around line 197-199: Remove the inline tracker reference from the ROCCurve
negative-sample comment and keep the wording focused on the iteration contract
only. Update the comment near the `cit->second` guard in `ROCCurve.cpp` so it
explains that the loop iterates over negative samples to match the division by
`neg_`, without mentioning `issue `#9488`` or `ML-21`.

In `@src/tests/class_tests/openms/source/ROCCurve_test.cpp`:
- Around line 81-93: Remove the tracker references from the comments in
ROCCurve_test so they no longer mention issue `#9488` or ML-21. Update the nearby
test comments around the ROCCurve::cutoffNeg setup to focus only on the behavior
being validated: that cutoffNeg(0.95) iterates over negatives and returns a
negative-class score, never a positive-class score.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3a332468-0af1-4eb7-ad46-a33db3566132

📥 Commits

Reviewing files that changed from the base of the PR and between 02545db and 29fc6b8.

📒 Files selected for processing (2)
  • src/openms/source/ML/ROCCURVE/ROCCurve.cpp
  • src/tests/class_tests/openms/source/ROCCurve_test.cpp

Comment on lines +197 to +199
// iterate over NEGATIVE samples (cit->second == false) to match the
// division by neg_; the guard was wrongly cit->second (issue #9488, ML-21)
if (!cit->second)

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.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Drop the tracker reference from the code comment.

The comment cites issue #9488, ML-21 inline in source. Per the PR review feedback, tracker references should be removed and the comment kept focused on the negative-sample iteration contract.

✏️ Suggested comment cleanup
-        // iterate over NEGATIVE samples (cit->second == false) to match the
-        // division by neg_; the guard was wrongly cit->second (issue `#9488`, ML-21)
+        // iterate over NEGATIVE samples (cit->second == false) to match the
+        // division by neg_
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// iterate over NEGATIVE samples (cit->second == false) to match the
// division by neg_; the guard was wrongly cit->second (issue #9488, ML-21)
if (!cit->second)
// iterate over NEGATIVE samples (cit->second == false) to match the
// division by neg_
if (!cit->second)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/openms/source/ML/ROCCURVE/ROCCurve.cpp` around lines 197 - 199, Remove
the inline tracker reference from the ROCCurve negative-sample comment and keep
the wording focused on the iteration contract only. Update the comment near the
`cit->second` guard in `ROCCurve.cpp` so it explains that the loop iterates over
negative samples to match the division by `neg_`, without mentioning `issue
`#9488`` or `ML-21`.

Comment on lines +81 to +93
// deterministic check that cutoffNeg picks a NEGATIVE-class score (issue #9488, ML-21)
ROCCurve rc2;
// negatives at low scores, positives at high scores
rc2.insertPair(0.10, false);
rc2.insertPair(0.20, false);
rc2.insertPair(0.30, false);
rc2.insertPair(0.40, false);
rc2.insertPair(0.70, true);
rc2.insertPair(0.80, true);
rc2.insertPair(0.90, true);
rc2.insertPair(0.95, true);
// with the fix, cutoffNeg(0.95) walks negatives only and returns a
// negative-class score (<= 0.40), never a positive-class score (>= 0.70)

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.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Drop the tracker reference from test comments.

Comments at Lines 81 and 92-93 cite issue #9488, ML-21. Per the PR review feedback, remove tracker references and keep the comments focused on the negative-sample iteration contract being tested.

✏️ Suggested comment cleanup
-  // deterministic check that cutoffNeg picks a NEGATIVE-class score (issue `#9488`, ML-21)
+  // deterministic check that cutoffNeg picks a NEGATIVE-class score
   ROCCurve rc2;
   // negatives at low scores, positives at high scores
   rc2.insertPair(0.10, false);
   rc2.insertPair(0.20, false);
   rc2.insertPair(0.30, false);
   rc2.insertPair(0.40, false);
   rc2.insertPair(0.70, true);
   rc2.insertPair(0.80, true);
   rc2.insertPair(0.90, true);
   rc2.insertPair(0.95, true);
   // with the fix, cutoffNeg(0.95) walks negatives only and returns a
-  // negative-class score (<= 0.40), never a positive-class score (>= 0.70)
+  // negative-class score (<= 0.40), never a positive-class score (>= 0.70)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// deterministic check that cutoffNeg picks a NEGATIVE-class score (issue #9488, ML-21)
ROCCurve rc2;
// negatives at low scores, positives at high scores
rc2.insertPair(0.10, false);
rc2.insertPair(0.20, false);
rc2.insertPair(0.30, false);
rc2.insertPair(0.40, false);
rc2.insertPair(0.70, true);
rc2.insertPair(0.80, true);
rc2.insertPair(0.90, true);
rc2.insertPair(0.95, true);
// with the fix, cutoffNeg(0.95) walks negatives only and returns a
// negative-class score (<= 0.40), never a positive-class score (>= 0.70)
// deterministic check that cutoffNeg picks a NEGATIVE-class score
ROCCurve rc2;
// negatives at low scores, positives at high scores
rc2.insertPair(0.10, false);
rc2.insertPair(0.20, false);
rc2.insertPair(0.30, false);
rc2.insertPair(0.40, false);
rc2.insertPair(0.70, true);
rc2.insertPair(0.80, true);
rc2.insertPair(0.90, true);
rc2.insertPair(0.95, true);
// with the fix, cutoffNeg(0.95) walks negatives only and returns a
// negative-class score (<= 0.40), never a positive-class score (>= 0.70)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/tests/class_tests/openms/source/ROCCurve_test.cpp` around lines 81 - 93,
Remove the tracker references from the comments in ROCCurve_test so they no
longer mention issue `#9488` or ML-21. Update the nearby test comments around the
ROCCurve::cutoffNeg setup to focus only on the behavior being validated: that
cutoffNeg(0.95) iterates over negatives and returns a negative-class score,
never a positive-class score.

@timosachsenberg
timosachsenberg merged commit c367b63 into OpenMS:develop Jul 14, 2026
38 checks passed
timosachsenberg added a commit that referenced this pull request Jul 15, 2026
, #9740 (#9744)

Backfills changelog entries for a SQLite private-dependency change, a
ROCCurve::cutoffNeg fix, a pyOpenMS Windows NO_DEPENDENCIES test fix,
and the Ghostscript-to-MathJax documentation build change, none of
which had CHANGELOG entries yet.


Claude-Session: https://claude.ai/code/session_012hWmgLm1tVqhrwzBZsFN1X

Co-authored-by: Claude <[email protected]>
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