From 27b5aae998cf5bab78f20a08e1d218e5a59b7e12 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Thu, 26 Nov 2026 13:22:50 +0000 Subject: [PATCH 1/3] fix(repo): repo compare keeps 2 significant digits of per-task values and arm means below 5e-7 (#1224) compare._round kept 6 places, so every per-task baseline, treatment and delta and the arm means baseline_mean and treatment_mean below 5e-7 printed as 0.0 beside a non-zero delta, interval and p. _round now goes through round_off_zero(value, 6): a value that 6 places would put at 0 keeps 2 significant digits and its sign, a zero stays 0.0, and a non-finite value is still None. Values of 5e-7 and above print as before. mde, the one field that used the separate _round_off_zero wrapper, now uses _round, and the wrapper is removed. The "changed:" line of format_compare read the rounded task deltas to leave out noise, so a delta of 4e-7 would now have been listed as +0.00. It tests round(delta, 6) instead, which lists the same tasks as before. Signed-off-by: Anton Volkov --- ...0261126_140000_compare-tiny-task-values.md | 8 ++++++ dokimi/docs/repo-evaluation-contract.md | 3 ++- dokimi/dokimi/repos/compare.py | 12 +++------ dokimi/tests/test_repo_compare_reading.py | 27 ++++++++++++++++++- 4 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 dokimi/changelog.d/20261126_140000_compare-tiny-task-values.md diff --git a/dokimi/changelog.d/20261126_140000_compare-tiny-task-values.md b/dokimi/changelog.d/20261126_140000_compare-tiny-task-values.md new file mode 100644 index 000000000..65ce6127b --- /dev/null +++ b/dokimi/changelog.d/20261126_140000_compare-tiny-task-values.md @@ -0,0 +1,8 @@ + + +### Fixed + +- **`repo compare` no longer prints a per-task `baseline`, `treatment` or `delta`, or an arm mean, below 5e-7 as `0.0`** — a value that 6 places would put at 0 now keeps 2 significant digits and its sign, as `mde` and the interval ends already do: eight tasks with baseline `1e-12` print `1e-12`, not `0.0`, in `tasks` and `baseline_mean`. Values of 5e-7 and above print as before, and the keys and types are unchanged. A stored `repo compare` JSON differs from a new one on such values. diff --git a/dokimi/docs/repo-evaluation-contract.md b/dokimi/docs/repo-evaluation-contract.md index c039503d9..656f6e57c 100644 --- a/dokimi/docs/repo-evaluation-contract.md +++ b/dokimi/docs/repo-evaluation-contract.md @@ -2783,7 +2783,8 @@ python cli.py repo compare repo-runs/authoring --baseline guidance:none --metric non-zero end that would print as `0.000` at 2 significant digits (`+0.0002`), so it keeps its side of 0. The ends and `delta.mean` are printed at 4 places, or at 2 significant digits where 4 places would give 0, so a non-zero one is never `0.0`: six deltas of `4e-5` give `4e-05` for the mean and both ends. `delta.mean` stays - inside those ends. `mde` is at 6 places, or at 2 significant digits where 6 places would give 0. + inside those ends. `mde`, the per-task `baseline`, `treatment` and `delta` and the arm means `baseline_mean` and + `treatment_mean` are at 6 places, or at 2 significant digits where 6 places would give 0. A `process` count, `first_prompt_tokens` or `first_useful_*` only one arm reports for the shared tasks of a (treatment, model) is not compared; a warning names it. When neither arm reports it (a batch run before `repo run` recorded it), the row is absent. diff --git a/dokimi/dokimi/repos/compare.py b/dokimi/dokimi/repos/compare.py index b856b2581..d1f03aeb5 100644 --- a/dokimi/dokimi/repos/compare.py +++ b/dokimi/dokimi/repos/compare.py @@ -618,7 +618,7 @@ def sign_flip_summary(pairs: list[dict[str, Any]], measure: str = "gate", seed: "p": p, "p_holm": None, "p_holm_floor": None, - "mde": _round_off_zero(min_detectable(sd, len(deltas))) if sd > EPS * tie_scale(changed) and reachable else None, + "mde": _round(min_detectable(sd, len(deltas))) if sd > EPS * tie_scale(changed) and reachable else None, "interval_p_disagree": p is not None and includes_zero(lo, hi) == (p < ALPHA), "up": sum(d > w for d, w in zip(deltas, widths, strict=True)), "down": sum(d < -w for d, w in zip(deltas, widths, strict=True)), @@ -647,8 +647,7 @@ def format_compare(summary: dict[str, Any]) -> str: f"{r['up']}/{r['down']}/{r['tied']}") for r in rows: if r["measure"] in PRIMARY: - # the tasks hold rounded values: this line follows the printed deltas, which are 0 or 1e-6 and more - moved = [t for t in r["tasks"] if abs(t["delta"]) > EPS] + moved = [t for t in r["tasks"] if round(t["delta"], 6)] # below 5e-7 is float noise, not a change if moved: lines.append(f" {r['measure']} changed: " + ", ".join( f"{t['task']} {t['delta']:+.2f}" for t in sorted(moved, key=lambda t: t["delta"]))) @@ -776,15 +775,10 @@ def _mean(values: list[Any]) -> float | None: def _round(value: float | None) -> float | None: + """``value`` at 6 places, or at 2 significant digits where that would be 0.0; ``None`` for a non-finite one.""" if value is None: return None number = float(value) # a numpy float64 would warn on overflow while rounding - return round(number, 6) if math.isfinite(number) else None - - -def _round_off_zero(value: float) -> float | None: - """:func:`_round`, but a value it would put at 0.0 keeps 2 significant digits.""" - number = float(value) return round_off_zero(number, 6) if math.isfinite(number) else None diff --git a/dokimi/tests/test_repo_compare_reading.py b/dokimi/tests/test_repo_compare_reading.py index febef494a..ea95f8ae9 100644 --- a/dokimi/tests/test_repo_compare_reading.py +++ b/dokimi/tests/test_repo_compare_reading.py @@ -6,13 +6,14 @@ from __future__ import annotations import json +import math import statistics from pathlib import Path import pytest from dokimi.cli import build_parser -from dokimi.repos.compare import CompareError, compare, format_compare, min_detectable +from dokimi.repos.compare import CompareError, _round, compare, format_compare, min_detectable, sign_flip_summary from dokimi.repos.runner import cell_name from test_repo_compare import _cell, _row @@ -360,3 +361,27 @@ def test_a_descriptive_p_below_005_is_named_as_uncorrected(tmp_path): assert not any(line.startswith(" turns: the interval") for line in lines) assert (" p < 0.05 on turns: descriptive rows, their p uncorrected and outside Holm's family, which covers " "gate and score only") in lines + + +def _pairs_at(base: float, deltas: list[float]) -> list[dict]: + return [{"task": f"t{i}", "baseline": base, "treatment": base + d, "delta": d} for i, d in enumerate(deltas)] + + +def test_per_task_values_and_arm_means_below_5e7_keep_two_significant_digits(): + row = sign_flip_summary(_pairs_at(1e-12, [1e-12, 2e-12, 3e-12, 4e-12, 5e-12, 6e-12, 2.5e-12, 3.5e-12])) # #1224 + assert row["tasks"][0] == {"task": "t0", "baseline": 1e-12, "treatment": 2e-12, "delta": 1e-12} + assert row["baseline_mean"] == 1e-12 and row["treatment_mean"] == 4.4e-12 and row["delta"]["mean"] == 3.4e-12 + + +def test_the_changed_line_still_leaves_out_a_task_delta_below_5e7(tmp_path): + _score_tasks(tmp_path / "b", [4e-7, 0.5, 0.25], 0.25) # 4e-7 printed as 0.0 before the tasks kept 2 significant digits + lines = format_compare(compare([tmp_path / "b"], "guidance:none")).splitlines() + assert " score changed: review_2 +0.25, review_1 +0.50" in lines + + +@pytest.mark.parametrize(("value", "printed"), [(-1e-12, -1e-12), (4e-7, 4e-7), (0.1234567, 0.123457), (0.0, 0.0), + (1.234e-9, 1.2e-9)]) +def test_round_keeps_six_places_and_a_sign_where_they_do_not_give_zero(value, printed): + assert _round(value) == printed + assert math.copysign(1.0, _round(value)) == math.copysign(1.0, printed) # a zero stays +0.0, never -0.0 + assert math.copysign(1.0, _round(-0.0)) == 1.0 From 0d2db693350bafc74313aab613b6bca2cbd8643f Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Thu, 26 Nov 2026 13:23:18 +0000 Subject: [PATCH 2/3] fix(eval): arms delta_std below 0.005 keeps 2 significant digits (#1225) _describe_deltas printed delta_std as round(d_sd, 2), so a spread under 0.005 was 0.0 beside a non-zero delta_mean, cohens_d and interval. delta_std now goes through round_off_zero(d_sd, 2), the helper round_mean is built on: a spread that 2 places would put at 0 keeps 2 significant digits, an exact 0 stays 0.0, and a spread of 0.005 and above prints as before. A non-finite spread is still refused before this line. Signed-off-by: Anton Volkov --- dokimi/changelog.d/20261126_140100_arms-tiny-delta-std.md | 8 ++++++++ dokimi/dokimi/eval/stats.py | 3 ++- dokimi/tests/test_stats.py | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 dokimi/changelog.d/20261126_140100_arms-tiny-delta-std.md diff --git a/dokimi/changelog.d/20261126_140100_arms-tiny-delta-std.md b/dokimi/changelog.d/20261126_140100_arms-tiny-delta-std.md new file mode 100644 index 000000000..c1a9918b9 --- /dev/null +++ b/dokimi/changelog.d/20261126_140100_arms-tiny-delta-std.md @@ -0,0 +1,8 @@ + + +### Fixed + +- **An arms row no longer prints a `delta_std` below 0.005 as `0.0`** — a spread that 2 places would put at 0 now keeps 2 significant digits, as `delta_mean` does: deltas of 2e-12 to 9e-12 print `delta_std` `2.4e-12` beside `delta_mean` `4.5e-12`, not `0.0`. A spread of 0.005 and above, and an exact 0, print as before. A stored arms result differs from a new one on rows with such a spread. diff --git a/dokimi/dokimi/eval/stats.py b/dokimi/dokimi/eval/stats.py index 1edfc4571..4f4472e8c 100644 --- a/dokimi/dokimi/eval/stats.py +++ b/dokimi/dokimi/eval/stats.py @@ -72,6 +72,7 @@ min_sign_flip_p, pair_magnitudes, round_mean, + round_off_zero, sign_flip_row, tie_widths, within, @@ -642,7 +643,7 @@ def _describe_deltas( return { "n": len(d), "delta_mean": within(round_mean(d_mean), shown_lo, shown_hi), - "delta_std": round(d_sd, 2), + "delta_std": round_off_zero(d_sd, 2), "cohens_d": cohens_d, "effect": effect_label(cohens_d), "ci_lo": shown_lo, diff --git a/dokimi/tests/test_stats.py b/dokimi/tests/test_stats.py index 95fd7f73a..b679071d4 100644 --- a/dokimi/tests/test_stats.py +++ b/dokimi/tests/test_stats.py @@ -752,6 +752,12 @@ def test_mean_of_huge_values_keeps_a_small_term_that_survives_the_cancellation() assert stats._mean([big, big, -big, -big, 1e-100]) == pytest.approx(2e-101, rel=1e-12, abs=0.0) +def test_paired_test_keeps_two_significant_digits_of_a_tiny_delta_std(): + res = stats.paired_test([2e-12, 4e-12, 3e-12, 5e-12, 6e-12, 9e-12, 7e-12, 8e-12], [1e-12] * 8) # #1225 + assert res["delta_std"] == 2.4e-12 and res["delta_mean"] == 4.5e-12 + assert stats.paired_test([1.0, 1.4, 0.8], [0.0] * 3)["delta_std"] == 0.31 # at 2 places as before + + def test_paired_test_at_1e200_matches_the_scaled_down_deltas(): """The sd overflowed here: https://github.com/intel/dokimi/issues/475.""" small = [1.0, -1.0, 3.0, 2.0, 1.0, -1.0] From 75b35980581c3f2dfcfd97ac3b6bb3f044fd9f33 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Thu, 26 Nov 2026 13:24:00 +0000 Subject: [PATCH 3/3] fix(repo): the inconclusive note of repo compare prints a tiny mde in scientific notation (#1226) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _inconclusive_note formatted mde as :.3f below 1e6, so a row whose mde field is 2.6e-12 read "about ±0.000" in the note. A non-zero mde below 0.0005 now prints as :.1e (2 significant digits, the precision the field carries): "about ±2.6e-12". fmt_small was tried and gives a 13-decimal string for this value, unreadable in a sentence. An mde of 0.0005 and above keeps :.3f, and 1e6 and above :.3e. The text is pinned in test_repo_compare_reading.py. Signed-off-by: Anton Volkov --- .../20261126_140200_compare-tiny-mde-note.md | 8 ++++++++ dokimi/docs/repo-evaluation-contract.md | 3 ++- dokimi/dokimi/repos/compare.py | 9 ++++++++- dokimi/tests/test_repo_compare_reading.py | 16 +++++++++++++++- 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 dokimi/changelog.d/20261126_140200_compare-tiny-mde-note.md diff --git a/dokimi/changelog.d/20261126_140200_compare-tiny-mde-note.md b/dokimi/changelog.d/20261126_140200_compare-tiny-mde-note.md new file mode 100644 index 000000000..e77b5666b --- /dev/null +++ b/dokimi/changelog.d/20261126_140200_compare-tiny-mde-note.md @@ -0,0 +1,8 @@ + + +### Fixed + +- **The inconclusive note of `repo compare` no longer prints a tiny `mde` as `±0.000`** — a non-zero `mde` below 0.0005 now prints in scientific notation at 2 significant digits, as the row's `mde` field carries it: a row of deltas around 2e-12 reads `about ±2.6e-12 (8 tasks)`. An `mde` of 0.0005 and above keeps its 3 decimals, and from 1e6 its `.3e` form. diff --git a/dokimi/docs/repo-evaluation-contract.md b/dokimi/docs/repo-evaluation-contract.md index 656f6e57c..c0590493e 100644 --- a/dokimi/docs/repo-evaluation-contract.md +++ b/dokimi/docs/repo-evaluation-contract.md @@ -2800,7 +2800,8 @@ python cli.py repo compare repo-runs/authoring --baseline guidance:none --metric `(t(0.975, n-1) + t(0.80, n-1)) * sd / sqrt(n)` over the per-task deltas, of the mean delta a one-sample t test at the uncorrected two-sided 5% level detects with 80% power at that spread, the t quantiles at `n-1` degrees of - freedom (every row has `mde` under `data` in `--json`; `null` for one task, for deltas with + freedom (the note prints it at 3 decimals, and in scientific notation at 2 significant digits below 0.0005, as `2.6e-12`, and from 1e6; + every row has `mde` under `data` in `--json`; `null` for one task, for deltas with no spread (then no note), or for a figure that leaves the float range (the note then names the changed-task or Holm floor where one keeps p above 0.05, and says nothing otherwise). It is not the power of the sign-flip test nor of the Holm-corrected decision; a Holm-calibrated figure would depend on the other rows' observed p, which a figure for planning the next run's task count diff --git a/dokimi/dokimi/repos/compare.py b/dokimi/dokimi/repos/compare.py index d1f03aeb5..90cfeadd8 100644 --- a/dokimi/dokimi/repos/compare.py +++ b/dokimi/dokimi/repos/compare.py @@ -686,13 +686,20 @@ def _reading_notes(rows: list[dict[str, Any]], family: int) -> list[str]: return out +def _mde_text(mde: float) -> str: + """``mde`` at 3 decimals; at 2 significant digits in scientific notation below 0.0005 (``2.6e-12``, not 0.000) and from 1e6.""" + if 0 < mde < 0.0005: + return f"{mde:.1e}" + return f"{mde:.3f}" if mde < 1e6 else f"{mde:.3e}" # a figure near the float range is no 300-digit string + + def _inconclusive_note(r: dict[str, Any], family: int) -> str | None: """The note of a gate or score row of 2+ tasks whose interval includes 0: its ``mde``, or why it has none.""" if r["n_tasks"] < 2 or not includes_zero(r["delta"]["lo"], r["delta"]["hi"]): return None head = f" {r['measure']} inconclusive: the interval includes 0; " if r["mde"] is not None: - mde = f"{r['mde']:.3f}" if r["mde"] < 1e6 else f"{r['mde']:.3e}" # a figure near the float range is no 300-digit string + mde = _mde_text(r["mde"]) return head + (f"an uncorrected t-test estimate puts the effect 80% power detects at this spread at about " f"±{mde} ({r['n_tasks']} tasks), before Holm and not for the sign-flip test") changed, holm = r["up"] + r["down"], r["p_holm_floor"] diff --git a/dokimi/tests/test_repo_compare_reading.py b/dokimi/tests/test_repo_compare_reading.py index ea95f8ae9..a9a9c267c 100644 --- a/dokimi/tests/test_repo_compare_reading.py +++ b/dokimi/tests/test_repo_compare_reading.py @@ -13,7 +13,7 @@ import pytest from dokimi.cli import build_parser -from dokimi.repos.compare import CompareError, _round, compare, format_compare, min_detectable, sign_flip_summary +from dokimi.repos.compare import CompareError, _inconclusive_note, _round, compare, format_compare, min_detectable, sign_flip_summary from dokimi.repos.runner import cell_name from test_repo_compare import _cell, _row @@ -379,6 +379,20 @@ def test_the_changed_line_still_leaves_out_a_task_delta_below_5e7(tmp_path): assert " score changed: review_2 +0.25, review_1 +0.50" in lines +def test_inconclusive_note_prints_a_tiny_mde_at_two_significant_digits(): + row = sign_flip_summary(_pairs_at(1e-12, [3e-12, -2e-12, 1e-12, -1e-12, 2e-12, -3e-12, 1.5e-12, -2.5e-12])) # #1226 + assert row["mde"] == 2.6e-12 + assert _inconclusive_note({**row, "measure": "gate"}, 1) == ( + " gate inconclusive: the interval includes 0; an uncorrected t-test estimate puts the effect 80% power detects " + "at this spread at about ±2.6e-12 (8 tasks), before Holm and not for the sign-flip test") + + +@pytest.mark.parametrize(("mde", "text"), [(0.0004, "4.0e-04"), (0.0005, "0.001"), (0.0123, "0.012"), (0.474342, "0.474")]) +def test_inconclusive_note_keeps_three_decimals_from_0005(mde, text): + row = {"measure": "score", "n_tasks": 6, "delta": {"lo": -1.0, "hi": 1.0}, "mde": mde} + assert f"at about ±{text} (6 tasks)," in _inconclusive_note(row, 1) + + @pytest.mark.parametrize(("value", "printed"), [(-1e-12, -1e-12), (4e-7, 4e-7), (0.1234567, 0.123457), (0.0, 0.0), (1.234e-9, 1.2e-9)]) def test_round_keeps_six_places_and_a_sign_where_they_do_not_give_zero(value, printed):