1202: Fix interval_coverage() floating point matching and NaN scores for quantile levels 0 and 1#1217
Draft
nikosbosse wants to merge 1 commit into
Draft
1202: Fix interval_coverage() floating point matching and NaN scores for quantile levels 0 and 1#1217nikosbosse wants to merge 1 commit into
nikosbosse wants to merge 1 commit into
Conversation
…antile levels 0 and 1 (#1202) interval_coverage() now rounds quantile levels to 10 decimal places before checking for the required quantiles, so seq()-generated levels no longer trigger a spurious missing-quantile error. interval_score() applies the indicator before the 2 / alpha factor and cancels the alpha / 2 weight analytically, so quantile levels 0 and 1 (interval_range = 100, alpha = 0) yield finite scores instead of NaN, restoring the WIS = mean quantile score identity. Unweighted scores return Inf when the observation falls outside a 100% interval. quantile_score(weigh = FALSE) receives the analogous fix. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1217 +/- ##
=======================================
Coverage 98.15% 98.15%
=======================================
Files 41 41
Lines 2225 2226 +1
=======================================
+ Hits 2184 2185 +1
Misses 41 41 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Collaborator
Author
|
Automated review (Claude Fable, directed by @nikosbosse): Verification
Non-blocking observations
Verdict: approve. |
nikosbosse
marked this pull request as draft
July 18, 2026 13:53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR closes #1202.
Two related edge-case bugs in the quantile-based metrics:
interval_coverage()errored onseq()-generated quantile levels. The check for the required quantile levels used an exact floating point comparison (necessary_quantiles %in% quantile_level), so e.g.interval_coverage(observed, predicted, seq(0.05, 0.95, 0.05), interval_range = 30)aborted with "the 0.35 and 0.65 quantiles are required" even though those quantiles were present (0.35 %in% seq(0.05, 0.95, 0.05)isFALSE). The fix rounds both sides to 10 decimal places before matching, consistent with the package's existing convention (e.g. inas_forecast_quantile()).wis(),interval_score()andquantile_score(weigh = FALSE)returnedNaNfor quantile levels 0 and 1. These levels are explicitly permitted by input validation and occur in real hub data ("min"/"max" quantiles), but they form a 100% interval withalpha = 0, and the penalty terms2 / alpha * (bound - observed) * indicatorevaluated toInf * 0 = NaN. This broke the documented WIS = mean quantile score identity:wis(5, matrix(c(1, 3, 5, 7, 9), nrow = 1), c(0, 0.25, 0.5, 0.75, 1))returnedNaNwhilequantile_score()returned0.4. The fix applies the indicator before the2 / alphafactor and cancels2 / alpha * alpha / 2analytically in the weighted case; in the unweighted case, zero penalties stay zero and the score isInfwhen the observation falls outside a 100% interval (mathematically correct, per maintainer decision).quantile_score(weigh = FALSE)gets the analogous fix (a zero weighted score maps to a zero unweighted score instead of0/0). Outputs for all other interval ranges are unchanged.Tests were written first and failed on the unfixed code:
After the fix, the full test suite passes (0 failed, 920 passed).
Dev note: bug identified by an LLM audit (#1189); fix and tests implemented with LLM support, directed by @nikosbosse.
Checklist
lintr::lint()on the changed files; no new lints were introduced.