| """ |
| Build the Claim 5 figures from the two ResNet-50 / CIFAR-10 self-distillation runs: |
| * K=8, n=5000, eta=0.4 -> weak-teacher regime: clear U-shape (min at t*=2). |
| * K=4, n=10000, eta=0.4/0.6 -> strong-teacher regime: monotone denoising. |
| |
| Together they show the denoising->forgetting trade-off and its regime dependence. |
| Produces a Plotly HTML (logbook) + CSV (raw) and a matplotlib PNG (poster). |
| """ |
| import sys, json, numpy as np, pandas as pd |
| sys.path.insert(0, "src") |
| from plotting import new_fig, save, PALETTE |
| import plotly.graph_objects as go |
|
|
| ext = json.load(open("outputs/claim5/cifar_results_K8_n5000.json"))["curves"] |
| base = json.load(open("outputs/claim5/cifar_results_K4_n10000.json"))["curves"] |
|
|
| e04 = ext["0.4"] |
| b04 = base["0.4"] |
| b06 = base.get("0.6") |
|
|
| rows = [] |
| tstar = int(np.argmin(e04)) |
| from plotly.subplots import make_subplots |
| fig = make_subplots(rows=1, cols=2, horizontal_spacing=0.13, subplot_titles=( |
| "Weak teacher (n=5000, K=8): U-shape", "Strong teacher (n=10000, K=4): denoising")) |
| fig.add_trace(go.Scatter(x=list(range(len(e04))), y=e04, mode="lines+markers", |
| line=dict(color=PALETTE[3], width=3), marker=dict(size=9), name="η=0.4 (n=5k)"), 1, 1) |
| fig.add_trace(go.Scatter(x=[tstar], y=[e04[tstar]], mode="markers", showlegend=True, |
| marker=dict(symbol="star", size=18, color=PALETTE[3], line=dict(color="black", width=1)), |
| name=f"t*={tstar}"), 1, 1) |
| fig.add_trace(go.Scatter(x=list(range(len(b04))), y=b04, mode="lines+markers", |
| line=dict(color=PALETTE[0], width=3), marker=dict(size=8), name="η=0.4 (n=10k)"), 1, 2) |
| if b06: |
| fig.add_trace(go.Scatter(x=list(range(len(b06))), y=b06, mode="lines+markers", |
| line=dict(color=PALETTE[2], width=3), marker=dict(size=8), name="η=0.6 (n=10k)"), 1, 2) |
| fig.update_xaxes(title_text="iteration t", row=1, col=1) |
| fig.update_xaxes(title_text="iteration t", row=1, col=2) |
| fig.update_yaxes(title_text="test error (%)", row=1, col=1) |
| fig.update_yaxes(title_text="test error (%)", row=1, col=2) |
| fig.update_layout(template="plotly_white", width=900, height=430, |
| title="Claim 5: ResNet-50 / CIFAR-10 self-distillation — denoising vs forgetting", |
| margin=dict(l=60, r=20, t=80, b=50)) |
| for name, arr, cfg in [("weak_n5k_K8_eta0.4", e04, "n=5000,K=8"), |
| ("strong_n10k_K4_eta0.4", b04, "n=10000,K=4"), |
| ("strong_n10k_K4_eta0.6", b06 or [], "n=10000,K=4")]: |
| for t, v in enumerate(arr): |
| rows.append(dict(series=name, config=cfg, t=t, test_error=v)) |
| save(fig, pd.DataFrame(rows), "outputs/claim5", "claim5_cifar") |
| print(f"weak-teacher eta=0.4 (n=5000,K=8): U-shape, t*={tstar}, " |
| f"min={e04[tstar]:.1f}% vs t0={e04[0]:.1f}%, t8={e04[-1]:.1f}%") |
| print(f"strong-teacher eta=0.4 (n=10000,K=4): {b04[0]:.1f}% -> {min(b04):.1f}% (denoising)") |
|
|
| |
| import matplotlib; matplotlib.use("Agg"); import matplotlib.pyplot as plt |
| plt.rcParams.update({"font.size": 20, "axes.linewidth": 1.6, "font.family": "DejaVu Sans", |
| "axes.spines.top": False, "axes.spines.right": False}) |
| fig2, (a1, a2) = plt.subplots(1, 2, figsize=(8.2, 3.9)) |
| a1.plot(range(len(e04)), e04, color="#C1443C", lw=3, marker="o", ms=9, |
| markeredgecolor="white", markeredgewidth=1.3) |
| a1.scatter([tstar], [e04[tstar]], marker="*", s=460, color="#C1443C", edgecolor="k", zorder=6) |
| a1.set_title("weak teacher (n=5k, K=8)\nU-shape, t*=2", fontsize=16) |
| a1.set_xlabel("iteration t"); a1.set_ylabel("test error (%)") |
| a2.plot(range(len(b04)), b04, color="#2D5F8B", lw=3, marker="s", ms=9, |
| markeredgecolor="white", markeredgewidth=1.2, label="η=0.4") |
| a2.plot(range(len(b06)), b06, color="#4E9B47", lw=3, marker="^", ms=9, |
| markeredgecolor="white", markeredgewidth=1.2, label="η=0.6") |
| a2.set_title("strong teacher (n=10k, K=4)\nmonotone denoising", fontsize=16) |
| a2.set_xlabel("iteration t"); a2.set_ylabel("test error (%)") |
| a2.legend(frameon=False, fontsize=15) |
| for ax in (a1, a2): |
| ax.grid(alpha=0.18, linewidth=1.0); ax.tick_params(width=1.6, length=6) |
| fig2.tight_layout() |
| fig2.savefig("poster_images/fig_cifar.png", dpi=200, bbox_inches="tight", facecolor="white") |
| print("wrote poster_images/fig_cifar.png (2-panel)") |
|
|