fix(types): refuse NaN and out-of-range probabilities; stop the Brier floor indexing past a distribution - #78
Merged
Conversation
…rier floor indexing past a distribution
Prediction checked that a distribution summed to about 1 but not that each
entry was a probability. {"a": nan, "b": 1.0} and {"a": 1.5, "b": -0.5}
both passed, as did a NaN latency; downstream, a NaN makes ECE and Brier
silently NaN and a negative entry corrupts the floors. Each entry must now
be finite and in [0, 1], and the error names the option. latency_ms must
be finite.
multiclass_brier_floor drew the gold label with searchsorted over the raw
cumulative sum, so a distribution summing to 0.9995 (which Prediction
allows) indexed one past the last option whenever the uniform draw landed
above the sum. The cumulative sum is now normalized and the index clamped;
a distribution that sums to 1 draws exactly as before, so no existing
figure moves.
Fixes #31. Fixes #32.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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.
Fixes #31. Fixes #32.
#32:
Predictionaccepted impossible probabilities.{"a": nan, "b": 1.0}and{"a": 1.5, "b": -0.5}both passed, and so did a NaN latency.latency_msmust be finite.#31:
multiclass_brier_floorcould index past the last option.searchsortedover the raw cumulative sum. A distribution summing to 0.9995, whichPredictionallows, then indexed one past the last option whenever the uniform draw landed above the sum.Checked
mainand pass now: NaN and negative distribution entries are refused, NaN and inf latency are refused, and the floor accepts a 0.9995 distribution.ruff,mypy --strict, the fullpytestsuite, and the site build all pass.🤖 Generated with Claude Code