""" Bootstrap CI on Delta_contam = Run-C - Run-A LVIS top-1. NOTE: Per-UID predictions for Run-A and Run-C are NOT available on disk. Per-stack training logs exist (numbers cited in paper from those logs), but the raw .log files themselves are not on VAE. The 5 checkpoints on VAE are: Run-0 T2-MLP, Run-B-v2 T2-MLP, Run-C T2-MLP, Run-NN T1, Run-NN T2-MLP. No Run-A checkpoint, no Run-C T1 checkpoint. What IS available: 1. Per-stack best LVIS values from numbers_validation.md (paper's own validated logs): Run-A: T1=36.66, T2-MLP=35.02, T3=36.40 (n=3, mean=36.03, SD=0.880) Run-C: T1=45.43, T2-MLP=45.97 (n=2, mean=45.70, SD=0.382) 2. metrics.jsonl for Run-C T2-MLP (45.97) and Run-B-v2 T2-MLP (28.98) with hundreds of test_lvis/overall_acc points giving within-run eval noise SD ~0.20pp. Two CIs are computed: (A) "STACK-LEVEL CI on Delta_contam_mean = Run-C_mean - Run-A_mean = 9.67 pp" Resample stack values with replacement at the natural unit of variation: - Sample 2 with-replacement Run-C values from {45.43, 45.97} - Sample 3 with-replacement Run-A values from {36.66, 35.02, 36.40} - Compute delta of means - 10000 iterations Note: With only 2 and 3 samples per condition, the bootstrap distribution is discrete with very few unique values. Reported as a CI on the 2-stack vs 3-stack mean delta. The headline 9.03pp number in the paper is a different statistic (single-stack delta Run-C T1 - Run-A T3) which does NOT have stack-level variance. (B) "EVAL-NOISE CI" -- a within-run training-noise bound: Use late-training (within-1pp-of-best) variation in test_lvis/overall_acc from metrics.jsonl as a sample of "what value would this run report if we re-evaluated at a slightly different step." Bootstrap the delta: Run-C T2-MLP: ~85 near-plateau values, mean ~45.44, SD ~0.20pp For Run-A T2-MLP we have NO metrics.jsonl. We approximate by assuming Run-A has the same eval-noise SD as Run-B-v2 T2-MLP (~0.28pp) -- a conservative overestimate of Run-A's noise -- and shift the trajectory to be centered at the paper's reported best 35.02. THIS IS AN APPROXIMATION; the resulting CI bounds eval-noise only, not seed/init/data-order/mask-seed variance. Both CIs are reported with explicit framing. The paper should adopt the STACK-LEVEL CI as the headline (it's the most credible from existing data); the eval-noise CI is a sensitivity check showing that within-run noise is small. """ import json import numpy as np np.random.seed(42) # ------------------------------------------------------------------------ # (A) Stack-level bootstrap on Delta_contam_mean = Run-C_mean - Run-A_mean # ------------------------------------------------------------------------ runA_per_stack = np.array([36.66, 35.02, 36.40]) # T1, T2-MLP, T3 runC_per_stack = np.array([45.43, 45.97]) # T1, T2-MLP print("=" * 80) print("(A) STACK-LEVEL BOOTSTRAP -- the headline Delta_contam_mean") print("=" * 80) print(f"Run-A per-stack: {runA_per_stack.tolist()}") print(f" mean={runA_per_stack.mean():.4f} SD={runA_per_stack.std(ddof=1):.4f} SE_mean={runA_per_stack.std(ddof=1)/np.sqrt(len(runA_per_stack)):.4f}") print(f"Run-C per-stack: {runC_per_stack.tolist()}") print(f" mean={runC_per_stack.mean():.4f} SD={runC_per_stack.std(ddof=1):.4f} SE_mean={runC_per_stack.std(ddof=1)/np.sqrt(len(runC_per_stack)):.4f}") point_estimate_A = runC_per_stack.mean() - runA_per_stack.mean() print(f"\nPoint estimate Delta_contam_mean = {point_estimate_A:.4f} pp") print(f" (paper's headline single-stack 'Delta_contam = 9.03 pp' uses T1 Run-C - T3 Run-A = 45.43 - 36.40 = 9.03)") B = 10000 deltas = np.zeros(B) for i in range(B): c_resample = np.random.choice(runC_per_stack, size=len(runC_per_stack), replace=True) a_resample = np.random.choice(runA_per_stack, size=len(runA_per_stack), replace=True) deltas[i] = c_resample.mean() - a_resample.mean() print(f"\nBootstrap (B={B}, stack-level resampling):") print(f" mean: {deltas.mean():.4f}") print(f" SE: {deltas.std(ddof=1):.4f}") print(f" 95% percentile CI: [{np.percentile(deltas, 2.5):.4f}, {np.percentile(deltas, 97.5):.4f}]") basic_lo = 2*point_estimate_A - np.percentile(deltas, 97.5) basic_hi = 2*point_estimate_A - np.percentile(deltas, 2.5) print(f" 95% basic CI: [{basic_lo:.4f}, {basic_hi:.4f}]") print(f" P(delta > 0): {(deltas > 0).mean():.4f}") print(f" P(delta > 5): {(deltas > 5).mean():.4f}") print(f" P(delta > 7): {(deltas > 7).mean():.4f}") print(f" unique values in bootstrap dist: {len(np.unique(deltas))}") # Welch's t-CI for the difference of means (parametric, classical) nA, nC = len(runA_per_stack), len(runC_per_stack) sA, sC = runA_per_stack.std(ddof=1), runC_per_stack.std(ddof=1) se_diff = np.sqrt(sA**2/nA + sC**2/nC) # Welch-Satterthwaite df df_welch = (sA**2/nA + sC**2/nC)**2 / ( (sA**2/nA)**2/(nA-1) + (sC**2/nC)**2/(nC-1) ) from scipy import stats t_crit = stats.t.ppf(0.975, df_welch) ci_lo_welch = point_estimate_A - t_crit*se_diff ci_hi_welch = point_estimate_A + t_crit*se_diff print(f"\nWelch's t 95% CI (parametric, for context): [{ci_lo_welch:.4f}, {ci_hi_welch:.4f}] (df={df_welch:.2f}, t_crit={t_crit:.3f})") stack_result = { "method": "stack-level bootstrap of Delta_contam = Run-C - Run-A means", "runA_per_stack": runA_per_stack.tolist(), "runC_per_stack": runC_per_stack.tolist(), "n_runA_stacks": int(nA), "n_runC_stacks": int(nC), "point_estimate_pp": float(point_estimate_A), "B": B, "bootstrap_mean_pp": float(deltas.mean()), "SE_pp": float(deltas.std(ddof=1)), "ci_95_percentile_pp": [float(np.percentile(deltas, 2.5)), float(np.percentile(deltas, 97.5))], "ci_95_basic_pp": [float(basic_lo), float(basic_hi)], "p_delta_gt_0": float((deltas > 0).mean()), "p_delta_gt_5pp": float((deltas > 5).mean()), "welch_t_ci_95_pp": [float(ci_lo_welch), float(ci_hi_welch)], "welch_df": float(df_welch), } # ------------------------------------------------------------------------ # (B) Eval-noise bootstrap: within-run plateau variation # ------------------------------------------------------------------------ print() print("=" * 80) print("(B) EVAL-NOISE BOOTSTRAP -- within-run training noise lower bound") print("=" * 80) def load_late_evals(path, window_pp=1.0): """Return overall_acc values within `window_pp` of best.""" vals = [] for l in open(path): try: d = json.loads(l) if "test_lvis/overall_acc" in d: vals.append(d["test_lvis/overall_acc"]) except: pass arr = np.array(vals) * 100.0 # pp best = arr.max() plateau = arr[arr >= best - window_pp] return plateau, best runC_plateau, runC_best = load_late_evals("/home/builder/bmvc_hf_release/metrics/run_c_v3_t2_mlp_metrics.jsonl") runBv2_plateau, runBv2_best = load_late_evals("/home/builder/bmvc_hf_release/metrics/run_b_v2_t2_mlp_metrics.jsonl") runNN_t2_plateau, runNN_t2_best = load_late_evals("/home/builder/bmvc_hf_release/metrics/run_nn_t2_mlp_metrics.jsonl") runNN_t1_plateau, runNN_t1_best = load_late_evals("/home/builder/bmvc_hf_release/metrics/run_nn_t1_metrics.jsonl") print(f"Run-C T2-MLP plateau: n={len(runC_plateau)}, mean={runC_plateau.mean():.4f}, SD={runC_plateau.std(ddof=1):.4f}, best={runC_best:.4f}") print(f"Run-B-v2 T2-MLP plateau: n={len(runBv2_plateau)}, mean={runBv2_plateau.mean():.4f}, SD={runBv2_plateau.std(ddof=1):.4f}, best={runBv2_best:.4f}") print(f"Run-NN T2-MLP plateau: n={len(runNN_t2_plateau)}, mean={runNN_t2_plateau.mean():.4f}, SD={runNN_t2_plateau.std(ddof=1):.4f}, best={runNN_t2_best:.4f}") print(f"Run-NN T1 plateau: n={len(runNN_t1_plateau)}, mean={runNN_t1_plateau.mean():.4f}, SD={runNN_t1_plateau.std(ddof=1):.4f}, best={runNN_t1_best:.4f}") # Pool plateau SDs as a typical "within-run eval noise SD" pooled_sd = np.sqrt(np.mean([ runC_plateau.std(ddof=1)**2, runBv2_plateau.std(ddof=1)**2, runNN_t1_plateau.std(ddof=1)**2, runNN_t2_plateau.std(ddof=1)**2, ])) print(f"\nPooled within-run plateau eval noise SD: {pooled_sd:.4f} pp") # Construct a synthetic Run-A T2-MLP plateau by shifting Run-B-v2's trajectory # (most similar in shape: aggressive prune, recovers to local best) to be # centered at the paper-reported Run-A T2-MLP best of 35.02. runA_t2mlp_approx_best = 35.02 runA_t2mlp_synthetic = runBv2_plateau - runBv2_best + runA_t2mlp_approx_best print(f"Run-A T2-MLP SYNTHETIC plateau (from Run-B-v2 trajectory, shifted): n={len(runA_t2mlp_synthetic)}, mean={runA_t2mlp_synthetic.mean():.4f}, SD={runA_t2mlp_synthetic.std(ddof=1):.4f}, best={runA_t2mlp_synthetic.max():.4f}") print(" (this is an APPROXIMATION; Run-A's true eval-noise SD is unknown)") # Eval-noise bootstrap on Delta_contam_T2MLP = Run-C T2-MLP - Run-A T2-MLP # Resample eval points within each run (preserving "best" framing requires resampling the best # from each bootstrap sample, since the paper reports "best LVIS top-1") print("\nApproach: resample plateau values within run, take MAX of each sample (mirrors 'best' reporting)") B_eval = 10000 deltas_eval = np.zeros(B_eval) for i in range(B_eval): c_resample = np.random.choice(runC_plateau, size=len(runC_plateau), replace=True) a_resample = np.random.choice(runA_t2mlp_synthetic, size=len(runA_t2mlp_synthetic), replace=True) deltas_eval[i] = c_resample.max() - a_resample.max() print(f"\nEval-noise bootstrap (B={B_eval}, within-run resampling, T2-MLP only):") print(f" mean: {deltas_eval.mean():.4f}") print(f" SE: {deltas_eval.std(ddof=1):.4f}") print(f" 95% percentile CI: [{np.percentile(deltas_eval, 2.5):.4f}, {np.percentile(deltas_eval, 97.5):.4f}]") # Approach 2: resample plateau values, take MEAN (treats reported acc as # the run's "true" plateau accuracy) deltas_eval_mean = np.zeros(B_eval) for i in range(B_eval): c_resample = np.random.choice(runC_plateau, size=len(runC_plateau), replace=True) a_resample = np.random.choice(runA_t2mlp_synthetic, size=len(runA_t2mlp_synthetic), replace=True) deltas_eval_mean[i] = c_resample.mean() - a_resample.mean() print(f"\nEval-noise bootstrap (B={B_eval}, plateau mean as statistic):") print(f" mean: {deltas_eval_mean.mean():.4f}") print(f" SE: {deltas_eval_mean.std(ddof=1):.4f}") print(f" 95% percentile CI: [{np.percentile(deltas_eval_mean, 2.5):.4f}, {np.percentile(deltas_eval_mean, 97.5):.4f}]") eval_noise_result = { "method": "eval-noise bootstrap (within-run plateau, T2-MLP only, Run-A approximated)", "caveat": "Run-A metrics.jsonl not available; Run-A trajectory synthesized from Run-B-v2 trajectory (most similar prune-rate run) shifted to paper-reported best=35.02. Bounds eval-noise only; does NOT capture seed/init/mask-seed/data-order variance.", "runC_plateau_n": int(len(runC_plateau)), "runC_plateau_mean": float(runC_plateau.mean()), "runC_plateau_sd": float(runC_plateau.std(ddof=1)), "runC_best": float(runC_best), "runA_synthetic_plateau_n": int(len(runA_t2mlp_synthetic)), "runA_synthetic_plateau_mean": float(runA_t2mlp_synthetic.mean()), "runA_synthetic_plateau_sd": float(runA_t2mlp_synthetic.std(ddof=1)), "runA_assumed_best": runA_t2mlp_approx_best, "B": B_eval, "best_minus_best": { "mean_pp": float(deltas_eval.mean()), "SE_pp": float(deltas_eval.std(ddof=1)), "ci_95_percentile_pp": [float(np.percentile(deltas_eval, 2.5)), float(np.percentile(deltas_eval, 97.5))], }, "mean_minus_mean": { "mean_pp": float(deltas_eval_mean.mean()), "SE_pp": float(deltas_eval_mean.std(ddof=1)), "ci_95_percentile_pp": [float(np.percentile(deltas_eval_mean, 2.5)), float(np.percentile(deltas_eval_mean, 97.5))], }, } # ------------------------------------------------------------------------ # Save full result # ------------------------------------------------------------------------ result = { "context": "BMVC paper Phase-2 review L24: bootstrap CI on Delta_contam = 9.03 pp (Run-C - Run-A on LVIS top-1).", "data_constraint": "Per-UID predictions are NOT available for Run-A or Run-C (only Run-0 baseline has them). Per-stack training logs underlie all numbers; only one of the five checkpoints on disk corresponds to a published 'Run-A' or 'Run-C' best LVIS number, namely Run-C T2-MLP (45.97). Run-A checkpoints were not preserved.", "headline_numbers_from_paper": { "delta_contam_single_stack_pp": 9.03, "delta_contam_two_three_stack_mean_pp": 9.67, "runC_two_stack_mean": 45.70, "runA_three_stack_mean": 36.03, }, "stack_level_bootstrap": stack_result, "eval_noise_bootstrap": eval_noise_result, "recommended_paper_report": { "headline": "Delta_contam = 9.67 pp [stack-level 95% CI given below]", "stack_bootstrap_ci_95_percentile_pp": stack_result["ci_95_percentile_pp"], "welch_t_ci_95_pp": stack_result["welch_t_ci_95_pp"], "framing": "Use the stack-level CI as the headline. The eval-noise CI is reported as a sensitivity check.", "caveat_to_acknowledge": "Bootstrap is over the n=3 Run-A and n=2 Run-C training stacks, treating each stack as one independent realization of the 'final LVIS top-1' statistic. Sample sizes are small; the percentile bootstrap with replacement provides a conservative interval given the limited stack count.", }, } with open("/home/builder/bmvc_hf_release/bootstrap_delta_contam_result.json", "w") as f: json.dump(result, f, indent=2) print() print("=" * 80) print("RESULTS WRITTEN TO /home/builder/bmvc_hf_release/bootstrap_delta_contam_result.json") print("=" * 80) print(f"HEADLINE (stack-level bootstrap, n=3 vs n=2):") print(f" Point estimate: Delta_contam_mean = {point_estimate_A:.2f} pp (vs paper's single-stack 9.03)") print(f" 95% percentile CI: [{stack_result['ci_95_percentile_pp'][0]:.2f}, {stack_result['ci_95_percentile_pp'][1]:.2f}]") print(f" Welch's t 95% CI: [{stack_result['welch_t_ci_95_pp'][0]:.2f}, {stack_result['welch_t_ci_95_pp'][1]:.2f}]") print(f" SE: {stack_result['SE_pp']:.2f} pp") print(f" P(delta > 0): {stack_result['p_delta_gt_0']*100:.2f}%")