| """ |
| Stage 05 (v8b): build the AIME25 4-alpha results table. |
| |
| Reads the stage-04 summary JSON and emits a CSV + Markdown table with, |
| per alpha: accuracy, mean thinking tokens (+ reduction vs alpha=1.0), |
| mean chars (+ reduction), mean reflection markers (+ reduction), and |
| collapse rate. Reductions are relative to the alpha=1.0 baseline. |
| |
| Outputs into results/: |
| aime25_seed{seed}_4alpha_table.csv |
| aime25_seed{seed}_4alpha_table.md |
| """ |
| import argparse, csv, math, os, sys |
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
|
|
| from configs import get_config |
| from configs.paths import dim_paths, ensure_dirs |
| from src.utils import read_json |
|
|
| FIELDS = [ |
| "alpha", "n", "accuracy_%", "correct", "mean_think_tokens", |
| "token_reduction_%", "mean_chars", "char_reduction_%", |
| "mean_reflection_markers", "reflection_reduction_%", |
| "no_boxed", "collapse_rate_%", |
| ] |
|
|
|
|
| def fmt(x, nd=2): |
| if x is None: |
| return "" |
| try: |
| if math.isnan(float(x)): |
| return "" |
| except Exception: |
| return str(x) |
| return f"{float(x):.{nd}f}" |
|
|
|
|
| def rows_from_summary(summary): |
| base = summary.get("1.00") |
| rows = [] |
| for a in sorted([float(k) for k in summary.keys()], reverse=True): |
| k = f"{a:.2f}" |
| s = summary[k] |
| def red(field): |
| if not base or float(base[field]) == 0: |
| return None |
| return 1 - float(s[field]) / float(base[field]) |
| rows.append({ |
| "alpha": k, |
| "n": s.get("n", ""), |
| "accuracy_%": fmt(100.0 * float(s.get("accuracy", 0)), 1), |
| "correct": s.get("n_correct", ""), |
| "mean_think_tokens": fmt(float(s.get("mean_think_tokens", 0)), 1), |
| "token_reduction_%": fmt(100.0 * red("mean_think_tokens"), 1) |
| if red("mean_think_tokens") is not None else "", |
| "mean_chars": fmt(float(s.get("mean_chars", 0)), 1), |
| "char_reduction_%": fmt(100.0 * red("mean_chars"), 1) |
| if red("mean_chars") is not None else "", |
| "mean_reflection_markers": fmt(float(s.get("mean_mon", 0)), 2), |
| "reflection_reduction_%": fmt(100.0 * red("mean_mon"), 1) |
| if red("mean_mon") is not None else "", |
| "no_boxed": s.get("n_no_boxed", ""), |
| "collapse_rate_%": fmt(100.0 * float(s.get("collapse_rate", 0)), 1), |
| }) |
| return rows |
|
|
|
|
| def main(): |
| ap = argparse.ArgumentParser() |
| ap.add_argument("--dimension", default="monitoring") |
| ap.add_argument("--seed", type=int, default=0) |
| args = ap.parse_args() |
|
|
| ensure_dirs(args.dimension) |
| cfg = get_config(args.dimension) |
| p = dim_paths(args.dimension) |
|
|
| sum_path = os.path.join(p.RESULTS_DIR, f"aime25_seed{args.seed}_4alpha_summary.json") |
| if not os.path.exists(sum_path): |
| print(f"[05] missing {sum_path} — run stage 04 first."); sys.exit(1) |
| data = read_json(sum_path) |
| rows = rows_from_summary(data["summary"]) |
|
|
| csv_path = os.path.join(p.RESULTS_DIR, f"aime25_seed{args.seed}_4alpha_table.csv") |
| md_path = os.path.join(p.RESULTS_DIR, f"aime25_seed{args.seed}_4alpha_table.md") |
|
|
| with open(csv_path, "w", newline="", encoding="utf-8") as f: |
| w = csv.DictWriter(f, fieldnames=FIELDS) |
| w.writeheader() |
| for r in rows: |
| w.writerow({k: r.get(k, "") for k in FIELDS}) |
|
|
| with open(md_path, "w", encoding="utf-8") as f: |
| f.write("| " + " | ".join(FIELDS) + " |\n") |
| f.write("| " + " | ".join(["---"] * len(FIELDS)) + " |\n") |
| for r in rows: |
| f.write("| " + " | ".join(str(r.get(k, "")) for k in FIELDS) + " |\n") |
|
|
| print(f"[05] selected_layers: {data.get('selected_layers')}") |
| print(f"[05] wrote:\n {csv_path}\n {md_path}\n") |
| print("| " + " | ".join(FIELDS) + " |") |
| print("| " + " | ".join(["---"] * len(FIELDS)) + " |") |
| for r in rows: |
| print("| " + " | ".join(str(r.get(k, "")) for k in FIELDS) + " |") |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|