AsianPlayer/TriDrive / code /eval /finish_warning_head_gaze.py
AsianPlayer's picture
download
raw
7.02 kB
"""cwm3/eval/finish_warning_head_gaze.py — final assembly of results/tables/warning_head_final_gaze.md (gaze/robustness agent, 2026-09-12; coordinator request):
(1) prepends the banner with the PRE-STATED kill rule and the "gaze validation pending" status; (2) appends the equal-load operating points of the gaze head vs the
DMS chain from results/operating_points/final_gaze_dwfcgz_<latest>/{operating_points,paired_lead,dms_reference}.csv (eval/operating_points.py output; the
`_dwfc` reference item final_ext_dwfc for the same loads); (3) appends " ⟨gaze validation pending⟩" to every table row that carries a gaze column (`dwfcgz`) or the
gaze item's ensemble rows; (4) a verdict block read from the regime report's paired rows (the `gaze_beyond_dwell_face` pair; kill rule = AUROC Δ CI excl. 0 on
>= 2/3 seeds in engaged OR pooled). Idempotent (a marker line guards the banner). Numbers are copied from the CSVs / the report — nothing is recomputed.
python eval/finish_warning_head_gaze.py [--table results/tables/warning_head_final_gaze.md]
"""
from __future__ import annotations
import argparse
import re
import time
from pathlib import Path
import numpy as np
import pandas as pd
CWM3 = Path(__file__).resolve().parents[1]
MARK = "<!-- gaze-head banner -->"
PENDING = " ⟨gaze validation pending⟩"
def latest(item):
ds_ = sorted((CWM3 / "results" / "operating_points").glob(f"{item}_*"))
return ds_[-1] if ds_ else None
def ops_section(item, label):
d = latest(item)
if d is None or not (d / "operating_points.csv").exists():
return [f"(no operating-points run for item `{item}`)", ""]
op = pd.read_csv(d / "operating_points.csv")
pl = pd.read_csv(d / "paired_lead.csv") if (d / "paired_lead.csv").exists() else pd.DataFrame()
L = [f"#### item `{item}` ({label}; `{d.name}`; mean over seeds {sorted(op.seed.unique().tolist())}; per-seed CIs in the CSV)", "",
"| load | score | regime | alerts/h | recall | precision | lead median s | detected |", "|---|---|---|---|---|---|---|---|"]
for (load, score, reg), g in op.groupby(["load", "score", "regime"], sort=False):
aph = g.alerts_per_hour_manual.mean() if reg == "manual" else g.alerts_per_hour_engaged.mean() if reg == "engaged" else (g.alerts_per_hour_manual.mean() + g.alerts_per_hour_engaged.mean()) / 2
L.append(f"| {load} | {score} | {reg} | {aph:.1f} | {g.recall.mean():.3f} | {g.precision.mean():.3f} | {g.lead_median.mean():.1f} | {g.lead_detected_frac.mean():.2f} |")
if len(pl):
L += ["", "| load | regime | paired lead Δ head − DMS (s, undetected = 0), mean over seeds | verdicts per seed |", "|---|---|---|---|"]
for (load, reg), g in pl.groupby(["load", "regime"], sort=False):
L.append(f"| {load} | {reg} | {g.delta_lead0_mean.mean():+.2f} [{g.delta_lead0_ci_lo.mean():+.2f},{g.delta_lead0_ci_hi.mean():+.2f}] | {', '.join(str(v) for v in g.verdict)} |")
return L + [""]
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--table", default=str(CWM3 / "results" / "tables" / "warning_head_final_gaze.md"))
a = ap.parse_args()
p = Path(a.table)
txt = p.read_text()
# (3) label every gaze row
lines = []
for ln in txt.splitlines():
if ln.startswith("|") and ("dwfcgz" in ln or "gaze_beyond" in ln) and PENDING not in ln and not ln.startswith("|---"):
ln = ln.rstrip()
ln = ln[:-1].rstrip() + PENDING + " |" if ln.endswith("|") else ln + PENDING
lines.append(ln)
txt = "\n".join(lines) + ("\n" if not txt.endswith("\n") else "")
# (4) verdict from the regime report's paired rows (the section written by warning_head_regime_report.py: "| pair | stratum | ... | verdict |")
verdict = "not found in the report"
m = re.findall(r"^\|\s*gaze_beyond_dwell_face[^\n]*$", txt, flags=re.M)
if m:
verdict = "; ".join(x.strip() for x in m[:6])
ops = ["## Equal-alert-load operating points (eval/operating_points.py; head thresholded per regime to the DMS att@3s chain's alerts/hour; same_recall = thresholded to the DMS gold recall; low10 = 10 alerts/h)", "",
"Comparison rows: the gaze head (item `final_gaze_dwfcgz`) and the cur+dwell+face reference head (item `final_ext_dwfc`, warning-head agent, same loads).", ""]
ops += ops_section("final_gaze_dwfcgz", "HGB(current+dwell+face+gaze) — GAZE VALIDATION PENDING") + ops_section("final_ext_dwfc", "HGB(current+dwell+face) reference")
if MARK not in txt:
banner = [MARK, f"# GAZE-CHAIN WARNING HEAD — `cur+dwell+face+gaze` vs the `cur+dwell+face` reference (item `cwm3_final_gaze`; assembled {time.strftime('%Y-%m-%d %H:%M:%S UTC', time.gmtime())})", "",
"**Status: GAZE VALIDATION PENDING on every gaze row** — the `gaze` block (10 dims) is the PREDICTED gaze_off onset / marginal / state of our own causal landmark-yaw chain "
"(`U0_kin_can_noK_s<k>_kcv2_clip8_ln_gzfc`, results/tables/gaze_chain.md); no human gaze label exists yet, so these features are validated only against our own state definition.", "",
"**Pre-stated kill rule (before the numbers were read):** adopt the gaze head ONLY if the paired AUROC Δ (cur+dwell+face+gaze − cur+dwell+face) on the clean-test gold has a "
"device-cluster-bootstrap CI excluding 0 on ≥ 2/3 seeds in the engaged stratum OR in the pooled stratum (section \"between-column paired Δ\" of the regime report below; "
"the reference head is seed-invariant, the gaze head varies with the U0 seed). Otherwise: \"no gaze effect\" and the reference head stays. Secondary: paired Δ vs DMS att@3s per stratum; "
"equal-load operating points (appendix).", "",
"Pipeline (all unchanged evaluators): `eval/predict_u0_rows.py` (U0 gaze chain on the 979 TRAIN label rows) → `train/train_warning_head.py --feature-sets current --extra-features dwell,face,gaze --w-suffix _dwfcgz` "
"(same device-grouped 5-fold CV, hp grid and labels as the `_dwfc` heads; fixed-HGB rows = `curhgb`) → `eval/merge_w_layouts.py` (`_dwfc` + `_dwfcgz` → `_gzmerged`, bit-identical) → "
"`cwm2/eval/warning_gold.py` via `eval/warning_head_eval.py --item cwm3_final_gaze` (509-row gold, n_boot 2000) → `eval/warning_head_regime_report.py` → `eval/operating_points.py`.", "",
f"**Kill-rule readout (copied from the regime report rows below):** {verdict}", "", "---", ""]
txt = "\n".join(banner) + txt
else:
txt = re.sub(r"\*\*Kill-rule readout \(copied from the regime report rows below\):\*\* [^\n]*", f"**Kill-rule readout (copied from the regime report rows below):** {verdict}", txt)
if "## Equal-alert-load operating points" not in txt:
txt += "\n" + "\n".join(ops) + "\n"
p.write_text(txt)
print(f"finished {p} (verdict rows: {len(m)})")
if __name__ == "__main__":
main()

Xet Storage Details

Size:
7.02 kB
·
Xet hash:
b725a98b106521ae03a434649c63c267e11204f82808c0fb29004e57b07ccbe4

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.