run_expansion_retrieval_029.py VOYNICH RESEARCH ARCHIVE | 16 SEPTEMBER 2026 3 'mrr':{m:float(d[m+'_mrr'].mean()) for m in ('RANDOM','POSITION_ONLY','KEY_ONLY','KEY_PLUS_ POSITION')}, 'recall_at_1':{m:float(d[m+'_r1'].mean()) for m in ('RANDOM','POSITION_ONLY','KEY_ONLY','KEY_PLUS_POSITION')}, 'model_over_random_mrr':observed, 'model_random_target_p':{m:float((1+sum(x>=observed[m] for x in model_null[m]))/(REPS+1)) for m in observed}, 'combined_over_best_component_mrr':obs,'positive_combined_folds':int(sum(r['KEY_PLUS_POSITI ON_mrr']>max(r['KEY_ONLY_mrr'],r['POSITION_ONLY_mrr']) for r in folds)), 'random_target_p':float((1+sum(x>=obs for x in null))/(REPS+1)),'null_mean':float(np.mean(n ull))} ps=summary['model_random_target_p'];order=sorted(ps,key=ps.get);adj={};run=0. for i,m in enumerate(order): run=max(run,min(1.,ps[m]*(len(order)-i)));adj[m]=run summary['model_holm_p']=adj return d,pd.DataFrame(folds),summary,pd.DataFrame({'witness':w,'replicate':range(REPS),'gain':null}) def main(): allq=[];allf=[];alls=[];alln=[] for w in ('ZL','GC'): z,q=build(w);d,f,s,n=evaluate(w,z,q);allq.append(d);allf.append(f);alls.append(s);alln.append(n) pd.concat(allq).to_csv(OUT/'query_results.csv',index=False) pd.concat(allf).to_csv(OUT/'heldout_folds.csv',index=False) pd.concat(alln).to_csv(OUT/'random_target_null.csv',index=False) passed=all(s['combined_over_best_component_mrr']>0 and s['positive_combined_folds']>=4 and s['random_target_p']<.05 for s in alls) summary={'test':'EXPANSION-RETRIEVAL-029','design':'Retrieve residual prose line containing label key; query key removed from candidate content. Five folio-held-out folds; 1,000 within-folio random-target nulls.','results':alls,'replicated_pass':passed,'boundary':'Anonymous record retrieval only; no plaintext, referent, or direct manuscript descent.'} (OUT/'summary.json').write_text(json.dumps(summary,indent=2)) report=['# EXPANSION-RETRIEVAL-029','',('**PASS**' if passed else '**FAIL / NOT PROMOTED**'),'',summary['design'],''] for s in alls: report += [f"## {s['witness']}",'',f"- Queries / folios / keys: {s['queries']} / {s['folios']} / {s['keys']}",f"- MRR — random {s['mrr']['RANDOM']:.4f}; position {s['mrr']['POSITION_ONLY']:.4f}; key {s['mrr']['KEY_ONLY']:.4f}; combined {s['mrr']['KEY_PLUS_POSITION']:.4f}",f"- Recall@1 — random {s['recall_at_1']['RANDOM']:.4f}; position {s['recall_at_1']['POSITION_ONLY']:.4f}; key {s['recall_at_1']['KEY_ONLY']:.4f}; combined {s['recall_at_1']['KEY_PLUS_POSITION']:.4f}",f"- Position over random: {s['model_over_random_mrr']['POSITION_ONLY']:+.4f}; p {s['model_random_target_p']['POSITION_ONLY']:.6f}; Holm p {s['model_holm_p']['POSITION_ONLY']:.6f}",f"- Key over random: {s['model_over_random_mrr']['KEY_ONLY']:+.4f}; p {s['model_random_target_p']['KEY_ONLY']:.6f}; Holm p {s['model_holm_p']['KEY_ONLY']:.6f}",f"- Combined over best component MRR: {s['combined_over_best_component_mrr']:+.4f}",f"- Positive combined folds: {s['positive_combined_folds']}/5",f"- Random-target p: {s['random_target_p']:.6f}",''] report += ['## Interpretation','',('The compact key and page position jointly retrieve held-out residual prose blocks in both witnesses.' if passed else 'The predeclared replicated gate is not met. The historical catchword analogy has not yet become a Voynich expansion decoder. Any component-level signal is exploratory unless it independently replicates against its random-target null.'),'','## Rule audit','','The live six-rule ledger is unchanged. A pass would strengthen CORE PRESERVATION, EDGE HANDOFF, and REGISTER SHIFT; a failure adds no rule.'] (OUT/'report.md').write_text('\n'.join(report)) files=sorted(p for p in OUT.iterdir() if p.is_file() and p.name!='SHA256SUMS.txt') (OUT/'SHA256SUMS.txt').write_text('\n'.join(f'{hashlib.sha256(p.read_bytes()).hexdigest()} {p.name}' for p in files)+'\n') print(json.dumps(summary,indent=2)) if __name__=='__main__':main()