File size: 3,082 Bytes
8246b15 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | import json,re,glob,statistics as st
import os
R=os.path.expanduser('~/repo/homunculus/')
rows={}
for f in ['prune_results','clust2_results','clust3_results','clust4_results']:
for i,l in enumerate(open(R+'results/'+f+'.jsonl'),1):
r=json.loads(l); rows[r['job']]=(f,i,r)
def rnd(x,n=2): return round(x+1e-12,n)
def parse(path):
out=[]
for l in open(path):
if l.startswith('|') and not set(l.strip())<=set('|- '):
out.append([c.strip() for c in l.strip().strip('|').split('|')])
return out
bad=0;tot=0
# p3 table
for c in parse(R+'papers/p3_energy_canvas.md'):
j=c[0]
if j in rows and len(c)==7:
r=rows[j][2];tot+=1
exp=[ '%.3f'%r['frac'] ,'%.2f'%r['ce_shakes'],'%.2f'%r['kl_prompts'],'%.2f'%r['top1_agree'],str(r['gen_identical']),'%.2f'%r['gen_prefix_frac']]
got=c[1:]
if [round(float(a),2) if k!=0 else round(float(a),3) for k,a in enumerate(got)]!=[round(float(a),2) if k!=0 else round(float(a),3) for k,a in enumerate(exp)]:
bad+=1;print('P3 MISMATCH',j,got,exp)
print('p3 rows checked',tot,'bad',bad)
# p2 table 3.1 and 3.2
m={'act+rf':'c2:act+rf','act':'c2:act','gu+rf':'c2:gu+rf','gu':'c2:gu','gud':'c2:gud','imp+rf':'c2:imp+rf','imp':'c2:imp','interp':'c2:interp','interps':'c2:interps','rand':'c2:rand','svd':'c2:svd'}
tot=bad=0
for c in parse(R+'papers/p2_visual_geometric.md'):
if len(c)==8 and ':' in c[0] and c[0].split(':')[0] in m:
meth,cut=c[0].split(':'); j=m[meth]+':'+cut
if j not in rows: print('NOROW',c[0]);continue
f,i,r=rows[j];tot+=1
got=[float(x) for x in c[2:5]]+[float(c[1])]
exp=[r['ce_shakes'],r['kl_prompts'],r['top1_agree'],r['frac']]
ok=all(abs(a-round(b,2 if k<3 else 3))<0.0051 for k,(a,b) in enumerate(zip(got,exp)))
# round trip
rt=r['rt']; gu=st.mean(x['rel_gu'] for x in rt); dn=st.mean(x['rel_down'] for x in rt)
okrt=abs(float(c[6])-gu)<0.0006 and abs(float(c[7])-dn)<0.0006
if not(ok and okrt): bad+=1;print('P2 MISMATCH',c,'exp',[round(x,3) for x in exp],round(gu,3),round(dn,3))
if len(c)==4 and c[0].split(':')[0] in('nn','pca'):
o,b,cut=c[0].split(':'); j='c4:%s:%s:%s'%(o,b,cut); f,i,r=rows[j]; tot+=1
got=[float(x) for x in c[1:]]
if not all(abs(a-b)<0.0051 for a,b in zip(got,[r['ce_shakes'],r['kl_prompts'],r['top1_agree']])): bad+=1;print('P2b MISMATCH',c)
print('p2 rows',tot,'bad',bad)
# p2 table 3.4 per-layer gud 0.25
r=rows['c2:gud:0.25'][2]['rt']
for c in parse(R+'papers/p2_visual_geometric.md'):
if len(c)==3 and c[0].isdigit():
L=int(c[0]);x=r[L]
if abs(float(c[1])-x['rel_gu'])>0.0006 or abs(float(c[2])-x['max_gu'])>0.0006: print('LAYER MISMATCH',c,x['rel_gu'],x['max_gu'])
print('per-layer done; min',min(x['rel_gu'] for x in r),'max',max(x['rel_gu'] for x in r))
# mean rel gu by method @ .25,.5,.75
for cut in ['0.25','0.5','0.75']:
print(cut,{k:round(st.mean(x['rel_gu'] for x in v[2]['rt']),3) for k,v in rows.items() if k.endswith(':'+cut) and k.startswith('c2') and v[2]['rt']})
|