"""damping_check.py (run 5): compare the measured ratio of AdamW step sizes (eps=1e-8 / eps=1e-16, from update_size_*.csv, N=88 seed 0)
with the one-line prediction g_rms/(g_rms+eps), where g_rms is the per-coordinate RMS gradient of the eps=1e-8 run.
Prediction assumes m_hat ~ sqrt(v_hat) ~ g per coordinate in steady state. Output: damping_check.txt"""
import csv
def load(p): return {int(r['step']):r for r in csv.DictReader(open(p))}
a=load('update_size_eps1e-8.csv'); b=load('update_size_eps1e-16.csv')
print("step  frac_sat  g_rms(1e-8)  step/lr(1e-8)  step/lr(1e-16)  ratio_meas  pred g/(g+eps)  test(1e-8) test(1e-16)")
for s in sorted(set(a)&set(b)):
    if s%200: continue
    g=float(a[s]['rms_grad']); r=float(a[s]['rms_step_over_lr'])/float(b[s]['rms_step_over_lr']); pred=g/(g+1e-8)
    print(f"{s:5d}  {a[s]['frac_sat']}   {g:.2e}   {float(a[s]['rms_step_over_lr']):.3f}   {float(b[s]['rms_step_over_lr']):.3f}   {r:.3f}   {pred:.3f}   {a[s]['test_acc']} {b[s]['test_acc']}")
