edumirror-repro-code / experiments /make_wide_figures.py
ygoldi's picture
Upload folder using huggingface_hub
ca7c787 verified
Raw
History Blame Contribute Delete
4.68 kB
"""Wide two-panel versions of the Claim 3 and Claim 4 figures.
Why: the single-panel square versions render at ~42-45% of a poster column's
width (posterly polish: FIG/SQUARE, FIG/WIDE want >=55-75%). Rather than shrink
the cards, we widen the figures by adding a genuinely informative second panel.
"""
import json, matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
METHODS = ["EduMirror", "LLMob", "BabyAGI", "D2A", "ReAct"]
# ---------------- Claim 3: scatter + per-arm RSES pre/post ----------------
d3 = json.load(open("/tmp/res/claim3/claim3.json"))
recs = [r for r in d3["records"] if r.get("delta_rses") is not None]
fig, (a1, a2) = plt.subplots(1, 2, figsize=(11.4, 4.5))
arms = ["neglectful", "authoritative_punitive", "supportive_individual", "supportive_cooperative"]
cols = {"neglectful": "#C44E52", "authoritative_punitive": "#DD8452",
"supportive_individual": "#55A868", "supportive_cooperative": "#4C72B0"}
for arm in arms:
pts = [(r["delta_value"], r["delta_rses"]) for r in recs if r["arm"] == arm]
if pts:
a1.scatter([p[0] for p in pts], [p[1] for p in pts], s=90, alpha=.85,
color=cols[arm], label=arm.replace("_", " "), edgecolor="w", zorder=3)
xs = [r["delta_value"] for r in recs]; ys = [r["delta_rses"] for r in recs]
coef = np.polyfit(xs, ys, 1); xr = np.linspace(min(xs), max(xs), 50)
a1.plot(xr, np.polyval(coef, xr), "--", color="#333", lw=1.3, zorder=2)
a1.axhline(0, color="#ccc", lw=.8); a1.axvline(0, color="#ccc", lw=.8)
a1.set_xlabel("Δ internal value ('self worth', 'sense of respect')")
a1.set_ylabel("Δ RSES total (external, 10–40)")
a1.set_title("Internal state vs external instrument\nr = 0.943, ρ = 0.951, n = 12")
a1.legend(fontsize=7.5); a1.grid(alpha=.3)
pre = [np.mean([r["rses_pre"] for r in recs if r["arm"] == a]) for a in arms]
post = [np.mean([r["rses_post"] for r in recs if r["arm"] == a]) for a in arms]
x = np.arange(4); w = .38
a2.bar(x - w/2, pre, w, label="RSES pre", color="#BBB")
a2.bar(x + w/2, post, w, label="RSES post", color=[cols[a] for a in arms])
a2.set_xticks(x); a2.set_xticklabels(["neglect\n(control)", "authoritative\npunitive",
"supportive\nindividual", "supportive\ncooperative"], fontsize=8)
a2.set_ylabel("RSES total (10–40)"); a2.set_ylim(10, 40)
a2.set_title("Victim self-esteem, pre → post\nNeglect: 31.0 → 19.7; every intervention arrests it")
a2.legend(fontsize=8); a2.grid(axis="y", alpha=.3)
for i, (b, p) in enumerate(zip(pre, post)):
a2.text(i + w/2, p + .6, f"{p:.1f}", ha="center", fontsize=8,
fontweight="bold" if arms[i] == "neglectful" else "normal")
fig.tight_layout(); fig.savefig("outputs/figures/claim3_rses_validity.png", dpi=150); plt.close(fig)
print("claim3 wide written")
# ---------------- Claim 4: heatmap + average win rate ----------------
d4 = json.load(open("/tmp/res/claim4_72b/claim4.json"))
mat = np.array([[d4["matrix"][r].get(c, np.nan) for c in METHODS] for r in METHODS], float)
fig, (b1, b2) = plt.subplots(1, 2, figsize=(11.4, 4.6),
gridspec_kw={"width_ratios": [1.25, 1]})
im = b1.imshow(mat, cmap="RdYlBu_r", vmin=0, vmax=1)
b1.set_xticks(range(5)); b1.set_xticklabels(METHODS, rotation=30, ha="right", fontsize=8)
b1.set_yticks(range(5)); b1.set_yticklabels(METHODS, fontsize=8)
b1.set_xlabel("Column model"); b1.set_ylabel("Row model")
for i in range(5):
for j in range(5):
v = mat[i, j]
b1.text(j, i, "--" if v != v else f"{v:.2f}", ha="center", va="center",
fontsize=8, color="white" if (v == v and (v < .28 or v > .72)) else "black")
fig.colorbar(im, ax=b1, fraction=.046, label="win rate, column vs row")
b1.set_title("Pairwise win rates (72B validated judge)\n6 scenarios, 120 comparisons, all decided")
aw = d4["average_win_rate"]
order = sorted(METHODS, key=lambda m: -aw[m])
vals = [aw[m] for m in order]
colors = ["#4C72B0" if m == "EduMirror" else "#BBB" for m in order]
b2.barh(range(5), vals, color=colors)
b2.set_yticks(range(5)); b2.set_yticklabels(order, fontsize=9); b2.invert_yaxis()
b2.axvline(.5, color="#333", ls=":", lw=1)
b2.set_xlabel("Average win rate vs all opponents"); b2.set_xlim(0, .8)
b2.set_title("EduMirror is NOT top: LLMob leads\n(paper claims EduMirror strongest)")
for i, v in enumerate(vals):
b2.text(v + .012, i, f"{v:.3f}", va="center", fontsize=9,
fontweight="bold" if order[i] == "EduMirror" else "normal")
b2.grid(axis="x", alpha=.3)
fig.tight_layout(); fig.savefig("outputs/figures/claim4_heatmap.png", dpi=150); plt.close(fig)
print("claim4 wide written | avg win:", {m: aw[m] for m in order})