| """Claims 4 & 5: find the corner where the bounds are actually non-vacuous. |
| |
| Theorems 3 and 4 both carry an exponential prefactor, |
| |
| Thm 3: F^gen <= C * (eta*T/n) * exp( eta*T*(K-k+1)/sqrt(m) ) |
| Thm 4: F^gen <= C * (eta/n) * sum_t Fhat * exp( eta*c_kK /sqrt(m) ) |
| |
| On the main exp4 grid (eta = 100) those exponents run from 71 to 15179, so both |
| right-hand sides exceed the measured gap by 30 to 300+ orders of magnitude. |
| "The bound holds" is then true but empty: it would hold for any conceivable |
| measurement. The question worth answering is whether there is *any* reachable |
| setting in which the bounds say something, and whether they hold there. |
| |
| The exponent is O(1) when eta*T*K / sqrt(m) is O(1). That is reachable with a |
| small step size and a wide network: eta = 1, T <= 100, m up to 1e4 gives |
| eta*T*K/sqrt(m) in [0.2, 6.7], i.e. an exp factor of at most ~800 rather |
| than 10^103. |
| |
| Grid: d=50, K=3, logistic loss, eta=1, T in {10,25,50,100}, |
| m in {2000,10000}, n in {200,800,3200}, 6 seeds = 144 runs. |
| Cheap: K*T <= 300 GD steps, and both the width and sample size stay modest. |
| """ |
|
|
| import json |
| import os |
| import sys |
| import time |
| from multiprocessing import Pool |
|
|
| import numpy as np |
|
|
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
| import clcore as C |
|
|
| OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "results") |
| os.makedirs(OUT, exist_ok=True) |
|
|
| D, K, ETA, SIGMA_C = 50, 3, 1.0, 0.1 |
| TS = [10, 25, 50, 100] |
| MS = [2000, 10000] |
| NS = [200, 800, 3200] |
| SEEDS = list(range(6)) |
| NPROC = int(os.environ.get("CL_NPROC", 3)) |
|
|
|
|
| def one(job): |
| T, m, n, seed = job |
| r = C.continual_run(d=D, m=m, K=K, n=n, T=T, eta=ETA, sigma_c=SIGMA_C, |
| loss_name="logistic", seed=seed, n_test=4000) |
| k = 0 |
| gap = C.gen_gap(r, k) |
| ck = float(sum(r["cum_train_loss"][k + 1:])) |
| ex3 = float(ETA * T * (K - k) / np.sqrt(m)) |
| ex4 = float(ETA * ck / np.sqrt(m)) |
| core3 = float(ETA * T / n) |
| core4 = float((ETA / n) * r["cum_train_loss"][k]) |
| return dict( |
| T=T, m=m, n=n, seed=seed, d=D, K=K, eta=ETA, |
| gen_gap=gap, |
| train_forget=C.train_forgetting(r, k), |
| test_forget=C.test_forgetting(r, k), |
| c_kK=ck, |
| exponent_thm3=ex3, exponent_thm4=ex4, |
| rhs_thm3_core=core3, rhs_thm4_core=core4, |
| rhs_thm3=float(core3 * np.exp(min(ex3, 700.0))), |
| rhs_thm4=float(core4 * np.exp(min(ex4, 700.0))), |
| train_loss_end=float(r["loss_at"][K - 1, k]), |
| test_loss_end=float(r["test_loss_at"][K - 1, k])) |
|
|
|
|
| if __name__ == "__main__": |
| jobs = [(T, m, n, s) for T in TS for m in MS for n in NS for s in SEEDS] |
| print(len(jobs), "runs", flush=True) |
| t0 = time.time() |
| recs = [] |
| with Pool(NPROC) as p: |
| for i, r in enumerate(p.imap_unordered(one, jobs)): |
| recs.append(r) |
| if (i + 1) % 12 == 0: |
| print(f" {i+1}/{len(jobs)} {time.time()-t0:.0f}s", flush=True) |
| with open(os.path.join(OUT, "exp8_nonvacuous.json"), "w") as f: |
| json.dump(recs, f) |
| print("wrote exp8_nonvacuous.json", f"{time.time()-t0:.0f}s", flush=True) |
|
|