v7: CHR band-index clamp (bin-0 wrap), per-config error isolation (degenerate CRD ellipse -> labeled error row), ok-only summaries
Browse files427 unmodified lines428429430431432433434932 unmodified lines13671368136913701371137286 unmodified lines14591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515162 unmodified lines151915201521152215231524152541 unmodified lines1567156815691570157115721573427 unmodified linesj_star = np.max(j_star_idx)S = S_grid[j_star]bands[:, 0] = self.breaks[S[:, 0] - 1]bands[:, 1] = self.breaks[S[:, -1]]return S, bands932 unmodified lines"crd-ellipse", "crd-convexhull", "crd-hyperrectangle")def _orca_skip_set():import os as _osreturn set(x for x in _os.environ.get("ORCA_SKIP", "").split(",") if x)86 unmodified linesif "orca" not in _skip:for spec in ("paper", "author"):for sampler in ("iid", "shared"):m, d = run_orca(model, y_explore, y_calib, y_test,X_explore, X_calib, X_test, rng,sampler=sampler, spec=spec,S_exp=samples[(sampler, "explore")],S_cal=samples[(sampler, "calib")],S_te=samples[(sampler, "test")],span_clipped=span_clipped)out.append(("orca", spec, sampler, m, d))# ---- PCP x {iid, shared} ----if "pcp" not in _skip:for sampler in ("iid", "shared"):m, d = run_pcp(model, y_calib, y_test, X_calib, X_test, rng,sampler=sampler,S_cal=samples[(sampler, "calib")],S_te=samples[(sampler, "test")])out.append(("pcp", "", sampler, m, d))# ---- CQR ----if "cqr" not in _skip:m, d = run_cqr(model, y_calib, y_test, X_calib, X_test)out.append(("cqr", "", "", m, d))# ---- CHR ----if "chr" not in _skip:m, d = run_chr(model, y_calib, y_test, X_calib, X_test, y_min, y_max)out.append(("chr", "", "", m, d))# ---- DCP ----if "dcp-cqr" not in _skip:m, d = run_dcp(model, y_calib, y_test, X_calib, X_test, y_min, y_max)out.append(("dcp-cqr", "", "", m, d))# ---- DistSplit ----if "distsplit" not in _skip:m, d = run_distsplit(model, y_calib, y_test, X_calib, X_test,y_min, y_max)out.append(("distsplit", "", "", m, d))# ---- CDSplit ----if "cdsplit" not in _skip:m, d = run_cdsplit(model, y_train, y_calib, y_test, X_train, X_calib,X_test, y_min, y_max, seed)out.append(("cdsplit", "", "", m, d))# ---- CRD (3 shape templates) ----for tmpl in ("ellipse", "convexhull", "hyperrectangle"):if f"crd-{tmpl}" not in _skip:m, d = run_crd(model, y_calib, y_test, X_calib, X_test,y_min, y_max, tmpl, seed)out.append((f"crd-{tmpl}", "", "", m, d))# ---- R2CCP ----if "r2ccp" not in _skip:# max_epochs: the paper's 500; ORCA_R2CCP_EPOCHS exists ONLY for# plumbing smoke tests and must stay unset in real runsep = int(os.environ.get("ORCA_R2CCP_EPOCHS", "500"))m, d = run_r2ccp(X_train, y_train, X_test, y_test, seed,max_epochs=ep)out.append(("r2ccp", "", "", m, d))rows = []for method, spec, sampler, m, d in out:2 unmodified linesrows.append({"dataset": dataset, "preproc": preproc, "run_id": run_id,"method_config": mc, "coverage": m["coverage"], "eff": m["eff"],"seconds": m["seconds"], "status": "ok","threshold": d["threshold"], "proxy_objective": d["proxy_objective"],"quota": d["quota"], "tighten": d["tighten"], "clip": d["clip"],"sampler": d["sampler"], "spec": d["spec"],41 unmodified linesdf = pd.DataFrame(all_rows, columns=header)print("\n=== summary (mean +- SE over runs) ===", flush=True)print(f"{'method_config':30s} {'coverage':>18s} {'eff':>18s}")for mc, g in df.groupby("method_config"):print(f"{mc:30s} {g['coverage'].mean():.4f} +- "f"{g['coverage'].sem():.4f} {g['eff'].mean():.4f} +- "f"{g['eff'].sem():.4f}")427 unmodified lines428429430431432433434435436437438932 unmodified lines137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139886 unmodified lines14851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415452 unmodified lines1548154915501551155215531554155541 unmodified lines15971598159916001601160216031604427 unmodified linesj_star = np.max(j_star_idx)S = S_grid[j_star]# clamp at 0: bin 0 is [ymin, breaks[0]], so a band including bin 0# starts at breaks[0] = ymin; S[:,0]-1 == -1 would wrap to breaks[-1]# (the original chr code never hits this because its bin 0 always has# zero mass; the delta_alpha floor path can include it -- documented)bands[:, 0] = self.breaks[np.maximum(S[:, 0] - 1, 0)]bands[:, 1] = self.breaks[S[:, -1]]return S, bands932 unmodified lines"crd-ellipse", "crd-convexhull", "crd-hyperrectangle")def _run_config(out, name, spec, sampler, fn):"""Run one method-config. A per-config failure (e.g. the CRD toolbox'sdegenerate-ellipse case on one seed: adjust_shape(m) with m < -1 makesscore_margin negative and sqrt(sm/Q) undefined -- undefined behavior ofthe referenced implementation) is recorded as a status='error' row withthe exception as diagnostics, instead of killing the 30-run job. Failedrows are labeled in the CSV and excluded from summaries (never countedas successful repetitions)."""try:m, d = fn()out.append((name, spec, sampler, m, d))except Exception as exc: # noqa: BLE001m = {"coverage": float("nan"), "eff": float("nan"), "seconds": 0.0}d = {"threshold": f"{type(exc).__name__}: {exc}"[:120],"proxy_objective": "", "quota": "", "tighten": "","clip": "", "sampler": sampler, "spec": spec,"milp_status": "error"}out.append((name, spec, sampler, m, d))print(f"[config-error] {name}|{spec}|{sampler}: "f"{type(exc).__name__}: {exc}", flush=True)def _orca_skip_set():import os as _osreturn set(x for x in _os.environ.get("ORCA_SKIP", "").split(",") if x)86 unmodified linesif "orca" not in _skip:for spec in ("paper", "author"):for sampler in ("iid", "shared"):_run_config(out, "orca", spec, sampler,lambda: run_orca(model, y_explore, y_calib, y_test,X_explore, X_calib, X_test, rng,sampler=sampler, spec=spec,S_exp=samples[(sampler, "explore")],S_cal=samples[(sampler, "calib")],S_te=samples[(sampler, "test")],span_clipped=span_clipped))# ---- PCP x {iid, shared} ----if "pcp" not in _skip:for sampler in ("iid", "shared"):_run_config(out, "pcp", "", sampler,lambda: run_pcp(model, y_calib, y_test, X_calib,X_test, rng, sampler=sampler,S_cal=samples[(sampler, "calib")],S_te=samples[(sampler, "test")]))# ---- CQR ----if "cqr" not in _skip:_run_config(out, "cqr", "", "",lambda: run_cqr(model, y_calib, y_test, X_calib, X_test))# ---- CHR ----if "chr" not in _skip:_run_config(out, "chr", "", "",lambda: run_chr(model, y_calib, y_test, X_calib, X_test,y_min, y_max))# ---- DCP ----if "dcp-cqr" not in _skip:_run_config(out, "dcp-cqr", "", "",lambda: run_dcp(model, y_calib, y_test, X_calib, X_test,y_min, y_max))# ---- DistSplit ----if "distsplit" not in _skip:_run_config(out, "distsplit", "", "",lambda: run_distsplit(model, y_calib, y_test, X_calib,X_test, y_min, y_max))# ---- CDSplit ----if "cdsplit" not in _skip:_run_config(out, "cdsplit", "", "",lambda: run_cdsplit(model, y_train, y_calib, y_test,X_train, X_calib, X_test,y_min, y_max, seed))# ---- CRD (3 shape templates) ----for tmpl in ("ellipse", "convexhull", "hyperrectangle"):if f"crd-{tmpl}" not in _skip:_run_config(out, f"crd-{tmpl}", "", "",lambda: run_crd(model, y_calib, y_test, X_calib,X_test, y_min, y_max, tmpl, seed))# ---- R2CCP ----if "r2ccp" not in _skip:# max_epochs: the paper's 500; ORCA_R2CCP_EPOCHS exists ONLY for# plumbing smoke tests and must stay unset in real runsep = int(os.environ.get("ORCA_R2CCP_EPOCHS", "500"))_run_config(out, "r2ccp", "", "",lambda: run_r2ccp(X_train, y_train, X_test, y_test, seed,max_epochs=ep))rows = []for method, spec, sampler, m, d in out:2 unmodified linesrows.append({"dataset": dataset, "preproc": preproc, "run_id": run_id,"method_config": mc, "coverage": m["coverage"], "eff": m["eff"],"seconds": m["seconds"],"status": ("error" if d.get("milp_status") == "error" else "ok"),"threshold": d["threshold"], "proxy_objective": d["proxy_objective"],"quota": d["quota"], "tighten": d["tighten"], "clip": d["clip"],"sampler": d["sampler"], "spec": d["spec"],41 unmodified linesdf = pd.DataFrame(all_rows, columns=header)print("\n=== summary (mean +- SE over runs) ===", flush=True)print(f"{'method_config':30s} {'coverage':>18s} {'eff':>18s}")df_ok = df[df["status"] == "ok"]for mc, g in df_ok.groupby("method_config"):print(f"{mc:30s} {g['coverage'].mean():.4f} +- "f"{g['coverage'].sem():.4f} {g['eff'].mean():.4f} +- "f"{g['eff'].sem():.4f}")
code/run_full.py+65-34