"""Independent finite construction checks. Standard library only; no model training. Run: python this_file.py. Stdout contains the two figure datasets. """ import json, math from itertools import product, combinations from fractions import Fraction as F figures=[] ps=[.6,.8,.95];entropy=[-p*math.log(p)-(1-p)*math.log(1-p)for p in ps];ce=[-math.log(1-p)for p in ps] assert all(entropy[i]>entropy[i+1]and ce[i].5 for p in ps) figures.append(dict(id="confidence-versus-correctness",x=ps,series=[dict(name="Prediction entropy",y=entropy),dict(name="True class-0 cross-entropy",y=ce)])) def running(xs): out=[0.] for x in xs:out.append((out[-1]+x)/2) return out a=[0,0,2,2,0,0];b=[2,2,0,0,0,0];ra=running(a);rb=running(b) assert sorted(a)==sorted(b)and ra[-1]==.375 and rb[-1]==.09375 assert running([0,2])[-1]==1 and running([2,0])[-1]==.5 figures.append(dict(id="stream-order-state",x=list(range(7)),series=[dict(name="0,0,2,2,0,0",y=ra),dict(name="2,2,0,0,0,0",y=rb)])) # Fixed threshold probes and actual full/partial state restoration. def probe(state):return int(state['mean']>.75) source={'weight':1.,'optimizer':0.,'mean':0.} state={'weight':2.,'optimizer':7.,'mean':running([0,2])[-1]} reversed_state=dict(state,mean=running([2,0])[-1]) assert probe(state)!=probe(reversed_state) fully_reset=dict(source) partly_reset=dict(state,weight=source['weight'],optimizer=source['optimizer']) assert fully_reset==source and probe(fully_reset)==probe(source) assert partly_reset['mean']!=source['mean']and probe(partly_reset)!=probe(source) # Deliberately false inference: decreasing entropy proves improved 0-1 accuracy. errors=[int(p>.5)for p in ps] try: assert entropy[-1]