#!/usr/bin/env python3 # Author: Simon-Pierre Boucher — simon-pierre.boucher@uqo.ca """Additional LaTeX table fragments for the results, ablations and calibration sections (paper/tables/tab_*.tex, booktabs, siunitx-safe, CSV twin next to each fragment). Every number is read from the versioned outputs of scripts/20_evaluate.py (results/evaluation*/), scripts/35_rounds_curve.py (rounds_validation.csv) and results/evaluation/contrasts.csv; the only new computations are paired block bootstraps on the stored per-record frames (records.parquet) for contrasts that scripts/20_evaluate.py does not pre-register, using the same block_bootstrap_contrast routine, the same blocks (municipality × month), B = 2000 and seed 20261027. Fragments tab_primary_effects primary family on test: Δ, CI, SE, relative CI, minimum detectable effect (80 % power) tab_aggregation test: mean |e| of the committee arms under each aggregation rule tab_rounds validation rounds grid: per-round mean |e| of the committee median, IQR of log estimates tab_deliberation per run: IQR round 0 / final, convergence, anchoring index, share moving toward the median tab_committees validation: E, F, G2 by provider committee + paired contrasts vs the mixed committee tab_contrasts_extra validation exploratory paired contrasts (G2 vs G-fullview, committees) tab_spatial spatial holdout: in-region vs withheld-region models paired on the 8,988 withheld sales tab_strata_compact test: mean |e| by stratum for D, E, F, G2, I, J (mid) and G2 (small); suppressed cells = -- tab_coverage_subgroups test: conditional 50 / 90 % coverage by subgroup (non-suppressed cells) tab_drift test / holdout / prospective: accuracy and calibration of D (full and paired), E, F, G2 tab_faithfulness faithfulness audit per run with the split made explicit Usage: python3 scripts/22_extra_tables.py """ from __future__ import annotations import json import sys from pathlib import Path import numpy as np import pandas as pd ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "src")) from agentic_valuation.evaluation.inference import block_bootstrap_contrast # noqa: E402 from agentic_valuation.evaluation.metrics import per_record # noqa: E402 from agentic_valuation.evaluation.tables import arm_pretty, escape, num, tabular # noqa: E402 RES = ROOT / "results" OUT = ROOT / "paper" / "tables" B = 2000 SEED = 20261027 Z80 = 1.959964 + 0.841621 # two-sided 5 % test, 80 % power def write(tex: str, stem: str, csv_df: pd.DataFrame | None = None) -> None: body = tex.rstrip() assert not body.endswith(r"\\"), "fragment must not end with \\\\" path = OUT / f"{stem}.tex" path.write_text("% Author: Simon-Pierre Boucher — simon-pierre.boucher@uqo.ca\n% generated by scripts/22_extra_tables.py — do not edit\n" + body + "\n", encoding="utf-8") if csv_df is not None: csv_df.to_csv(path.with_suffix(".csv"), index=False) print("wrote", path.relative_to(ROOT)) def ci(lo: float, hi: float, d: int = 3) -> str: if not (np.isfinite(lo) and np.isfinite(hi)): return "{--}" return f"{{[{lo:.{d}f}, {hi:.{d}f}]}}" def short(arm: str) -> str: """Compact arm label: G_debate_r2 → G2, G_fullview → G-fullview, E_single_llm_small → E (small).""" base = {"A_hedonic": "A", "B_hierarchical": "B", "C_gbm": "C (gbm)", "C_catboost": "C (catboost)", "C_xgboost": "C (xgboost)", "D_avm": "D", "E_single_llm": "E", "F_independent": "F", "G_debate_r1": "G1", "G_debate_r2": "G2", "G_debate_r4": "G4", "G_fullview": "G-fullview", "H_debate_skeptic": "H", "I_placebo": "I", "J_cost_matched": "J"} if arm.endswith("_small"): return short(arm[:-6]) + " (small)" if arm.endswith("_spatial"): return short(arm[:-8]) + " (spatial)" return base.get(arm, arm_pretty(arm)) COMM = {"mixed_random": "mixed", "all_anthropic": "all-Anthropic", "all_openai": "all-OpenAI", "none": "--"} def records(split_dir: str) -> pd.DataFrame: return pd.read_parquet(RES / split_dir / "records.parquet") def run_records(run_id: str, aggregation: str = "median") -> pd.DataFrame: """Per-record frame of one stored run (results/runs//predictions.parquet joined to the analytic table); needed for the provider committees, which records.parquet (main configuration only) does not carry.""" preds = pd.read_parquet(RES / "runs" / run_id / "predictions.parquet") preds = preds[preds["aggregation"] == aggregation] truth = pd.read_parquet(ROOT / "data" / "processed" / "analytic.parquet") return per_record(preds, truth) def pnum(p: float) -> str: if not np.isfinite(p): return "{--}" return r"{$<$0.001}" if p < 0.001 else num(p) def sub(df: pd.DataFrame, arm: str, committee: str | None = None, aggregation: str | None = None) -> pd.DataFrame: m = df["arm"] == arm if committee is not None: m &= df["committee"] == committee if aggregation is not None: m &= df["aggregation"] == aggregation s = df.loc[m] if s["tx_id"].duplicated().any(): raise ValueError(f"ambiguous selection {arm}/{committee}/{aggregation}") return s def paired(a: pd.DataFrame, b: pd.DataFrame) -> tuple[pd.DataFrame, pd.DataFrame]: a = a.set_index("tx_id") b = b.set_index("tx_id") common = a.index.intersection(b.index) return a.loc[common].reset_index(), b.loc[common].reset_index() def contrast(a: pd.DataFrame, b: pd.DataFrame, metric: str = "mean_abs_log_error") -> dict[str, float]: a, b = paired(a, b) return block_bootstrap_contrast(a, b, metric, B=B, seed=SEED) # ------------------------------------------------------------------------------------------ 1. primary effects def tab_primary_effects() -> None: c = pd.read_csv(RES / "evaluation" / "contrasts.csv") c = c[c["family"].isin(["primary", "primary_tail"])].copy() rows, out = [], [] for _, r in c.iterrows(): se = r["se_boot"] half = 1.959964 * se mde = Z80 * se rel_lo, rel_hi = r["ci_lo"] / r["value_a"], r["ci_hi"] / r["value_a"] lab = f"{short(r['arm_b'])} vs {short(r['arm_a'])}" met = r"Mean $|e|$" if r["metric"] == "mean_abs_log_error" else r"P95 $|e|$" rows.append([lab, f"{{{met}}}", num(r["diff"]), ci(r["ci_lo"], r["ci_hi"]), num(se, 4), num(100 * r["rel_diff"], 1), ci(100 * rel_lo, 100 * rel_hi, 1), num(mde, 3), num(100 * mde / r["value_a"], 1), num(r["p_holm"]) if np.isfinite(r["p_holm"]) else "{--}"]) out.append({"contrast": lab, "metric": r["metric"], "diff": r["diff"], "ci_lo": r["ci_lo"], "ci_hi": r["ci_hi"], "se_boot": se, "rel_diff_pct": 100 * r["rel_diff"], "rel_ci_lo_pct": 100 * rel_lo, "rel_ci_hi_pct": 100 * rel_hi, "half_width": half, "mde80_abs": mde, "mde80_rel_pct": 100 * mde / r["value_a"], "p_holm": r["p_holm"], "value_a": r["value_a"], "value_b": r["value_b"]}) header = ["Contrast", "{Metric}", r"{$\Delta$}", r"{95\% CI}", "{SE}", r"{$\Delta$ (\%)}", r"{95\% CI (\%)}", "{MDE}", r"{MDE (\%)}", r"{$p$ (Holm)}"] write(tabular(header, rows, "llrcrrcrrr"), "tab_primary_effects", pd.DataFrame(out)) # ------------------------------------------------------------------------------------------ 2. aggregation rules def tab_aggregation() -> None: s = pd.read_csv(RES / "evaluation" / "summary.csv") arms = ["F_independent", "G_debate_r2", "H_debate_skeptic", "I_placebo", "J_cost_matched", "F_independent_small", "G_debate_r2_small"] rules = [("median", "Median (primary)"), ("mean", "Arithmetic mean"), ("trimmed_mean_20", r"Trimmed mean (20\%)"), ("inverse_variance", "Inverse variance (validation weights)"), ("stacking", "Stacking (validation weights)"), ("robust_bayes", "Robust Student-$t$ pool"), ("mixture", "Mixture of role distributions"), ("samples_mean", "J: mean of 12 samples"), ("samples_median", "J: median of 12 samples"), ("self_refine", "J: self-refined estimate")] rows, out = [], [] for key, lab in rules: row = [lab] rec = {"aggregation": key} for a in arms: x = s[(s["arm"] == a) & (s["aggregation"] == key)] v = float(x["mean_abs_log_error"].iloc[0]) if len(x) else np.nan row.append(num(v)) rec[a] = v rows.append(row) out.append(rec) header = ["Aggregation rule"] + [f"{{{short(a)}}}" for a in arms] write(tabular(header, rows, "l" + "r" * len(arms), midrules_after=[6]), "tab_aggregation", pd.DataFrame(out)) # ------------------------------------------------------------------------------------------ 3. rounds grid def tab_rounds() -> None: r = pd.read_csv(RES / "evaluation" / "rounds_validation.csv") order = [("G_debate_r1", "mixed_random"), ("G_debate_r2", "mixed_random"), ("G_debate_r2", "all_anthropic"), ("G_debate_r2", "all_openai"), ("G_debate_r4", "mixed_random"), ("G_fullview", "mixed_random")] rows, out, i = [], [], 0 mid = [] for arm, comm in order: g = r[(r["arm"] == arm) & (r["committee"] == comm)] rounds = sorted(g["round"].unique()) for k, rd in enumerate(rounds): med = g[(g["round"] == rd) & (g["metric"] == "ae_median")].iloc[0] mean = g[(g["round"] == rd) & (g["metric"] == "ae_mean")].iloc[0] iqr = g[(g["round"] == rd) & (g["metric"] == "iqr")].iloc[0] rows.append([short(arm) if k == 0 else "", COMM[comm] if k == 0 else "", str(int(rd)), str(int(med["n"])), num(med["value"]), ci(med["ci_lo"], med["ci_hi"]), num(mean["value"]), num(iqr["value"]), ci(iqr["ci_lo"], iqr["ci_hi"])]) out.append({"arm": arm, "committee": comm, "round": int(rd), "n": int(med["n"]), "ae_median": med["value"], "ae_median_lo": med["ci_lo"], "ae_median_hi": med["ci_hi"], "ae_mean": mean["value"], "iqr": iqr["value"], "iqr_lo": iqr["ci_lo"], "iqr_hi": iqr["ci_hi"]}) i += 1 mid.append(i - 1) header = ["Arm", "Committee", "{Round}", "{$n$}", r"{Mean $|e|$ (median)}", r"{95\% CI}", r"{Mean $|e|$ (mean)}", "{IQR}", r"{95\% CI}"] write(tabular(header, rows, "llrrrcrrc", midrules_after=mid[:-1]), "tab_rounds", pd.DataFrame(out)) # ------------------------------------------------------------------------------------------ 4. deliberation statistics SPLIT_OF = {"final_": "test (mid)", "final_small_": "test (small)", "holdout_": "holdout 2026", "prospective_": "prospective", "validation_": "validation"} def split_label(run_id: str) -> str: for k in ["final_small_", "final_", "holdout_", "prospective_", "validation_"]: if run_id.startswith(k): return SPLIT_OF[k] return run_id def tab_deliberation() -> None: f = pd.read_csv(RES / "evaluation" / "faithfulness.csv") f = f[f["arm"].str.startswith(("F_", "G_", "H_", "I_"))].copy() f["split"] = f["run_id"].map(split_label) order = ["validation", "test (mid)", "test (small)", "holdout 2026", "prospective"] f["k"] = f["split"].map({s: i for i, s in enumerate(order)}) f = f.sort_values(["k", "arm", "committee"]) rows, mid, i, last = [], [], 0, None for _, r in f.iterrows(): if last is not None and r["split"] != last: mid.append(i - 1) last = r["split"] rows.append([escape(r["split"]), short(r["arm"]), COMM[r["committee"]], str(int(r["n_properties"])), num(r["iqr_log_round0"]), num(r["iqr_log_final"]), num(r["convergence"]), num(r["anchoring_index"]), num(r["share_toward_median"])]) i += 1 header = ["Split", "Arm", "Committee", "{$n$}", r"{IQR$_0$}", r"{IQR$_R$}", "{Convergence}", "{Anchoring}", "{To median}"] cols = ["split", "run_id", "arm", "committee", "n_properties", "iqr_log_round0", "iqr_log_final", "convergence", "anchoring_index", "share_toward_median"] write(tabular(header, rows, "lllrrrrrr", midrules_after=mid), "tab_deliberation", f[cols]) # ------------------------------------------------------------------------------------------ 5. committees + extra contrasts def tab_committees_and_extra() -> None: s = pd.read_csv(RES / "evaluation_validation" / "summary.csv") f = pd.read_csv(RES / "evaluation" / "faithfulness.csv").set_index("run_id") rec = records("evaluation_validation") rows, out, i, mid = [], [], 0, [] for arm in ["E_single_llm", "F_independent", "G_debate_r2"]: for comm in ["all_anthropic", "all_openai", "mixed_random"]: x = s[(s["arm"] == arm) & (s["committee"] == comm) & (s["aggregation"] == "median")].iloc[0] run = x["run_id"] fa = f.loc[run] if run in f.index else None if comm != "mixed_random": a = run_records(f"validation_{arm}_mixed_random_mid") b = run_records(run) c = contrast(a, b) d, lo, hi, p = c["diff"], c["ci_lo"], c["ci_hi"], c["p_boot"] else: d = lo = hi = p = np.nan rows.append([short(arm), COMM[comm], str(int(x["n"])), num(x["mean_abs_log_error"]), num(x["p95_abs_log_error"]), num(x["bias_log"]), num(x["coverage_90"]), num(x["mean_log_width_90"]), num(fa["iqr_log_final"]) if fa is not None and arm == "G_debate_r2" else "{--}", num(fa["anchoring_index"]) if fa is not None and arm == "G_debate_r2" else "{--}", num(d) if np.isfinite(d) else "{--}", ci(lo, hi), pnum(p)]) out.append({"arm": arm, "committee": comm, "run_id": run, "n": x["n"], "mean_abs_log_error": x["mean_abs_log_error"], "mdape": x["mdape"], "p95_abs_log_error": x["p95_abs_log_error"], "bias_log": x["bias_log"], "coverage_90": x["coverage_90"], "mean_log_width_90": x["mean_log_width_90"], "cost_usd_mean": x["cost_usd_mean"], "iqr_log_final": fa["iqr_log_final"] if fa is not None else np.nan, "anchoring_index": fa["anchoring_index"] if fa is not None else np.nan, "diff_vs_mixed": d, "ci_lo": lo, "ci_hi": hi, "p_boot": p}) i += 1 mid.append(i - 1) header = ["Arm", "Committee", "{$n$}", r"{Mean $|e|$}", r"{P95 $|e|$}", r"{Bias}", r"{Cov. 90\%}", r"{Width 90\%}", r"{IQR$_R$}", "{Anchoring}", r"{$\Delta$ vs mixed}", r"{95\% CI}", r"{$p$}"] write(tabular(header, rows, "llrrrrrrrrrcr", midrules_after=mid[:-1]), "tab_committees", pd.DataFrame(out)) # exploratory paired contrasts on validation that 20_evaluate.py does not pre-register pairs = [("G_debate_r2", "mixed_random", "G_fullview", "mixed_random", "G-fullview vs G2 (evidence partition)"), ("I_placebo", "mixed_random", "G_fullview", "mixed_random", "G-fullview vs I (prompts at full view)"), ("F_independent", "mixed_random", "G_fullview", "mixed_random", "G-fullview vs F")] rows, out = [], [] for arm_a, ca, arm_b, cb, lab in pairs: for metric, mlab in [("mean_abs_log_error", r"Mean $|e|$"), ("mdape", "MdAPE"), ("p95_abs_log_error", r"P95 $|e|$"), ("coverage_90", r"Cov. 90\%")]: c = contrast(sub(rec, arm_a, ca, "median"), sub(rec, arm_b, cb, "median"), metric) rows.append([lab if metric == "mean_abs_log_error" else "", f"{{{mlab}}}", str(int(c["n"])), num(c["value_a"]), num(c["value_b"]), num(c["diff"]), ci(c["ci_lo"], c["ci_hi"]), pnum(c["p_boot"])]) out.append({"contrast": lab, "metric": metric, **{k: c[k] for k in ["n", "n_blocks", "value_a", "value_b", "diff", "ci_lo", "ci_hi", "se_boot", "p_boot"]}}) header = ["Contrast (B vs A)", "{Metric}", "{$n$}", "{A}", "{B}", r"{$\Delta$}", r"{95\% CI}", r"{$p$ (boot)}"] write(tabular(header, rows, "llrrrrcr", midrules_after=[3, 7]), "tab_contrasts_extra", pd.DataFrame(out)) # ------------------------------------------------------------------------------------------ 6. spatial holdout def tab_spatial() -> None: rec = records("evaluation") rows, out = [], [] for base in ["A_hedonic", "C_gbm", "D_avm"]: sp = sub(rec, base + "_spatial") full = sub(rec, base) a, b = paired(full, sp) # A = model trained with the regions, B = model trained without them for metric, mlab in [("mean_abs_log_error", r"Mean $|e|$"), ("mdape", "MdAPE"), ("p95_abs_log_error", r"P95 $|e|$"), ("bias_log", r"Bias $\bar e$"), ("coverage_90", r"Cov. 90\%")]: c = block_bootstrap_contrast(a, b, metric, B=B, seed=SEED) rows.append([short(base) if metric == "mean_abs_log_error" else "", f"{{{mlab}}}", str(int(c["n"])), num(c["value_a"]), num(c["value_b"]), num(c["diff"]), ci(c["ci_lo"], c["ci_hi"]), pnum(c["p_boot"])]) out.append({"arm": base, "metric": metric, **{k: c[k] for k in ["n", "n_blocks", "value_a", "value_b", "diff", "ci_lo", "ci_hi", "se_boot", "p_boot"]}}) header = ["Arm", "{Metric}", "{$n$}", "{In-region model}", "{Withheld model}", r"{$\Delta$}", r"{95\% CI}", r"{$p$ (boot)}"] write(tabular(header, rows, "llrrrrcr", midrules_after=[4, 9]), "tab_spatial", pd.DataFrame(out)) # ------------------------------------------------------------------------------------------ 7. compact strata STRATA = [("region_group", "Region"), ("urban_class", "Urban class"), ("property_class", "Property class"), ("price_tercile", "Price tercile"), ("year_built_decade", "Construction decade")] def tab_strata_compact() -> None: s = pd.read_csv(RES / "evaluation" / "strata.csv") s = s[s["metric"] == "mean_abs_log_error"] arms = ["D_avm", "E_single_llm", "F_independent", "G_debate_r2", "I_placebo", "J_cost_matched", "G_debate_r2_small"] rows, out, mid, i = [], [], [], 0 for stratum, lab in STRATA: g = s[s["stratum"] == stratum] levels = list(dict.fromkeys(g["level"])) for lv in levels: row = [escape(f"{lab}: {lv}")] rec = {"stratum": stratum, "level": lv} nd = g[(g["arm"] == "D_avm") & (g["level"] == lv)] nm = g[(g["arm"] == "G_debate_r2") & (g["level"] == lv)] ns = g[(g["arm"] == "G_debate_r2_small") & (g["level"] == lv)] row += [str(int(nd["n"].iloc[0])) if len(nd) else "{--}", str(int(nm["n"].iloc[0])) if len(nm) else "{--}", str(int(ns["n"].iloc[0])) if len(ns) else "{--}"] rec.update({"n_full": nd["n"].iloc[0] if len(nd) else np.nan, "n_mid": nm["n"].iloc[0] if len(nm) else np.nan, "n_small": ns["n"].iloc[0] if len(ns) else np.nan}) for a in arms: x = g[(g["arm"] == a) & (g["level"] == lv)] v = float(x["value"].iloc[0]) if len(x) and not bool(x["suppressed"].iloc[0]) else np.nan row.append(num(v)) rec[a] = v rows.append(row) out.append(rec) i += 1 mid.append(i - 1) header = ["Stratum", "{$n$ full}", "{$n$ mid}", "{$n$ small}"] + [f"{{{short(a)}}}" for a in arms] write(tabular(header, rows, "lrrr" + "r" * len(arms), midrules_after=mid[:-1]), "tab_strata_compact", pd.DataFrame(out)) # ------------------------------------------------------------------------------------------ 8. conditional coverage def tab_coverage_subgroups() -> None: c = pd.read_csv(RES / "evaluation" / "coverage.csv") c = c[(c["kind"] == "interval") & (c["group"] != "all") & (c["nominal"].isin([0.5, 0.9]))] arms = ["D_avm", "E_single_llm", "F_independent", "G_debate_r2", "H_debate_skeptic", "I_placebo", "J_cost_matched", "G_debate_r2_small"] groups = [("region_group", "Region"), ("property_class", "Property class"), ("price_tercile", "Price tercile")] rows, out, mid, i = [], [], [], 0 for nominal in [0.9, 0.5]: for grp, lab in groups: g = c[(c["group"] == grp) & (c["nominal"] == nominal)] for lv in list(dict.fromkeys(g["level_value"])): row = [escape(f"{lab}: {lv}")] rec = {"nominal": nominal, "group": grp, "level": lv} nm = g[(g["arm"] == "G_debate_r2") & (g["level_value"] == lv)] ns = g[(g["arm"] == "G_debate_r2_small") & (g["level_value"] == lv)] row += [str(int(nm["n"].iloc[0])) if len(nm) else "{--}", str(int(ns["n"].iloc[0])) if len(ns) else "{--}"] rec.update({"n_mid": nm["n"].iloc[0] if len(nm) else np.nan, "n_small": ns["n"].iloc[0] if len(ns) else np.nan}) for a in arms: x = g[(g["arm"] == a) & (g["level_value"] == lv)] v = float(x["empirical"].iloc[0]) if len(x) and not bool(x["suppressed"].iloc[0]) else np.nan row.append(num(v)) rec[a] = v rows.append(row) out.append(rec) i += 1 mid.append(i - 1) header = ["Subgroup", "{$n$ mid}", "{$n$ small}"] + [f"{{{short(a)}}}" for a in arms] write(tabular(header, rows, "lrr" + "r" * len(arms), midrules_after=mid[:-1]), "tab_coverage_subgroups", pd.DataFrame(out)) # ------------------------------------------------------------------------------------------ 9. drift def tab_drift() -> None: rows, out = [], [] cols = ["mean_abs_log_error", "mdape", "p95_abs_log_error", "bias_log", "severe_rate", "over_rate", "coverage_50", "coverage_90", "mean_log_width_90"] for split_dir, lab in [("evaluation", "test"), ("evaluation_holdout", "holdout 2026"), ("evaluation_prospective", "prospective")]: s = pd.read_csv(RES / split_dir / "summary_main.csv").set_index("arm") rec = records(split_dir) g2 = sub(rec, "G_debate_r2", "mixed_random", "median") d_full = s.loc["D_avm"] d_pair, _ = paired(sub(rec, "D_avm"), g2) from agentic_valuation.evaluation.metrics import summarise_records # noqa: E402 dp = summarise_records(d_pair) entries = [("D (full partition)", d_full.to_dict()), ("D (paired subsample)", dp)] for arm in ["E_single_llm", "F_independent", "G_debate_r2"]: entries.append((short(arm), s.loc[arm].to_dict())) for k, (name, v) in enumerate(entries): rows.append([escape(lab) if k == 0 else "", name, str(int(v["n"]))] + [num(v[c]) for c in cols]) out.append({"split": lab, "arm": name, "n": v["n"], **{c: v[c] for c in cols}}) header = ["Split", "Arm", "{$n$}", r"{Mean $|e|$}", "{MdAPE}", r"{P95 $|e|$}", r"{Bias $\bar e$}", r"{$|e|>\log 1.25$}", r"{Over +25\%}", r"{Cov. 50\%}", r"{Cov. 90\%}", r"{Width 90\%}"] write(tabular(header, rows, "llr" + "r" * len(cols), midrules_after=[4, 9]), "tab_drift", pd.DataFrame(out)) # ------------------------------------------------------------------------------------------ 10. faithfulness with split def tab_faithfulness() -> None: f = pd.read_csv(RES / "evaluation" / "faithfulness.csv").copy() f["split"] = f["run_id"].map(split_label) order = ["test (mid)", "test (small)", "holdout 2026", "prospective", "validation"] f["k"] = f["split"].map({s: i for i, s in enumerate(order)}) f = f.sort_values(["k", "arm", "committee"]) rows, mid, i, last = [], [], 0, None for _, r in f.iterrows(): if last is not None and r["split"] != last: mid.append(i - 1) last = r["split"] rows.append([escape(r["split"]), short(r["arm"]), COMM[r["committee"]], str(int(r["n_properties"])), str(int(r["n_turns"])), num(r["cited_share_valid"]), num(r["adj_share_within_40"]), num(r["share_turns_adj_ok"]), num(r["point_in_hull"]), num(r["quantile_sane"]), num(r["summary_words"], 0), num(r["summary_within_limit"]), num(r["validation_retries"])]) i += 1 header = ["Split", "Arm", "Committee", "{$n$}", "{Turns}", "{Valid ids}", r"{Adj. $\pm$40\%}", "{Turns ok}", "{In hull}", "{Quantiles ok}", "{Words}", r"{$\le$120}", "{Retries}"] cols = ["split", "run_id", "arm", "committee", "n_properties", "n_turns", "cited_share_valid", "share_turns_all_ids_valid", "adj_share_within_40", "share_turns_adj_ok", "point_in_hull", "hull_deviation_justified", "quantile_sane", "summary_words", "summary_within_limit", "validation_retries", "packet_hash_match"] write(tabular(header, rows, "lllrrrrrrrrrr", midrules_after=mid), "tab_faithfulness", f[cols]) # ------------------------------------------------------------------------------------------ 11. conformal rescaling def tab_conformal() -> None: """Split-conformal rescaling of the LLM intervals with the factors of results/evaluation/llm_conformal_scales.json (estimated on the validation runs only, Section 3.6 of docs/evaluation_protocol.md), applied unchanged to the test, holdout and prospective runs of the same arm and committee. Point and median are untouched.""" scales = json.loads((RES / "evaluation" / "llm_conformal_scales.json").read_text()) by_arm = {(v["arm"], v["committee"]): v["scales"] for v in scales.values()} rows, out, mid, i = [], [], [], 0 for split_dir, lab, arms in [("evaluation", "test (mid)", ["E_single_llm", "F_independent", "G_debate_r2", "J_cost_matched"]), ("evaluation_holdout", "holdout 2026", ["E_single_llm", "F_independent", "G_debate_r2"]), ("evaluation_prospective", "prospective", ["E_single_llm", "F_independent", "G_debate_r2"])]: rec = records(split_dir) for k, arm in enumerate(arms): r = sub(rec, arm, "mixed_random", "median") sc = by_arm[(arm, "mixed_random")] y, c = np.log(r["price"].to_numpy(float)), np.log(r["q50"].to_numpy(float)) l90, u90 = c - np.log(r["q05"].to_numpy(float)), np.log(r["q95"].to_numpy(float)) - c l50, u50 = c - np.log(r["q25"].to_numpy(float)), np.log(r["q75"].to_numpy(float)) - c k90, k50 = sc["scale_90"], sc["scale_50"] cov90 = float(np.mean((y >= c - k90 * l90) & (y <= c + k90 * u90))) cov50 = float(np.mean((y >= c - k50 * l50) & (y <= c + k50 * u50))) w90 = float(np.mean(k90 * (l90 + u90))) rows.append([escape(lab) if k == 0 else "", short(arm), str(len(r)), num(float(r["cov_50"].mean())), num(float(r["cov_90"].mean())), num(float(r["width_90"].mean())), num(k50), num(k90), num(cov50), num(cov90), num(w90)]) out.append({"split": lab, "arm": arm, "n": len(r), "coverage_50_raw": float(r["cov_50"].mean()), "coverage_90_raw": float(r["cov_90"].mean()), "width_90_raw": float(r["width_90"].mean()), "scale_50": k50, "scale_90": k90, "coverage_50_conformal": cov50, "coverage_90_conformal": cov90, "width_90_conformal": w90}) i += 1 mid.append(i - 1) header = ["Split", "Arm", "{$n$}", r"{Cov. 50\% raw}", r"{Cov. 90\% raw}", r"{Width 90\% raw}", r"{$k_{50}$}", r"{$k_{90}$}", r"{Cov. 50\% conf.}", r"{Cov. 90\% conf.}", r"{Width 90\% conf.}"] write(tabular(header, rows, "llrrrrrrrrr", midrules_after=mid[:-1]), "tab_conformal", pd.DataFrame(out)) def main() -> None: OUT.mkdir(parents=True, exist_ok=True) tab_conformal() tab_primary_effects() tab_aggregation() tab_rounds() tab_deliberation() tab_committees_and_extra() tab_spatial() tab_strata_compact() tab_coverage_subgroups() tab_drift() tab_faithfulness() (RES / "tables" / "extra_tables_manifest.json").write_text(json.dumps({"script": "scripts/22_extra_tables.py", "B": B, "seed": SEED, "fragments": sorted(p.name for p in OUT.glob("tab_*.tex"))}, indent=1)) if __name__ == "__main__": main()