"""Reconstruct registered contrasts from completed run manifests and paired world scores.""" import json import numpy as np from .paths import RESULTS, LOGS def read(path): return json.loads(path.read_text(encoding="utf-8")) def interval(values): """Student interval across independently generated worlds, in the original metric units.""" a=np.asarray(values,dtype=float) if not len(a): return {"n":0,"mean":None,"lo":None,"hi":None} m=float(a.mean()) radius=None if len(a)>1: from scipy.stats import t radius=float(t.ppf(.975,len(a)-1)*a.std(ddof=1)/np.sqrt(len(a))) return {"n":len(a),"mean":m,"lo":m-radius if radius is not None else None, "hi":m+radius if radius is not None else None} def contrasts(runs): """Only a complete set of eight registered observations can trigger a primary decision.""" indexed={(r["config"]["task"],r["config"]["model"],r["config"]["rule"],r["config"]["seed"]):r for r in runs if r["config"]["families"]==1024 and r["config"]["tag"]==""} def score(seed,model,rule="cd32",task="scene",split="test"): return indexed[task,model,rule,seed]["splits"][split]["accuracy"] def depth(seed): # Ties consistently favor the one-hop control in the prescribed ordering. better=max(("onehop","shallow"),key=lambda m:indexed["scene",m,"cd32",seed]["val_accuracy"]) return score(seed,"cd32")-score(seed,better) specs=[ ("Matched canonical accuracy",.60,lambda s:score(s,"cd32")), ("Matched randomized accuracy",.60,lambda s:score(s,"random","random")), ("Canonical minus randomized on canonical sensors",.01,lambda s:score(s,"cd32")-score(s,"random")), ("Randomized minus canonical on randomized sensors",.01,lambda s:score(s,"random","random")-score(s,"cd32","random")), ("Canonical minus frozen",0.,lambda s:score(s,"cd32")-score(s,"frozen")), ("Canonical minus validation-selected shallow control",0.,depth), ("Canonical minus randomized on ciFAIR-10",.01,lambda s:score(s,"cd32",task="pixel",split="cifair")-score(s,"random",task="pixel",split="cifair")), ] rows=[] for title,threshold,formula in specs: values={} for seed in range(8): try: values[str(seed)]=formula(seed) except KeyError: continue stats=interval(list(values.values())) decision="pending" if len(values)==8: decision=("above threshold" if stats["lo"]>threshold else "below threshold" if stats["hi"]