Repository navigation
fix: make error capture ties order invariant - #602
WilliamK112 wants to merge 1 commit into
Conversation
Signed-off-by: Ching-Wei Kang <ckang53@wisc.edu>
vawsgit
left a comment
There was a problem hiding this comment.
needs changes
One blocker: the PR has no CHANGELOG.md entry. The fix itself is correct and I would approve it once the entry is added.
Blocker (medium): add a ### Fixed entry under [Unreleased] in CHANGELOG.md.
RELEASING.mdrequires one "when it fixes a bug someone could have hit" and when a PR "changes ... an exported format" (). The PR template checklist asks for the same (Lines 100 to 104 in e4b6fef
).stickler/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md
Lines 36 to 39 in e4b6fef
- This PR does both. It fixes #601 (order-dependent
errors_found), and it changes the type ofbudgets["<b>"]["errors_found"]from alwaysinttoint | float( ). - Measured at
e4b6fef: 10 pairs all at confidence 0.9 with 7 errors,ErrorCaptureAtBudgetMetric(budgets=[0.1, 0.5, 1.0]), giveserrors_found=0.7000000000000001(float),3.5(float),7(int). A consumer that formats with:dor validates an integer schema gets a float without notice. - Suggested entry: "
ErrorCaptureAtBudgetMetricno longer depends on input order when a review budget cuts through a group of tied confidences. In that caseerrors_foundis now a fractional expected count (a float) instead of an integer that varied between runs."
Verified and cleared
- Full suite at head: 5568 passed, 13 skipped, 1 xfailed, matching the PR body. The 13 skips are missing
bert/strandsextras or unimplemented features, none in the confidence tests.test_confidence_metrics.py: 85 passed. - #601 reproduction: 200 shuffled seeds all give
errors_found1.5 and gain 1.0. The result no longer depends on order. - Exact reference check: 4000 random datasets (n 1 to 30, coarse confidence levels, all-tied cases, 0.0/1.0,
0.1+0.2against0.3) across budgets 0.01 to 1.0, compared against aFractioncomputation of the expected count. 0 mismatches, and 0 changes across 3 shuffles of each dataset. errors_foundstays anintin every case where the cutoff does not split a tie, as the docstring says.- Edge cases: budget ≥ n and n = 1 stop at the
k < nguard; a tied group always has at least 2 members, so the fraction cannot divide by zero; NaN and inf are rejected whenConfidencePairis built. - Mutation tests: with the
devversion ofmetrics.pyand the new test kept, the new test fails (assert 2 == 1.5). Changing the denominator totie_end - tie_start + 1also fails it. - No other code in
src/readserrors_found. The README sentence matches the behaviour. - Not stale:
devhas not changed the three touched files since the merge base, so merging undoes nothing.
Optional, not blocking (inline comments below): floating-point noise in the fraction, and a test gap for the backward tie scan.
| "errors_found": int, | ||
| # Float only when the cutoff splits a confidence tie; | ||
| # otherwise this remains an integer count. | ||
| "errors_found": int | float, |
There was a problem hiding this comment.
Blocker: this changes the exported type of errors_found from always int to int | float. RELEASING.md ("What belongs in the changelog") asks for a CHANGELOG.md entry for an exported-format change and for a user-visible bug fix. Please add a ### Fixed entry under [Unreleased] that says errors_found can now be a float when the budget cutoff splits a confidence tie.
| errors_in_tie = sum( | ||
| 1 for p in sorted_pairs[tie_start:tie_end] if not p.is_match | ||
| ) | ||
| reviewed_tie_fraction = (k - tie_start) / (tie_end - tie_start) |
There was a problem hiding this comment.
Optional, not blocking: dividing first gives float noise. 10 tied pairs with 7 errors at budget 0.1 return 0.7000000000000001. Multiplying first, errors_in_tie * (k - tie_start) / (tie_end - tie_start), returns exactly 0.7 for that case. The result is order-invariant either way.
| and sorted_pairs[tie_start - 1].confidence | ||
| == cutoff_confidence | ||
| ): | ||
| tie_start -= 1 |
There was a problem hiding this comment.
Optional, not blocking: no test runs this backward scan. In the new test the tied group starts exactly at k - 1. Replacing tie_start -= 1 with break leaves all 8 TestErrorCaptureAtBudget tests passing, while a brute-force comparison then finds 14,899 wrong results. A case with two or more tied pairs inside the reviewed set would pin it.
Issue #, if available:
Fixes #601
Description of changes:
errors_foundvalues when the cutoff does not split a tieValidation:
uv run ruff check src/stickler/structured_object_evaluator/models/confidence/metrics.py tests/structured_object_evaluator/test_confidence_metrics.py;uv run pytest tests/ -q(5568 passed, 13 skipped, 1 xfailed)By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.