# decryption_complete: false # source: archive/local/run_scribe_calibration_proxy_001.py # stated_sha256: c0895d661aa5e3a83b8d42e6e9b43305220be09832be0cfae73b31d09d3ad473 # matches_stated_sha256: false # pdf_pages: 502-502 # note: The stated SHA-256 is the digest printed in the PDF. # The PDF page extract follows the form feed. decryption_complete stays false. Voynich Complete Reproducibility Compendium - 2026-08-28 Page 3501 archive/local/run_scribe_calibration_proxy_001.py SHA-256: c0895d661aa5e3a83b8d42e6e9b43305220be09832be0cfae73b31d09d3ad473 | 5,180 bytes | workspace supplement #!/usr/bin/env python3 """Test Hand-specific realization interactions over the anonymous H2 decoder.""" import csv, hashlib, json, math, re from collections import Counter from pathlib import Path import numpy as np from sklearn.feature_extraction import DictVectorizer from sklearn.linear_model import LogisticRegression from sklearn.metrics import log_loss, accuracy_score ROOT=Path('crosswalk002_inputs/Voynich_Line_Local_Reproducibility_2026-08-22/data') OUT=Path('scribe_calibration_proxy_001');OUT.mkdir(exist_ok=True);SEED=20260828 TOK_RE=re.compile(r'[A-Z][0-9a-z]');LOC_RE=re.compile(r'^<([^>.]+)\.([^,>]+),[^>]*>\s*(.*)$');PAGE_RE=re.compile(r'^<([ ^>.]+)>\s*]*)>');META_RE=re.compile(r'\$([A-Z])=([^\s>]+)') BASE=['section','hand','currier','position','source_role','h1','mid_body'] CAL=BASE+['hand_source_role','hand_h1','hand_mid_body'] def fold(f):return int(hashlib.sha256(('composition-h2'+f).encode()).hexdigest()[:8],16)%5 def sec(f): m=re.search(r'\d+',f) if not m:return 'Other' n=int(m.group());return 'Herbal' if n<=66 else 'Astro' if n<=73 else 'Bio' if 75<=n<=84 else 'Pharma' if 87<=n<=102 else 'Recipes' if 103<=n<=116 else 'Other' def parse(path): meta={};pending=None;raw=[] for s in path.read_text(errors='ignore').splitlines(): pm=PAGE_RE.match(s) if pm:meta[pm.group(1)]=dict(META_RE.findall(pm.group(2)));continue lm=LOC_RE.match(s) if lm: fol,line,txt=lm.groups();pending=(fol,line,txt) if txt.strip():raw.append(pending);pending=None continue if pending and s and not s.startswith('<') and not s.startswith('#'): fol,line,txt=pending;raw.append((fol,line,(txt+' '+s).strip()));pending=None out=[] for fol,line,txt in raw: if not re.match(r'^f\d+[rv]$',fol):continue clean=re.sub(r'<[^>]*>','',txt).replace('[','').replace(']','').replace(':','');toks=[] for w in re.split(r'[.,\s]+',clean): u=TOK_RE.findall(w) if len(u)>=3:toks.append(u) if toks:out.append((fol,line,toks,meta.get(fol,{}))) return out def events(lines): out=[] for fol,line,z,meta in lines: hand=meta.get('H','?') for i in range(len(z)-2): a,b,c=z[i:i+3];ratio=i/max(len(z)-1,1);pos='START' if i==0 else 'LATE' if ratio>=.67 else 'MID' if ratio>=.34 else 'EARLY' sr=(z[i-1][-1] if i else 'BOL')+'>'+a[0];h1=a[-1]+'>'+b[0];mid=' '.join(b[1:-1]);h2=b[-1]+'>'+c[0] out.append({'folio':fol,'section':sec(fol),'hand':hand,'currier':meta.get('L','?'),'position':pos,'source_role':sr, 'h1':h1,'mid_body':mid,'h2':h2,'source_body':' '.join(a[1:-1]),'hand_source_role':hand+'|'+sr,'hand_h1':hand+'|'+h1, 'hand_mid_body':hand+'|'+mid}) return out rows=[] for wit in ('ZL','GC'): data=events(parse(ROOT/(wit+'.txt'))) for k in range(5): tr=[r for r in data if fold(r['folio'])!=k];te=[r for r in data if fold(r['folio'])==k];classes=sorted({r['h2'] for r in tr}&{r['h2'] for r in te});tr=[r for r in tr if r['h2'] in classes];te=[r for r in te if r['h2'] in classes] freq=Counter(r['source_body'] for r in tr);tf=Counter(r['source_body'] for r in te);wt=np.array([1/freq[r[ 'source_body']] for r in tr]);we=np.array([1/tf[r['source_body']] for r in te]);scale=len(wt)/wt.sum();wt*=scale; we*=len(we)/we.sum();C=.03/scale for name,fs in (('GENERIC_HAND',BASE),('SCRIBE_CALIBRATED',CAL)): v=DictVectorizer();x=v.fit_transform([{q:r[q] for q in fs} for r in tr]);xt=v.transform([{q:r[q] for q in fs} for r in te]);m=LogisticRegression(C=C,max_iter=500,tol=1e-3,solver='saga',random_state=SEED).fit(x,[r['h2'] for r in tr], sample_weight=wt);p=m.predict_proba(xt);pred=np.asarray(m.classes_)[p.argmax(1)] rows.append({'witness':wit,'fold':k,'model':name,'train_n':len(tr),'test_n':len(te),'features':x.shape[1], 'parameters':x.shape[1]*(len(m.classes_)-1),'bits':log_loss([r['h2'] for r in te],p,labels=m.classes_,sample_weight=we)/ math.log(2),'accuracy':accuracy_score([r['h2'] for r in te],pred,sample_weight=we),'iterations':int(np.max(m.n_iter_)), 'converged':int(np.max(m.n_iter_))0 for q in g),'accuracy_gain':float(np. mean(ag)),'strict_bic_mdl_net_bits':float(np.mean(mdl)),'all_converged':all(r['converged'] for r in z)} summary['promotion_gate']='Positive held-out bits in both witnesses and positive strict BIC/MDL net in both.' (OUT/'summary.json').write_text(json.dumps(summary,indent=2));print(json.dumps(summary,indent=2))