run_pixel_boundary_localization_050.py VOYNICH RESEARCH ARCHIVE | 16 SEPTEMBER 2026 2 return float(g[g[lab]==1].valley_score.mean()-g[g[lab]==0].valley_score.mean()) td=d.groupby('token_id').apply(dif,include_groups=False).rename('within_token_difference').reset_index( );keys=d[['token_id','folio','hand','currier','section']].drop_duplicates();td=td.merge(keys,on='token_i d');td.to_csv(OUT/'token_differences.csv',index=False) folds=[] for k in range(5): q=td[td.folio.map(p49.fold)==k];folds.append({'fold':k,'tokens':len(q),'folios':q.folio.nunique(),'mea n_difference':float(q.within_token_difference.mean()),'positive_token_share':float((q.within_token_diffe rence>0).mean())}) fd=pd.DataFrame(folds);fd.to_csv(OUT/'folio_heldout_folds.csv',index=False);obs=float(td.within_token_d ifference.mean()) groups=[(g.valley_score.to_numpy(),int(g.predicted_rl.sum())) for _,g in d.groupby('token_id')];rng=np.random.default_rng(SEED);null=[] for rep in range(REPS): vals=[] for scores,n in groups: ix=rng.choice(len(scores),n,replace=False);chosen=scores[ix];mask=np.ones(len(scores),bool);mask[ix]= False;vals.append(float(chosen.mean()-scores[mask].mean())) null.append(float(np.mean(vals))) pv=float((1+sum(x>=obs for x in null))/(REPS+1));positive=int((fd.mean_difference>0).sum());passed=bool (obs>0 and positive>=4 and pv<=.05) summary={'test':'PIXEL-BOUNDARY-LOCALIZATION-050','tokens':tokens,'boundary_events':len(d),'folios':d.f olio.nunique(),'invalid_crops_excluded':invalid,'mean_within_token_valley_difference':obs,'positive_fold s':positive,'within_token_permutation_p':pv,'null_mean':float(np.mean(null)),'pass':passed,'rule_count': 6,'boundary':'Proportional narrow-window atom-boundary localization; no ground-truth atom-to-pixel alignment, plaintext, or semantics.'} (OUT/'summary.json').write_text(json.dumps(summary,indent=2));pd.DataFrame({'replicate':range(REPS),'nu ll_mean_difference':null}).to_csv(OUT/'within_token_null.csv',index=False) report=['# PIXEL-BOUNDARY-LOCALIZATION-050','',('**PASS — LOCAL PHYSICAL SEPARATION DETECTED**' if passed else '**FAIL — LOCAL PHYSICAL SEPARATION NOT DETECTED**'),'','Every eligible atom boundary inside each positive token was projected into the physical manuscript crop. Each received the same narrow proportional search window. Predicted internal right-edge to left-edge transitions were compared with all other eligible boundaries inside the identical token. The null reassigned the same number of predicted boundaries within each token.','',f'- Tokens: {tokens:,}; boundary events: {len(d):,}; folios: {d.folio.nunique()}',f'- Mean within-token valley difference: {obs:+.6f}',f'- Positive folio folds: {positive}/5',f'- Within-token permutation p: {pv:.6f}',f'- Invalid crops excluded: {invalid:,}','','## Boundary','','The atlas supplies token boxes, not verified atom coordinates. This is a constrained localization test, not direct glyph segmentation. A failure rejects this proportional physical prediction but cannot prove that no differently aligned micro-stroke boundary exists.','','## Rule audit','',('EDGE HANDOFF gains localized pixel support; no new rule is added and six remain.' if passed else 'No rule change. EDGE HANDOFF remains transcription-supported; six rules remain.')] (OUT/'report.md').write_text('\n'.join(report)+'\n');pd.DataFrame([{'test':'PIXEL-BOUNDARY-LOCALIZATION -050','rule':'EDGE HANDOFF','status':'STRENGTHENED' if passed else 'UNCHANGED','evidence':f'difference={obs:+.6f}; folds={positive}/5; p={pv:.6f}','live_rule_count':6}]).to_csv(OUT/'rule_recovery_audit.csv',index=False) files=sorted(x for x in OUT.iterdir() if x.is_file() and x.name!='SHA256SUMS.txt');(OUT/'SHA256SUMS.txt ').write_text('\n'.join(f'{hashlib.sha256(x.read_bytes()).hexdigest()} {x.name}' for x in files)+'\n');print(json.dumps(summary,indent=2)) if __name__=='__main__':main()