icml2026-repro-l35QweVxgn-code / code /exp7_decomp_mc.py
nmaher's picture
Add exp6-8 drivers, results JSON, figures, poster, dataset card; drop duplicated root-level code copies
857044b verified
Raw
History Blame Contribute Delete
2.9 kB
"""Control for Claim 6: is the decomposition inequality really violated?
The paper's Eq. (near line 244 of main.tex) states, in the interpolating regime,
F^ts_{k,K} <= F^tr_{k,K} + F^gen_{k,K}
obtained by dropping the non-negative term F_k(w_k) - Fhat_k(w_k) (the
generalization gap of task k at the moment it finished training). On the
claim-6 grid of exp3_regime.py the inequality fails in 13 of 48 individual
runs. Those failures are exactly the runs where the dropped term comes out
negative, which cannot happen in expectation but can easily happen in a single
run because F_k is estimated from a finite test set.
This script re-measures the dropped term at the four corners of the claim-6
(n, m) grid with a 10x larger test set (n_test 3000 -> 20000), which cuts the
Monte-Carlo standard deviation by about sqrt(20000/3000) ~ 2.6. If the violations are
Monte-Carlo artifacts, the fraction of negative values must fall sharply; if
the inequality is genuinely violated somewhere, the negative values survive.
Single-process and modest: 20 runs, run after the exp4/exp5 sweeps finish.
"""
import json
import os
import sys
import time
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import clcore as C # noqa: E402
OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "results")
os.makedirs(OUT, exist_ok=True)
# Same base point as the claim-6 block of exp3_regime.py.
D, K, T, ETA = 50, 3, 200, 8.0
CORNERS = [(125, 50), (125, 5000), (4000, 50), (4000, 5000)]
SEEDS = [0, 1, 2, 3, 4]
N_TEST = 20000
if __name__ == "__main__":
t0 = time.time()
recs = []
total = len(CORNERS) * len(SEEDS)
for n, m in CORNERS:
for s in SEEDS:
r = C.continual_run(d=D, m=m, K=K, n=n, T=T, eta=ETA,
sigma_c=0.1, loss_name="hinge", seed=s,
n_test=N_TEST)
k = 0
tr = C.train_forgetting(r, k)
ts = C.test_forgetting(r, k)
gg = C.gen_gap(r, k)
recs.append(dict(
n=n, m=m, seed=s, d=D, K=K, T=T, eta=ETA, n_test=N_TEST,
train_forget=tr, test_forget=ts, gen_gap=gg,
# the term the paper drops; theory says it is >= 0
dropped_term=float(r["test_loss_at"][k, k] - r["loss_at"][k, k]),
# positive slack == the stated inequality is violated
slack=float(ts - (tr + gg)),
train_loss_own=float(r["loss_at"][k, k]),
test_loss_own=float(r["test_loss_at"][k, k]),
))
print(f" {len(recs)}/{total} n={n} m={m} seed={s} "
f"{time.time() - t0:.0f}s", flush=True)
path = os.path.join(OUT, "exp7_decomp_mc.json")
with open(path, "w") as f:
json.dump(recs, f)
print("wrote exp7_decomp_mc.json", f"{time.time() - t0:.0f}s", flush=True)