"""Analyze Claim 1 results: MSE/MAE improvement of Informer+DropoutTS vs baseline on the synthetic noise sweep, plus Claim 4c training-time comparison. Reads claim1_results.json (from `modal run modal_repro.py::claim1`), writes: - claim1_table.csv (per noise x horizon) - claim1_plot.html (plotly: MSE improvement % by noise level) - prints a summary vs the paper's claimed 46.0% MSE / 24.5% MAE, peak 48.2% @sigma=0.3 """ import json, sys, statistics as st results = json.load(open("claim1_results.json")) # index by (noise, horizon, dropout) by = {} for r in results: if not r or not r.get("metrics"): continue key = (r["noise"], r["output_len"], r["dropout"]) by[key] = r rows = [] noises = sorted({r["noise"] for r in results if r}) horizons = sorted({r["output_len"] for r in results if r}) for nl in noises: for h in horizons: b = by.get((nl, h, False)) d = by.get((nl, h, True)) if not b or not d: continue bm, dm = b["metrics"]["overall"], d["metrics"]["overall"] mse_imp = (bm["MSE"] - dm["MSE"]) / bm["MSE"] * 100 mae_imp = (bm["MAE"] - dm["MAE"]) / bm["MAE"] * 100 # per-epoch train time (Claim 4c) bpe = b["train_seconds"] / max(b.get("epochs_run") or 1, 1) dpe = d["train_seconds"] / max(d.get("epochs_run") or 1, 1) rows.append({ "noise": nl, "horizon": h, "mse_base": bm["MSE"], "mse_drop": dm["MSE"], "mse_imp_pct": mse_imp, "mae_base": bm["MAE"], "mae_drop": dm["MAE"], "mae_imp_pct": mae_imp, "base_s_per_ep": bpe, "drop_s_per_ep": dpe, "base_epochs": b.get("epochs_run"), "drop_epochs": d.get("epochs_run"), "base_total_s": b["train_seconds"], "drop_total_s": d["train_seconds"], }) # CSV import csv with open("claim1_table.csv", "w", newline="") as f: w = csv.DictWriter(f, fieldnames=list(rows[0].keys())) w.writeheader(); w.writerows(rows) # Summary mse_imps = [r["mse_imp_pct"] for r in rows] mae_imps = [r["mae_imp_pct"] for r in rows] avg_mse = st.mean(mse_imps); avg_mae = st.mean(mae_imps) peak = max(rows, key=lambda r: r["mse_imp_pct"]) print("=" * 72) print("CLAIM 1 — Informer +DropoutTS on synthetic noise sweep") print("=" * 72) print(f"{'noise':>6} {'H':>5} {'MSE base':>10} {'MSE drop':>10} {'dMSE%':>8} {'dMAE%':>8}") for r in rows: print(f"{r['noise']:>6} {r['horizon']:>5} {r['mse_base']:>10.4f} {r['mse_drop']:>10.4f} " f"{r['mse_imp_pct']:>8.1f} {r['mae_imp_pct']:>8.1f}") print("-" * 72) print(f"AVERAGE across all noise x horizon: MSE {avg_mse:+.1f}% MAE {avg_mae:+.1f}%") print(f" Paper Claim 1 (Informer): MSE +46.0% MAE +24.5%") print(f"PEAK MSE improvement: {peak['mse_imp_pct']:+.1f}% at sigma={peak['noise']}, H={peak['horizon']}") print(f" Paper peak: +48.2% at sigma=0.3") # per-sigma averages (over horizons) for the plot per_sigma = {} for nl in noises: sub = [r for r in rows if r["noise"] == nl] if sub: per_sigma[nl] = st.mean([r["mse_imp_pct"] for r in sub]) # Claim 4c summary print("\n" + "=" * 72) print("CLAIM 4c — training time (baseline vs +DropoutTS)") print("=" * 72) spe = st.mean([r["drop_s_per_ep"] / r["base_s_per_ep"] for r in rows if r["base_s_per_ep"]]) tot = st.mean([r["drop_total_s"] / r["base_total_s"] for r in rows if r["base_total_s"]]) print(f"mean per-epoch time ratio (drop/base): {spe:.2f}x (>1 => dropout SLOWER per epoch)") print(f"mean total wall-clock ratio(drop/base): {tot:.2f}x") print(f" Paper Claim 4c: 1.12-1.45x training SPEEDUP") # Plotly figure try: import plotly.graph_objects as go xs = [str(n) for n in per_sigma] ys = [per_sigma[n] for n in per_sigma] fig = go.Figure() fig.add_bar(x=xs, y=ys, name="Measured MSE improvement %", marker_color="#4C78A8", text=[f"{v:.1f}%" for v in ys], textposition="outside") fig.add_hline(y=46.0, line_dash="dash", line_color="#E45756", annotation_text="Paper avg 46.0%") fig.update_layout( title="Claim 1: Informer + DropoutTS — MSE improvement vs noise level (avg over horizons)", xaxis_title="Noise level sigma", yaxis_title="MSE improvement %", template="plotly_white", height=460) fig.write_html("claim1_plot.html", include_plotlyjs="inline") print("\nWrote claim1_plot.html, claim1_table.csv") except ImportError: print("\n(plotly not installed; wrote claim1_table.csv only)")