A candidate model scores a little higher than the baseline on a benchmark. Both were trained with several seeds and scored on the same questions. Write the function that reports the gap, a paired bootstrap interval for it, a verdict, and how many questions a benchmark would need to settle a gap of a given size.
Implement compare_checkpoints(base, cand, target_gap, n_boot=2000, seed=0):
base: a list of lists, one per training seed, each holding values in (1 means the question was answered correctly). cand: the same for the candidate with seeds, over the same questions in the same order. The two models' seeds are unrelated, so seeds are not paired; questions are.target_gap: a positive accuracy gap as a fraction (0.01 is one point).Definitions:
mean_base, mean_cand: the mean of all entries of each model.seed_std_base, seed_std_cand: a seed's accuracy is the mean of its row; report the sample standard deviation (ddof=1) of the per-seed accuracies, or None when the model has one seed.diff is mean_cand - mean_base (which equals the mean of ).ci: create one generator with np.random.default_rng(seed) and make exactly one draw from it, integers(0, Q, size=(n_boot, Q)), an index matrix idx. Replicate is the mean of at the indices in row of idx. The interval is [lo, hi], the 0.025 and 0.975 quantiles of the n_boot replicates computed with np.quantile and its default (linear) method.verdict: from the rounded interval, "better" if lo > 0, "worse" if hi < 0, otherwise "cannot tell".questions_needed: let be the sample standard deviation (ddof=1) of . The smallest benchmark size with target_gap, that is , or 1 when . The 2.8 is : a two-sided 95% test with 80% power.Return a dict with keys in this order: mean_base, mean_cand, seed_std_base, seed_std_cand, diff, ci, verdict, questions_needed. Every float is rounded to 4 decimals (ci is a list of two rounded floats).