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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ different event from one that moved because it was wrong.

### Fixed

- The site printed some figures one step off from the report, such as a
measured ECE of 0.00125 as `0.0012` where the report prints `0.0013` (#48).
Its formatter meant to round half to even only on an exact tie, but its tie
test compared a product with itself, so every near tie was rounded to even.
It now detects exact binary ties alone (odd multiples of 1/32, the only
values a double can hold exactly on a tie) and otherwise rounds the exact
value, as Python does. The golden fixture gains 890 values on and beside
ties, and near-tie measured values, so the parity check covers them.

- The release workflow gave its whole run a write token while it executed the
project's code and every dependency's, expanded the tag, which a manual run
takes as free text, straight into shell, and let a tag push and a manual run
Expand Down
10 changes: 10 additions & 0 deletions scripts/check_floor_parity.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ for (const c of fixture.cases) {
console.log(`${label.padEnd(36)} mean ${band.mean.toFixed(6)} p95 ${band.p95.toFixed(6)} ${elapsed}ms`);
}

// Every figure on the page is printed through fixed4, which must round as
// Python's "%.4f" does, including on and beside a tie.
const formats = Object.entries(fixture.fixed4);
const misformatted = formats.filter(([value, expected]) => floor.fixed4(Number(value)) !== expected);
for (const [value, expected] of misformatted.slice(0, 5)) {
failures.push(`fixed4(${value}) is ${floor.fixed4(Number(value))}, Python's %.4f prints ${expected}`);
}
if (misformatted.length > 5) failures.push(`...and ${misformatted.length - 5} more fixed4 disagreements`);
console.log(`${formats.length} values formatted, ${misformatted.length} differ from Python's %.4f`);

console.log(`\n${fixture.cases.length} cases, largest difference ${worst.toExponential(2)}, tolerance ${tolerance}`);

// The worked example, when a built site is given: the page derives the example
Expand Down
23 changes: 22 additions & 1 deletion scripts/floor_golden.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import argparse
import json
import math
import sys
from pathlib import Path
from typing import Any
Expand Down Expand Up @@ -72,7 +73,24 @@
#: Measured ECE values each case's verdict sentence is exported for, so the
#: wording, the formatting, and the side of the line a value falls on are all
#: checked, not only the floor.
MEASURED = [0.005, 0.02, 0.05, 0.074, 0.1, 0.2]
MEASURED = [0.00125, 0.005, 0.02, 0.03125, 0.05, 0.074, 0.1, 0.2]


def _formatting_cases() -> dict[str, str]:
"""Values on and beside a rounding tie, with what the report prints for them.

The report formats with ``:.4f``, which rounds the exact binary value, half
to even. A value that looks like a tie in decimal, such as 0.00125, is not
one in binary and rounds by which side of the tie it really lies on; the
only exact ties are odd multiples of 1/32. The measured values above held
none of either, which is how a formatter that rounded every near tie to
even passed this check.
"""
values = {j / 32 for j in range(1, 64, 2)}
for k in range(0, 2000, 7):
tie = (k + 0.5) / 10000
values.update({tie, math.nextafter(tie, 0.0), math.nextafter(tie, 1.0)})
return {repr(value): f"{value:.4f}" for value in sorted(values)}


def _pcg64_state(seed: int) -> dict[str, str]:
Expand Down Expand Up @@ -116,6 +134,7 @@ def build() -> dict[str, Any]:
"tolerance": TOLERANCE,
"pcg64_initial_state": {"0": _pcg64_state(0), "1": _pcg64_state(1)},
"cases": cases,
"fixed4": _formatting_cases(),
}


Expand All @@ -126,6 +145,8 @@ def _check(fresh: dict[str, Any]) -> list[str]:
problems = []
if committed["pcg64_initial_state"] != fresh["pcg64_initial_state"]:
problems.append("numpy's seeded PCG64 states differ from the fixture")
if committed.get("fixed4") != fresh["fixed4"]:
problems.append("the :.4f formatting cases differ from the fixture")
if len(committed["cases"]) != len(fresh["cases"]):
problems.append("the fixture holds a different set of cases; regenerate it")
return problems
Expand Down
Loading
Loading