Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!--
Copyright (C) 2026 Intel Corporation
SPDX-License-Identifier: Apache-2.0
-->

### 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.
8 changes: 8 additions & 0 deletions dokimi/changelog.d/20261126_140100_arms-tiny-delta-std.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!--
Copyright (C) 2026 Intel Corporation
SPDX-License-Identifier: Apache-2.0
-->

### 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.
8 changes: 8 additions & 0 deletions dokimi/changelog.d/20261126_140200_compare-tiny-mde-note.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!--
Copyright (C) 2026 Intel Corporation
SPDX-License-Identifier: Apache-2.0
-->

### 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.
6 changes: 4 additions & 2 deletions dokimi/docs/repo-evaluation-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -2799,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
Expand Down
3 changes: 2 additions & 1 deletion dokimi/dokimi/eval/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
min_sign_flip_p,
pair_magnitudes,
round_mean,
round_off_zero,
sign_flip_row,
tie_widths,
within,
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 11 additions & 10 deletions dokimi/dokimi/repos/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -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"])))
Expand Down Expand Up @@ -687,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"]
Expand Down Expand Up @@ -776,15 +782,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


Expand Down
41 changes: 40 additions & 1 deletion dokimi/tests/test_repo_compare_reading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, _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
Expand Down Expand Up @@ -360,3 +361,41 @@ 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


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):
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
6 changes: 6 additions & 0 deletions dokimi/tests/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading