Datasets:
Download src/robotics/eval/stats.py from Nabidnur/RoboRACE-Bench: direct link, hf CLI and curl.
- Browser
- Download file 2.78 kB
-
https://huggingface.co/datasets/Nabidnur/RoboRACE-Bench/resolve/main/src/robotics/eval/stats.py
- Command line
-
hf download hf://datasets/Nabidnur/RoboRACE-Bench/src/robotics/eval/stats.py
-
curl -L -o stats.py https://huggingface.co/datasets/Nabidnur/RoboRACE-Bench/resolve/main/src/robotics/eval/stats.py
2.78 kB
| """Success-rate statistics for robot evaluations. | |
| Results files are JSONL, one episode per line: | |
| {"run": "groot17_libero", "suite": "libero_spatial", "task": 3, "seed": 0, "success": true} | |
| Usage: | |
| python -m robotics.eval.stats results/*.jsonl # per run/suite table | |
| python -m robotics.eval.stats results/a.jsonl results/b.jsonl --compare RUN_A RUN_B | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import math | |
| from collections import defaultdict | |
| from pathlib import Path | |
| def wilson(k: int, n: int, z: float = 1.96) -> tuple[float, float]: | |
| """95% Wilson score interval for k successes out of n.""" | |
| if n == 0: | |
| return (0.0, 1.0) | |
| p = k / n | |
| denom = 1 + z * z / n | |
| centre = (p + z * z / (2 * n)) / denom | |
| half = z * math.sqrt(p * (1 - p) / n + z * z / (4 * n * n)) / denom | |
| return (max(0.0, centre - half), min(1.0, centre + half)) | |
| def compare(k1: int, n1: int, k2: int, n2: int) -> dict: | |
| """Two-proportion z-test (pooled). Returns diff, z and two-sided p-value.""" | |
| p1, p2 = k1 / n1, k2 / n2 | |
| pooled = (k1 + k2) / (n1 + n2) | |
| se = math.sqrt(pooled * (1 - pooled) * (1 / n1 + 1 / n2)) | |
| z = (p2 - p1) / se if se > 0 else 0.0 | |
| pval = math.erfc(abs(z) / math.sqrt(2)) | |
| return {"diff": p2 - p1, "z": z, "p_value": pval} | |
| def load(paths: list[str]) -> list[dict]: | |
| rows = [] | |
| for p in paths: | |
| for line in Path(p).read_text().splitlines(): | |
| if line.strip(): | |
| rows.append(json.loads(line)) | |
| return rows | |
| def summarize(rows: list[dict]) -> dict[tuple[str, str], tuple[int, int]]: | |
| agg: dict[tuple[str, str], list[int]] = defaultdict(lambda: [0, 0]) | |
| for r in rows: | |
| key = (r.get("run", "?"), r.get("suite", "all")) | |
| agg[key][0] += bool(r["success"]) | |
| agg[key][1] += 1 | |
| return {k: (v[0], v[1]) for k, v in agg.items()} | |
| def main(argv: list[str] | None = None) -> None: | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("files", nargs="+") | |
| ap.add_argument("--compare", nargs=2, metavar=("RUN_A", "RUN_B")) | |
| a = ap.parse_args(argv) | |
| summ = summarize(load(a.files)) | |
| print(f"{'run':30} {'suite':18} {'n':>5} {'success':>8} 95% CI") | |
| for (run, suite), (k, n) in sorted(summ.items()): | |
| lo, hi = wilson(k, n) | |
| print(f"{run:30} {suite:18} {n:5d} {k / n:8.1%} [{lo:.1%}, {hi:.1%}]") | |
| if a.compare: | |
| tot = defaultdict(lambda: [0, 0]) | |
| for (run, _), (k, n) in summ.items(): | |
| tot[run][0] += k | |
| tot[run][1] += n | |
| (k1, n1), (k2, n2) = tot[a.compare[0]], tot[a.compare[1]] | |
| c = compare(k1, n1, k2, n2) | |
| print(f"\n{a.compare[1]} - {a.compare[0]}: {c['diff']:+.1%} z={c['z']:.2f} p={c['p_value']:.4f}") | |
| if __name__ == "__main__": | |
| main() | |