Voynich Master Archive - Volume 07 - Pages 6001-7000
Test CSV, JSON, and Markdown records. Sections carry a Source path and a SHA-256 line.
PDF page 724 of 1000. Catalog page range 6001-7000.
Extracted text
run_bandwidth_maxstat_040.py
VOYNICH RESEARCH ARCHIVE | 16 SEPTEMBER 2026 1
run_bandwidth_maxstat_040.py
Source: /Voynich/Voynich_PORTABLE_ANONYMOUS_ROLE_BREAKTHROUGH_037_042_reproducibility.zip!/run_bandwidth
_maxstat_040.py
SHA-256: c8570bf07d166b6fde346e27117d2f7249f6ff276443272c2e62f984e1e473f0
!/usr/bin/env python3
"""BANDWIDTH-MAXSTAT-040: selection-corrected vertical band widths 1-5."""
from pathlib import Path
from scipy.special import comb
import hashlib,json
import numpy as np,pandas as pd
import run_geometric_expansion_link_030 as g30
import run_fifth_record_prospective_033 as p33
import run_anonymous_record_decompression_032 as d32
ROOT=Path(__file__).resolve().parent;OUT=ROOT/'bandwidth_maxstat_040';OUT.mkdir(exist_ok=True);KS=range(
1,6);REPS=20000;SEED=20260830
def exp(n,p,k):k=min(k,n);return 1-comb(n-p,k,exact=False)/comb(n,k,exact=False) if n-p>=k else 1.
def distances(q):return [abs((c['box'][1]+c['box'][3])/2/837-q['qy']/837) for c in q['cand']]
def gain(queries,k,shift=None):
vals=[]
for qi,q in enumerate(queries):
n=len(q['cand']);pos=q['pos'] if shift is None else {(x+shift[qi])%n for x in
q['pos']};top=set(sorted(range(n),key=lambda i:distances(q)[i])[:min(k,n)]);vals.append(int(bool(top&pos
))-exp(n,len(pos),k))
return float(np.mean(vals))
def main():
lb=g30.aligned_label_boxes();base=g30.aligned_prose_lines();add,_=p33.recover_unrestricted(base);coords
={**base,**add};qd={w:{(q['folio'],q['key']):q for q in g30.build(w,lb,coords)} for w in
('ZL','GC')};common=sorted(set(qd['ZL'])&set(qd['GC']));queries={w:[qd[w][x] for x in common] for w in
qd};obs={w:{k:gain(queries[w],k) for k in KS} for w in queries};selected=max(KS,key=lambda
k:np.mean([obs[w][k] for w in obs]));rng=np.random.default_rng(SEED);null={w:[] for w in queries}
for _ in range(REPS):
for w in queries:
shifts=[int(rng.integers(len(q['cand']))) for q in queries[w]];null[w].append(max(gain(queries[w],k,s
hifts) for k in KS))
p={w:(1+sum(x>=obs[w][selected] for x in null[w]))/(REPS+1) for w in queries};curve=[]
for w in queries:
for k in KS:curve.append({'witness':w,'band_width':k,'gain':obs[w][k],'selected':int(k==selected),'max
stat_p_if_selected':p[w] if k==selected else None})
# Extract new records only under the globally selected width.
old=pd.read_csv(ROOT/'gc_segmentation_recovery_035/five_record_anonymous_ledger.csv');oldphys={(r.folio
,int(r.zl_line),int(r.gc_line)) for r in old.itertuples()};new=[]
for key in common:
chosen={}
for w in ('ZL','GC'):
q=qd[w][key];ds=distances(q);top=sorted(range(len(ds)),key=lambda i:ds[i])[:selected];hits=[i for i
in top if i in q['pos']];chosen[w]=(q,min(hits,key=lambda i:ds[i])) if hits else None
if all(chosen.values()):
zq,zi=chosen['ZL'];gq,gi=chosen['GC'];zc,gc=zq['cand'][zi],gq['cand'][gi];zr=[x for x in
zc['payloads'] if x!=key[1]];gr=[x for x in gc['payloads'] if x!=key[1]];jac=d32.multiset_jaccard(zr,gr)
;lcs=d32.lcs_ratio(zr,gr);phys=(key[0],zc['line'],gc['line'])
if phys not in oldphys and jac>=.5 and lcs>=.75:new.append({'record_id':f'{key[0]}:{zc["line"]}/{gc["
line"]}','folio':key[0],'zl_line':zc['line'],'gc_line':gc['line'],'keys':key[1],'zl_residual':' |
'.join(zr),'gc_residual':' | '.join(gr),'multiset_jaccard':jac,'ordered_lcs_ratio':lcs})
nd=pd.DataFrame(new).drop_duplicates(['folio','zl_line','gc_line']) if new else
pd.DataFrame(columns=old.columns);passed=all(p[w]<.05 and obs[w][selected]>0 for w in p) and
len(nd)>=1;expanded=pd.concat([old,nd],ignore_index=True) if passed else old
pd.DataFrame(curve).to_csv(OUT/'bandwidth_curve.csv',index=False);pd.DataFrame({'witness':np.repeat(lis
t(null),REPS),'replicate':list(range(REPS))*len(null),'max_gain':sum([null[w] for w in
null],[])}).to_csv(OUT/'maxstat_null.csv',index=False);nd.to_csv(OUT/'candidate_new_records.csv',index=F
alse);expanded.to_csv(OUT/'promoted_ledger.csv',index=False)
summary={'test':'BANDWIDTH-MAXSTAT-040','widths_tested':list(KS),'globally_selected_width':selected,'ob
served_gains':obs,'maxstat_p':p,'candidate_new_records':len(nd),'promoted_records':len(expanded),'pass':