"""Size curve for browsecomp-plus-mini under the honest three-way protocol, repeated over several system splits (a single test split holds only six systems, so one split is a noisy estimate). Per subset size n and split seed: split SYSTEMS three ways (select / validate / test, stratified by accuracy); fit every candidate method on SELECT; choose the method on VALIDATE; refit it on SELECT+VALIDATE; score on TEST only. usage: python sizes.py INPUT_DIR [n_seeds] -> prints a table, writes size_curve.json (moved to data/size_curve.json) """ import sys, json import numpy as np from mini_lib import load, honest_pick, rho_on, pair_agreement, calibrated_mae, wspearman D = load(sys.argv[1]) SEEDS = int(sys.argv[2]) if len(sys.argv) > 2 else 10 X, full, w, systems, pool = D["X"], D["full"], D["w"], D["systems"], D["pool"] rng = np.random.default_rng(12345) curve = {} for n in (10, 12, 15, 20, 30): rhos, maes, rand_rhos, bands, chosen = [], [], [], {}, [] for seed in range(SEEDS): h = honest_pick(D, n, seed) si, vi, ti = h["idx"]; sub = X[:, h["subset"]].mean(1); chosen.append(h["method"]) rhos.append(rho_on(D, h["subset"], ti)) maes.append(calibrated_mae(full, sub, w, np.concatenate([si, vi]), ti)[0]) for b in pair_agreement(full, sub, w, ti): bands.setdefault(b["gap"], []).append(b) allowed = np.where(pool)[0] for _ in range(100): r = rng.choice(allowed, n, replace=False) rand_rhos.append(wspearman(X[ti][:, r].mean(1), full[ti], w[ti])) pa = {} for g, v in bands.items(): vals = [x["agreement_pct"] for x in v if x["agreement_pct"] is not None] pa[g] = dict(n_pairs=int(sum(x["n_pairs"] for x in v)), agreement_pct=round(float(np.mean(vals)), 1) if vals else None) curve[n] = dict(test_spearman_mean=round(float(np.mean(rhos)), 4), test_spearman_sd=round(float(np.std(rhos)), 4), test_calibrated_mae_pts=round(100 * float(np.mean(maes)), 2), random_test_spearman_mean=round(float(np.mean(rand_rhos)), 4), test_pair_agreement=pa, methods_chosen=chosen) c = curve[n] print(f"n={n:>2} test rho {c['test_spearman_mean']:.3f} ± {c['test_spearman_sd']:.3f} random {c['random_test_spearman_mean']:.3f} " f"MAE(after fit) {c['test_calibrated_mae_pts']:.1f} pts " + " ".join(f"{g}: {v['agreement_pct']}%" for g, v in pa.items()), flush=True) rs = [] for _ in range(50): perm = rng.permutation(X.shape[1]); hh = X.shape[1] // 2 rs.append(wspearman(X[:, perm[:hh]].mean(1), X[:, perm[hh:]].mean(1), w)) curve["full_benchmark_split_half_spearman"] = round(float(np.mean(rs)), 4) print(f"full benchmark against itself (two random halves of 415 queries), weighted Spearman: {np.mean(rs):.3f}") json.dump(curve, open("size_curve.json", "w"), indent=1)