Repository navigation
fix(eval): sign-flip interval ends, mean and mde of tiny deltas keep 2 significant digits - #1227
Conversation
…2 significant digits (intel#817) A sign-flip row whose deltas are below 5e-5 printed both interval ends and `delta.mean` as 0.0001 (`_rounded` rounded to 4 places and moved an end that landed on 0 to ±0.0001), so the interval was a point that did not hold the true mean, and `mde` was 0.0 because `compare._round` keeps 6 places. Deltas of 2e-12 to 9e-12 printed `[0.0001, 0.0001]` around a mean of 0.0001 for a row whose p is 0.0078. An end, `delta.mean` of `repo compare` (still held inside the ends by `within`) and `mde` that their 4 places (6 for `mde`) would put at 0 now keep 2 significant digits, as `round_mean` does for the arms mean, through one shared helper `round_off_zero`. A non-zero end keeps its side of 0, no `-0.0` is printed, and every value whose rounding is not 0 prints as before; `exact` output and the `includes_zero` verdicts are unchanged. The tests that pinned ±0.0001 and a mean of 0.0 now pin the 2-digit values, and the docs and docstrings state the new rule. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 7 selected item(s). CI at Review details
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1227 +/- ##
==========================================
- Coverage 96.07% 96.07% -0.01%
==========================================
Files 496 495 -1
Lines 65209 65353 +144
Branches 11317 11327 +10
==========================================
+ Hits 62652 62789 +137
- Misses 1583 1584 +1
- Partials 974 980 +6
🚀 New features to boost your workflow:
|
napetrov
left a comment
There was a problem hiding this comment.
Change class: CONTRACT (head 008b2f2)
- Contract: changed (count signal only, no file:line)
- Responsibility: none
- Dependency: none
- Review depth: check the changed surface: callers, docs, tests pin new behaviour
- Coverage gaps: none
The tiny example from #817 now returns a mean of 4.5e-12 inside the interval [2.3e-12, 6.7e-12]. The 50 focused comparison and sign-flip tests passed, and CI is green. One release-note clarification is inline.
…gment Settles the review note on the fragment: `exact` keeps the unrounded arms record and the full-precision mean and p, but `sign_flip_summary(..., exact=True)` still rounds the interval ends and `mde`, so those change for tiny deltas as well. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@napetrov (#1227 (review)): Approval with a recap of its checks; its one inline point is thread 4699605618, answered above. |
Summary
A sign-flip row whose deltas are below 5e-5 prints its interval ends and its mean as
0.0001, andrepo compareprints itsmdeas0.0, so the printed interval is a point that does not hold the true mean. Onmain:mainpaired_test([2e-12, 4e-12, 3e-12, 5e-12, 6e-12, 9e-12, 7e-12, 8e-12], [1e-12] * 8)(p 0.0078)delta_mean0.0001,ci_lo0.0001,ci_hi0.0001repo comparerow, baseline 1e-12, deltas 1e-12 to 6e-12 (p 0.007812)delta{'mean': 0.0001, 'lo': 0.0001, 'hi': 0.0001},mde0.0[4e-5] * 6deltamean, lo and hi 0.0001[4e-5] * 5 + [-1e-5]deltamean 0.0, lo -0.0001, hi 0.0001The cause is
sign_flip._rounded, which rounds an end to 4 places and moves one that lands on 0 to ±1e-4;delta.meanofrepo compareis held inside those ends, andcompare._roundkeeps 6 places formde.The issue offers two fixes; this takes the first: a value that 4 places (6 for
mde) would put at 0 keeps 2 significant digits instead, asround_meanalready does for the arms mean. It keeps the field a plain JSON float, where printing the unrounded value in scientific notation would change the form of the field for every reader, and it keeps the end on its side of 0 (2 significant digits of a non-zero finite float are never 0).Closes #817
Three places of the same class are not fixed here: the per-task values and arm means of
repo comparebelow 5e-7 print as0.0(#1224),delta_stdof the arms track below 0.005 prints as0.0(#1225), and the inconclusive note prints a tinymdeas±0.000(#1226).Changes
dokimi/dokimi/eval/sign_flip.py: newround_off_zero(value, places)(the value atplaces, or at 2 significant digits where that would be 0.0, no-0.0);_roundeduses it, soci_lo/ci_hiof the arms track (sign_flip_row) and thelo/hiofrepo compareget the new rule. Thewithinandsign_flip_intervaldocstrings say it.dokimi/dokimi/repos/compare.py:sign_flip_summaryroundsdelta.mean(when notexact) through the same helper, still held inside the ends bywithin, andmdethrough_round_off_zero(6 places, or 2 significant digits where that would be 0)._rounditself is unchanged.dokimi/dokimi/eval/stats.py:_describe_deltasdocstring.dokimi/docs/repo-evaluation-contract.md: the rule for the ends,delta.meanandmde.tests/test_repo_compare_interval.pyandtests/test_arms_sign_flip.pypin the issue's two repros, a negative tiny end, an end between 5e-5 and 1e-4 and above (4 places, the same as on the merge base), and a 6-placemde. Existing tests that pinned the old values are changed:test_rounding_keeps_an_end_on_its_side_of_zeronow asserts_rounded(±3e-5) == ±3e-5;test_a_tiny_mean_stays_inside_its_interval_kept_off_zeroasserts(±4e-5,) * 3for six deltas of±4e-5, and lo, mean, hi(-1e-5, 3.2e-5, 4e-5)for[4e-5] * 5 + [-1e-5](the mean was 0.0 between ends of ±0.0001);test_a_mean_rounded_to_zero_is_zero_not_negative_zeroasserts the mean of[-1e-5, 0, 0]is-3.3e-6(it was 0.0) and keeps its-0.0check on[1e-5, -1e-5, 0.0], whose mean is 0.0.exactkeeps the unrounded arms record and the full-precision mean and p, whilesign_flip_summary(..., exact=True)still rounds the interval ends andmde, so those change for tiny deltas too.Risk
Rows whose end,
delta.meanormdeis below 5e-5 (below 5e-7 formde) print other numbers than before: a storedrepo compareJSON or arms result read side by side with a new one differs on those rows. Every value whose 4-place (6-place formde) rounding is not 0 prints with the same 4 places (6 formde) as on the merge base,exactoutput keeps the unrounded arms record and the full-precision mean and p, an open end staysnull, andinterval_p_disagreeandincludes_zeroverdicts do not change. No schema changes: the fields stay floats.Open PRs on the same files change other parts of them: #1199 changes
_arm_warningsincompare.py, and it and #1138, #1155, #1192, #1195, #1201 and #1223 edit other sections ofrepo-evaluation-contract.md, none at thedelta.meanparagraph this PR rewrites, so a merge with any of them meets no conflict.Testing
On a Linux review host, at
e2fd9442(onmain602de14):make ci-local: 38 passed, 0 failed, 15 skipped (docker, conda-forge, semgrep, fuzz, the jobs that do not run on a PR, the Claude Code pin, the other Python versions). 28384 tests passed, 23 skipped; changed-line coverage 100%; the mutation run of the changed lines has no survivor.main's code (test_repo_compare_interval.py: 6 failed, 14 passed;test_arms_sign_flip.py: 2 failed, 28 passed) and pass here._rounded, the olddelta.meanrounding,mdethrough_round, no+ 0.0, 2 significant digits everywhere, and 7 places formde.Open questions
None. The issue calls the choice between its two fixes a decision for the maintainers; this takes the first by the precedent of
round_mean.Revert
A plain revert restores the ±0.0001 and
0.0printing of tiny rows. Nothing is stored.Checklist
pytestpassesruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to.github/.licenserc.yaml)