"""Exact scalar-loss and finite-memory examples; standard library only. Run this file to print the figure data. No model training or benchmark. """ import json,math from fractions import Fraction as F ls=[0,.25,1,4,16];ws=[(v-1)/(v+1)for v in ls] a=[.5*(w-1)**2 for w in ws];b=[.5*(w+1)**2 for w in ws] for lam,w in zip(ls,ws): assert math.isclose((w+1)+lam*(w-1),0,abs_tol=1e-12) r=lam/(1+lam);assert math.isclose(w,2*r-1,abs_tol=1e-12) ms=[1,5,10,20,40];miss=[float(F(math.comb(95,m),math.comb(100,m)))for m in ms];iid=[.95**m for m in ms] assert F(math.comb(95,0),math.comb(100,0))==1 assert math.comb(95,100)==0 and math.comb(100,100)==1 assert all(miss[i]>miss[i+1]for i in range(len(ms)-1)) figures=[dict(id='quadratic-retention-tradeoff',x=ls,series=[dict(name='Old task A',y=a),dict(name='New task B',y=b)]),dict(id='rare-memory-coverage',x=ms,series=[dict(name='Without replacement: 5 rare among 100',y=miss),dict(name='Independent draws: rare probability 0.05',y=iid)])] print(json.dumps(dict(status='PASS',scope='Exact author-constructed quadratic and finite-population examples; not neural training or measured accuracy.',figures=figures),indent=2))