# decryption_complete: false # source: /Voynich/Voynich_HELDOUT_NESTED_FRAME_SPLIT_047_reproducibility.zip!/run_heldout_nested_frame_sp # stated_sha256: c2eee853c017f59f0b0f9dd894b3fe2a944fb8141556898ae723cd58b358ae27 # matches_stated_sha256: false # pdf_pages: 510-511 # note: The stated SHA-256 is the digest printed in the PDF. # The PDF page extract follows the form feed. decryption_complete stays false. run_heldout_nested_frame_split_047.py VOYNICH RESEARCH ARCHIVE | 16 SEPTEMBER 2026 1 run_heldout_nested_frame_split_047.py Source: /Voynich/Voynich_HELDOUT_NESTED_FRAME_SPLIT_047_reproducibility.zip!/run_heldout_nested_frame_sp lit_047.py SHA-256: c2eee853c017f59f0b0f9dd894b3fe2a944fb8141556898ae723cd58b358ae27 !/usr/bin/env python3 """HELDOUT-NESTED-FRAME-SPLIT-047: one-rule raw-surface segmentation test.""" from pathlib import Path import hashlib,json from collections import defaultdict import numpy as np,pandas as pd import run_raw_corpus_ledger_expansion_041 as r41 import run_citation_dictionary_027 as c27 import run_anonymous_record_decompression_032 as d32 ROOT=Path(__file__).resolve().parent;OUT=ROOT/'heldout_nested_frame_split_047';OUT.mkdir(exist_ok=True); SRC=ROOT/'crosswalk002_inputs/Voynich_Line_Local_Reproducibility_2026-08-22/data';SEED=20260830;REPS=100 00 RSETS={'R_ANY':set(c27.R),'R_EXCLUSIVE':set(c27.R)-set(c27.L),'R_AMBIGUOUS':set(c27.R)&set(c27.L)};LSETS ={'L_ANY':set(c27.L),'L_EXCLUSIVE':set(c27.L)-set(c27.R),'L_AMBIGUOUS':set(c27.L)&set(c27.R)} RULES=['BASE']+[a+'>'+b for a in RSETS for b in LSETS] def fold(f):return int(hashlib.sha256(('nested-frame-split-047|'+f).encode()).hexdigest()[:8],16)%5 def split_token(s,rule): a=str(s).split() if rule=='BASE':return [' '.join(a)] rn,ln=rule.split('>');rs,ls=RSETS[rn],LSETS[ln];cuts=[i+1 for i in range(1,len(a)-2) if a[i] in rs and a[i+1] in ls] if not cuts:return [' '.join(a)] out=[];start=0 for stop in cuts+[len(a)]:out.append(' '.join(a[start:stop]));start=stop return out def lines(e,rule): out={} for (f,l,reg),g in e.groupby(['folio','line','register']): seq=[] for s in g.sort_values('token_index').surface:seq+=split_token(s,rule) if len(seq)>=1:out[(f,int(l),reg)]=seq return out def scores(ez,eg,rule,eligible): z,g=lines(ez,rule),lines(eg,rule);rows=[] for k in eligible:rows.append({'folio':k[0],'line':k[1],'register':k[2],'jaccard':d32.multiset_jaccard( z[k],g[k]),'lcs':d32.lcs_ratio(z[k],g[k]),'score':(d32.multiset_jaccard(z[k],g[k])+d32.lcs_ratio(z[k],g[ k]))/2}) return pd.DataFrame(rows) def main(): ev={w:r41.parse_raw(SRC/(w+'.txt'),w) for w in ('ZL','GC')};bz,bg=lines(ev['ZL'],'BASE'),lines(ev['GC'] ,'BASE');eligible=sorted(k for k in set(bz)&set(bg) if len(bz[k])>=2 and len(bg[k])>=2);allscore={r:scores(ev['ZL'],ev['GC'],r,eligible) for r in RULES};folds=[] for k in range(5): means={r:allscore[r][allscore[r].folio.map(fold)!=k].score.mean() for r in RULES};chosen=max(RULES,key=lambda r:(means[r],r=='BASE'));te=allscore[chosen][allscore[chosen].folio.ma p(fold)==k];base=allscore['BASE'][allscore['BASE'].folio.map(fold)==k];m=te.merge(base,on=['folio','line ','register'],suffixes=('_rule','_base'));folds.append({'fold':k,'selected_rule':chosen,'training_score' :means[chosen],'test_lines':len(m),'test_rule_score':m.score_rule.mean(),'test_base_score':m.score_base. mean(),'gain':m.score_rule.mean()-m.score_base.mean()}) fd=pd.DataFrame(folds);fd.to_csv(OUT/'folio_heldout_rule_selection.csv',index=False) summaryrules=[] for r,d in allscore.items():summaryrules.append({'rule':r,'lines':len(d),'mean_jaccard':d.jaccard.mean( ),'mean_lcs':d.lcs.mean(),'mean_score':d.score.mean()}) pd.DataFrame(summaryrules).to_csv(OUT/'all_rule_summary.csv',index=False) # Exact folio-block sign-flip null on held-out fold gains, weighted by test lines. obs=float(np.average(fd.gain,weights=fd.test_lines));rng=np.random.default_rng(SEED);null=[] for _ in range(REPS):null.append(float(np.average(fd.gain*rng.choice([-1,1],len(fd)),weights=fd.test_li nes))) pv=float((1+sum(x>=obs for x in null))/(REPS+1));pd.DataFrame({'replicate':range(REPS),'gain':null}).to run_heldout_nested_frame_split_047.py VOYNICH RESEARCH ARCHIVE | 16 SEPTEMBER 2026 2 _csv(OUT/'heldout_signflip_null.csv',index=False) passed=bool(obs>0 and (fd.gain>0).sum()>=4 and pv<.05 and len(set(fd.selected_rule))==1 and fd.selected_rule.iloc[0]!='BASE') summary={'test':'HELDOUT-NESTED-FRAME-SPLIT-047','candidate_rules':len(RULES),'fixed_eligible_lines':le n(eligible),'selected_rules':fd.selected_rule.tolist(),'weighted_heldout_gain':obs,'positive_folds':int( (fd.gain>0).sum()),'signflip_p':pv,'pass':passed,'rule_budget_cost':0,'rulebook_action':'REFINE_EDGE_HAN DOFF' if passed else 'NONE','boundary':'Raw-surface segmentation only; no semantics or plaintext.'};(OUT/'summary.json').write_text(json.dumps(summary,indent=2)) report=['# HELDOUT-NESTED-FRAME-SPLIT-047','',('**PASS — ONE-RULE NESTED FRAME SPLIT**' if passed else '**FAIL — SIMPLE NESTED FRAME RULE REJECTED**'),'','Ten historically executable candidates were compared on the identical baseline-eligible line universe: no split plus nine right-edge/left-edge membership variants. The rule was selected on four folio folds and scored on the untouched fifth. Edge atoms were retained as closers/openers; no dictionary or exception list was allowed.','',f'- Fixed shared multi-token lines: {len(eligible)}',f"- Fold selections: {' | '.join(fd.selected_rule)}",f'- Weighted held-out gain: {obs:+.6f}',f'- Positive folds: {(fd.gain>0).sum()}/5',f'- Sign-flip p: {pv:.6f}','','## Rule audit','',('The result refines existing EDGE HANDOFF at the sub-token level; it does not add a seventh rule. Six rules remain.' if passed else 'No new rule. The six-rule ledger remains unchanged; local B2→L1 repair is not generalized.')];(OUT/'report.md').write_text('\n'.join(repo rt)+'\n');pd.DataFrame([{'test':'HELDOUT-NESTED-FRAME-SPLIT-047','rule':'EDGE HANDOFF','status':'STRENGTHENED' if passed else 'UNCHANGED','evidence':f'fixed-line gain={obs:+.6f}; folds={(fd.gain>0).sum()}/5; p={pv:.6f}','live_rule_count':6}]).to_csv(OUT/'rule_recovery_audit.csv',ind ex=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()