LittlePlyResearch notebook

exact_metrics.py

python · 21 lines · Exact bytes

Line 1 ↗
Version & provenance · curriculum-cm7

Recorded SHA-256 49f80c4259609e1bc1a44273345976d34c27a0d1e056baefc5537544ea25ab60Rendered SHA-256 49f80c4259609e1bc1a44273345976d34c27a0d1e056baefc5537544ea25ab60

Apache-2.0 original project code; dependencies retain their own licenses. License notes. Line links are stable within this snapshot. CM-7 completed implementation source; original and public rendered hashes recorded. Host-specific paths use /work placeholders; inspect reproduction instructions before running. Separate Rust helper retains its GPL license.

1"""Position-weighted accuracy with source-game cluster bootstrap uncertainty."""
2import numpy as np
3def summarize(rows,baseline=None,repeats=1000):
4    if not rows:return None
5    old=None if baseline is None else {r['key']:r for r in baseline}
6    if old is not None and set(old)!={r['key'] for r in rows}:raise ValueError('paired membership changed')
7    groups={}
8    for row in rows:
9        value=row['correct']
10        if old is not None:
11            if old[row['key']]['game']!=row['game']:raise ValueError('paired cluster changed')
12            value-=old[row['key']]['correct']
13        a=groups.setdefault(row['game'],[0,0]);a[0]+=value;a[1]+=1
14    values=np.asarray(list(groups.values()),dtype=np.float64);rng=np.random.default_rng(20261029);draws=[]
15    for _ in range(repeats):
16        totals=values[rng.integers(0,len(values),len(values))].sum(0);draws.append(totals[0]/totals[1])
17    return {'positions':len(rows),'source_game_clusters':len(groups),'estimate':float(values[:,0].sum()/values[:,1].sum()),
18        'percentile95':np.quantile(draws,[.025,.975]).tolist(),'bootstrap_replicates':repeats,'seed':20261029,
19        'metric':'paired accuracy delta' if baseline is not None else 'raw autoregressive preserving-move accuracy',
20        'limitation':'continuation-heldout actual-zero-counter subset; not guaranteed unseen by inherited CM-6'}
21