| """Evidence-weight model (draft14 maths) evaluated on the v0.3 sweep fixtures.""" |
| import json,math,glob,os,collections,datetime as dt |
| T=1.0e25; MARGIN=0.10; ETA=0.40; WSC=5.11; L0=-2.0 |
| wF,wC,wN=2.5,2.2,0.85; BW,BM,BH=1.0,2.0,3.0 |
| SEV={'info':.05,'low':.15,'medium':.35,'high':.60,'critical':.85} |
| psi=lambda z:2*z-1 |
| g=lambda z,t:min(1.0,max(0.0,z/t)) if t>0 else 0.0 |
| sig=lambda x:2**x/(1+2**x) |
| def num(v,d=0.0): |
| try: |
| f=float(v); return d if f!=f else f |
| except (TypeError,ValueError): return d |
| def secs(w): |
| try: |
| a=dt.datetime.strptime(w['start'],'%Y-%m-%dT%H:%M:%SZ');b=dt.datetime.strptime(w['end'],'%Y-%m-%dT%H:%M:%SZ') |
| return (b-a).total_seconds() |
| except Exception: return 0.0 |
| def evaluate(site): |
| s=site.get('normalized_signals',{}) or {}; cv=site.get('coverage',{}) or {} |
| raw=site.get('raw_features',{}) or {} |
| C=lambda k: max(0.0,min(1.0,num(cv.get(k),0.0))) |
| dur=secs(site.get('audit_window',{}) or {}) |
| cnt=sum(num(r.get('count')) for r in raw.get('accelerator_count_by_family_sku',[]) or []) |
| rate=max([num(r.get('peak_rate')) for r in raw.get('advertised_peak_rate_by_precision',[]) or []] or [0.0]) |
| adj=num(s.get('capacity_adjustment_factor'),1.0) |
| B=cnt*rate*dur*adj |
| hidden=bool(s.get('hidden_or_unmonitored_capacity_possible',False)) |
| units=bool(s.get('capacity_unit_normalized',True)) |
| sigma_scope=0.0 if hidden else 1.0 |
| cstar=C('capacity')*sigma_scope*C('clock_alignment') |
| admissible = units and rate>0 and cnt>0 and dur>0 and adj>=0 and sigma_scope>0 |
| mu = B/(cstar*T) if cstar>0 else float('inf') |
| ruled = admissible and mu < 1/(1+MARGIN) |
| |
| O=num(s.get('achieved_operations'),0.0) |
| o_norm=bool(s.get('achieved_operations_unit_normalized',True)) |
| A=max(0.0,min(1.0,num(s.get('activity_score')))) |
| if ruled: pi_sc=0.0 |
| elif O>=T and o_norm and C('achieved_ops')>=0.75: pi_sc=1.0 |
| else: |
| Ch=max(ETA*A*B, O) |
| r=-3.0 if Ch<=0 else max(-3.0,min(3.0,math.log10(Ch/T))) |
| pi_sc=sig(WSC*r) |
| |
| wit=[] |
| if O>0 and o_norm and B>0: wit.append(B*(1+MARGIN)/O) |
| pc=num(s.get('participant_count')) |
| if pc>0 and cnt>0: wit.append(cnt*(1+MARGIN)/pc) |
| for rec in raw.get('allocated_accelerator_count_by_sku',[]) or []: |
| v=num(rec.get('count')) |
| if v>0 and cnt>0: wit.append(cnt*(1+MARGIN)/v) |
| chi=min(wit) if wit else None |
| chi_fail=(chi is not None and chi<1.0) |
| |
| serv=num(s.get('serving_counterevidence_score')); servov=num(s.get('serving_activity_overlap_fraction')) |
| e_serv=g(serv,.70)*g(servov,.50)*C('serving') |
| stov=num(s.get('storage_operation_overlap_fraction')); stby=num(s.get('bytes_explained_fraction')) |
| e_st=g(stov,.80)*g(stby,.70)*C('storage_operations') |
| breg=num(s.get('benchmark_regularity_score')); bdur=num(s.get('benchmark_duration_seconds'),dur) |
| e_bm=g(breg,.90)*(1.0 if 0<bdur<=7200 else 0.0)*C('benchmark_hpc') |
| hpc=num(s.get('hpc_mpi_score')); hov=num(s.get('hpc_overlap_fraction')) |
| e_hpc=g(hpc,.60)*g(A,.50)*g(hov,.50)*C('benchmark_hpc') |
| bF=min(1.0,max(e_serv,e_bm,e_hpc)); bC=min(1.0,e_st) |
| |
| F=num(s.get('collective_cadence_score')); rAF=num(s.get('activity_fabric_overlap_fraction')) |
| adur=num(s.get('activity_duration_seconds'),dur) |
| Ck=num(s.get('checkpoint_periodicity_score')); rAC=num(s.get('checkpoint_activity_adjacency_fraction')) |
| nb=num(s.get('checkpoint_burst_count')); N=num(s.get('non_serving_score')) |
| aF=C('fabric')*g(A,.55)*g(rAF,.50)*g(adur,1800) |
| aC=C('storage')*g(A,.50)*g(rAC,.50)*g(nb,2) |
| aN=C('serving')*g(C('serving'),.80)*g(A,.55) |
| LF=aF*(1-bF)*wF*psi(F); LC=aC*(1-bC)*wC*psi(Ck); LN=aN*wN*psi(N) |
| Lam=LF+LC+LN; Lcov=C('fabric')*wF+C('storage')*wC+C('serving')*wN |
| |
| D=1.0 |
| ratio=(O/B) if B>0 else 0.0 |
| disc=[] |
| if o_norm and ratio>1.10 and C('capacity')>=0.75 and num(s.get('unit_mismatch_or_hidden_capacity_explanation_score'))<0.70: |
| disc.append((min(1.0,(ratio-1.10)/1.10),C('capacity'),'critical')) |
| if A>=0.70 and adur>=600 and num(s.get('attribution_overlap_fraction'),1.0)<=0.05 and C('attribution')>=0.80 \ |
| and num(s.get('benign_attribution_explanation_overlap_fraction'))<0.80: |
| disc.append((1.0,C('attribution'),'high')) |
| for k in ('physical_timeline_conflict','health_throttle_conflict','topology_route_conflict','power_activity_conflict'): |
| if bool(s.get(k)): disc.append((1.0,1.0,'high')) |
| for t_r,c_r,sev in disc: D*= (1-t_r*c_r*SEV[sev]) |
| D=1-D |
| pi_ref=(0.0 if ruled else sig(WSC*max(-3,min(3,math.log10(max(ETA*B,1e-30)/T)))))*sig(L0) |
| pi=(1-D)*pi_sc*sig(L0+Lam)+D*pi_ref |
| |
| if not admissible or Lcov<1.0 and not ruled and B>0 and Lcov<1.0 and mu>=1/(1+MARGIN) and Lcov<1.0: |
| pass |
| if bool(s.get('decision_blocking_missingness')) or not admissible: route='inconclusive_due_to_missingness' |
| elif chi_fail or D>=0.5: route='integrity_review_required' |
| elif ruled: route='capacity_ruled_out_for_scope' |
| elif Lcov<1.0: route='inconclusive_due_to_missingness' |
| elif Lam>=BH: route='high_training_like_warning' |
| elif Lam>=BM: route='medium_training_like_warning' |
| elif Lam>=BW: route='weak_training_like_candidate' |
| elif max(bF,bC)>0.5: route='candidate_explained_or_demoted' |
| elif pi_sc>=0.5: route='weak_training_like_candidate' |
| else: route='no_training_like_candidate_detected_in_covered_live_segment' |
| return dict(route=route,chi=chi,Lam=Lam,Lcov=Lcov,mu=mu,pi=pi,pi_sc=pi_sc,D=D) |
| WARN={'high_training_like_warning','medium_training_like_warning'} |
| CAUGHT=WARN|{'integrity_review_required'} |
| if __name__=='__main__': |
| base='xx_claude/results/sweep_v0_3_20260613_01' |
| out={} |
| for d in sorted(os.listdir(base)): |
| p=os.path.join(base,d,'sites_all.jsonl') |
| if not os.path.exists(p): continue |
| rc=collections.Counter(); lam=[]; n=0 |
| for line in open(p): |
| rec=json.loads(line); site=rec.get('site',rec) |
| r=evaluate(site); rc[r['route']]+=1; lam.append(r['Lam']); n+=1 |
| out[d]=dict(n=n,routes=dict(rc), |
| warn=sum(rc[x] for x in WARN)/n, caught=sum(rc[x] for x in CAUGHT)/n, |
| mean_lambda=sum(lam)/n) |
| print(f"{d:45s} n={n:5d} warn={out[d]['warn']*100:6.2f}% caught={out[d]['caught']*100:6.2f}% meanL={out[d]['mean_lambda']:+.3f}") |
| json.dump(out,open('/private/tmp/claude-501/-Users-idacy-Develop-datacenter-verification/23d7cbd6-c237-44fb-bca4-24d8ac2a4692/scratchpad/newmodel_results.json','w'),indent=1) |
| print("\ntotal:",sum(v['n'] for v in out.values())) |
|
|