File size: 1,272 Bytes
79bd9ac | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | """Build the Figure-6a reproduction plot from the CIFAR self-distillation results JSON."""
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
src = sys.argv[1] if len(sys.argv) > 1 else "outputs/claim5/cifar_results.json"
res = json.load(open(src))
K = res["config"]["K"]
its = list(range(K + 1))
fig = new_fig("Claim 5 (Fig 6a): ResNet-50 / CIFAR-10 self-distillation test error",
"self-distillation iteration t", "test error (%)")
rows = []
for i, (eta, errs) in enumerate(sorted(res["curves"].items(), key=lambda kv: float(kv[0]))):
fig.add_trace(go.Scatter(x=its, y=errs, mode="lines+markers",
line=dict(color=PALETTE[i], width=2.5),
marker=dict(size=9, line=dict(color="white", width=1)),
name=f"η={eta}"))
tstar = int(np.argmin(errs))
shape = "U-shaped" if 0 < tstar < K else ("monotone↓" if tstar == K else "↑")
print(f"eta={eta}: {['%.1f'%e for e in errs]} t*={tstar} ({shape})")
for t, e in zip(its, errs):
rows.append(dict(eta=float(eta), t=t, test_error=e))
save(fig, pd.DataFrame(rows), "outputs/claim5", "claim5_fig6a_cifar")
|