Repository navigation
[Math] Make quantile1st/quantile3rd total for n<3; fix SummaryStatistics on small inputs (#9659) - #9664
Conversation
…ics on small inputs (#9659) Math::quantile1st/quantile3rd took the median of an empty half for input ranges of size 1 or 2, throwing Exception::InvalidRange. Math::SummaryStatistics calls both unconditionally and inherited the crash (e.g. a ProteomicsLFQ acceptor run with exactly 2 donor features aborted via PIP-ECHO, PR #9647). - quantile1st: return the minimum for size < 3 (the lower half is empty); quantile3rd: return the maximum. This matches the median-of-halves convention and is continuous with the method's own size-3 and size-4 results, which already yield min/max. - SummaryStatistics: variance divides by (n-1) and is undefined for a single value; report 0.0 (as in the empty case) instead of a silent NaN now that the quantile calls no longer throw for n==1. - Add StatisticFunctions_test coverage for quantile1st/quantile3rd at n = 1..4 and empty, plus a new SummaryStatistics section (previously untested). The n>=3 code path is unchanged, so the pinned quantile values and downstream reference outputs are unaffected. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesStatistic edge-case fixes
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Documents PRs that landed after the last CHANGELOG update (#9656): - #9647 PIP-ECHO match-between-runs algorithm in ProteomicsLFQ - #9666 ProteomicsLFQ mzTab crash on non-string search settings - #9658 ProteinQuantifier wrong per-file split on merged ID runs (fixes #5518) - #9664 Math::quantile1st/3rd crash on 1–2 element inputs (fixes #9659) Claude-Session: https://claude.ai/code/session_01DYJ6LYHiJADSGjCkfBBJiN Co-authored-by: Claude <[email protected]>
Summary
Fixes #9659.
Math::quantile1st,Math::quantile3rd, and thereforeMath::SummaryStatisticsthrewException::InvalidRangefor input ranges of size 1 or 2 (they take the median of a half of the range, which is empty for n ≤ 2). For n ≥ 3 they already worked. This is a general-purpose statistics utility, so any caller handed a 1–2 element range was a latent crash — it surfaced as a ProteomicsLFQ acceptor run with exactly 2 donor features aborting via PIP-ECHO (#9647).Changes (
src/openms/include/OpenMS/MATH/StatisticFunctions.h)quantile1st: forsize < 3return the minimum (the lower half is empty).quantile3rd: forsize < 3return the maximum (the upper half is empty).SummaryStatistics:variancedivides by(n-1)and is undefined for a single value. Now that the quantile helpers no longer throw for n==1, guard it to report0.0(as in the empty case) instead of a silentNaN.@exception ... NULLcorrected toempty).Why min / max (not Type-7 interpolation)
The fix preserves the existing algorithm's behavior. I cross-checked the convention against NumPy (all 9 Hyndman–Fan types), Python's
statistics.quantiles, and the median-of-halves variants:Crucially, OpenMS's own algorithm already returns min/max at n = 3 and n = 4, so extending n ≤ 2 to min/max is continuous with existing behavior rather than a new convention. Routing through the newer interpolation-based
quantile(begin, end, q)helper was rejected because it produces different values for n ≥ 3 (e.g. n=10 → 7.25/14.5 vs. the pinned 6.5/15.5) and would change the existing test and downstream reference outputs.The n ≥ 3 code path is byte-identical, so pinned quantile values and reference outputs are unaffected.
Tests (
StatisticFunctions_test.cpp)quantile1st/quantile3rdat n = 1, 2 (sorted and unsorted), 3, 4, and empty-still-throws.SummaryStatisticssection at n = 1, 2, 3, and empty (this class had no prior test coverage).Verified:
StatisticFunctions_test,FileInfo_test,PosteriorErrorProbabilityModel_test(direct helper callers), andTargetedExperiment_test(SummaryStatisticsconsumer) all pass against a freshly rebuilt library.Note (out of scope)
The even-n
-1/+1offsets make these helpers a slightly non-standard median-of-halves variant (n=4 → min/max where Moore-McCabe/Tukey give 1.5/3.5). That quirk is load-bearing for the existing pinned test values, so it is intentionally left unchanged here.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
0.0when there is not enough data.Tests