run_referential_core_019.py VOYNICH RESEARCH ARCHIVE | 16 SEPTEMBER 2026 3 shared=sorted(set(pages.get(a,{}))&set(pages.get(b,{}))) results.append({'witness':wit,**g,'section_pair':section(a)+'>'+section(b),'a_events':sum(pages.get(a ,{}).values()),'b_events':sum(pages.get(b,{}).values()),'weighted_jaccard':score,'matched_pairs':len(val s),'matched_median':med,'pair_empirical_p':pct,'above_matched_median':int(bool(vals) and score>med),'shared_stems':'|'.join(f'{sid[s]}:{s}' for s in shared)}) pools.append(pool);obs.append(score);pair_above.append(bool(vals) and score>med) valid=[i for i,p in enumerate(pools) if p] obsmean=float(np.mean([obs[i] for i in valid])) if valid else 0 null=np.zeros(REPS) sampled_pairs=[] for rep in range(REPS): picked=[] for i in valid: q=pools[i][rng.integers(len(pools[i]))];picked.append(q);sampled_pairs.append({'witness':wit,'replic ate':rep,'group_id':groups[i]['group_id'],'folio_a':q[0],'folio_b':q[1],'similarity':q[2]}) null[rep]=np.mean([x[2] for x in picked]) if picked else 0 p=(1+(null>=obsmean).sum())/(REPS+1) # Candidate stem support across duplicate groups; selection-aware maximum support null. observed_support={s:sum(s in pages.get(g['folio_a'],{}) and s in pages.get(g['folio_b'],{}) for g in groups) for s in stems} null_support=np.zeros((REPS,len(stems)),dtype=np.int8) for rep in range(REPS): pairs=[] for pool in pools: if pool: q=pool[rng.integers(len(pool))];pairs.append((q[0],q[1])) for j,s in enumerate(stems):null_support[rep,j]=sum(s in pages.get(a,{}) and s in pages.get(b,{}) for a,b in pairs) maxsup=null_support.max(1) for j,s in enumerate(stems): os=observed_support[s];support_rows.append({'witness':wit,'stem_id':sid[s],'payload':s,'duplicate_gro ups_supported':os,'familywise_p':(1+(maxsup>=os).sum())/(REPS+1),'supporting_groups':'|'.join(g['group_i d'] for g in groups if s in pages.get(g['folio_a'],{}) and s in pages.get(g['folio_b'],{}))}) nullrows.extend(sampled_pairs) summary_w[wit]={'available_pages':N,'duplicate_groups':len(groups),'valid_matched_groups':len(valid),' observed_mean_similarity':obsmean,'null_mean_similarity':float(null.mean()),'aggregate_p':float(p),'pair s_above_matched_median':sum(pair_above),'aggregate_pass':bool(p<.05 and all(pair_above))} # Cross-witness candidate promotions. z={r['payload']:r for r in support_rows if r['witness']=='ZL'};c={r['payload']:r for r in support_rows if r['witness']=='GC'} promoted=[s for s in stems if z[s]['duplicate_groups_supported']>=2 and c[s]['duplicate_groups_supported']>=2 and z[s]['familywise_p']<.05 and c[s]['familywise_p']<.05] # Positive-control receipt for the previously earned Pleiades body. pc=[] for wit in ('ZL','GC'): _,_,allb=parsed[wit];body='A1 A3 C1';pc.append({'witness':wit,'body':body,'f68r3_count':allb.get('f68r 3',{}).get(body,0),'f1r_count':allb.get('f1r',{}).get(body,0),'f113r_count':allb.get('f113r',{}).get(bod y,0),'control_pass':int(allb.get('f68r3',{}).get(body,0)>=1 and allb.get('f1r',{}).get(body,0)>=1 and allb.get('f113r',{}).get(body,0)>=1)}) with (OUT/'duplicate_group_source_ledger.csv').open('w',newline='') as f:w=csv.DictWriter(f,fieldnames=groups[0]);w.writeheader();w.writerows(groups) with (OUT/'duplicate_pair_results.csv').open('w',newline='') as f:w=csv.DictWriter(f,fieldnames=results[0]);w.writeheader();w.writerows(results) with (OUT/'matched_pair_null.csv').open('w',newline='') as f:w=csv.DictWriter(f,fieldnames=nullrows[0]) ;w.writeheader();w.writerows(nullrows) with (OUT/'stem_duplicate_support.csv').open('w',newline='') as f:w=csv.DictWriter(f,fieldnames=support_rows[0]);w.writeheader();w.writerows(support_rows) with (OUT/'positive_control_pleiades.csv').open('w',newline='') as f:w=csv.DictWriter(f,fieldnames=pc[0]);w.writeheader();w.writerows(pc) decision='REFERENTIAL_CORE_PASS' if all(summary_w[w]['aggregate_pass'] for w in ('ZL','GC')) and promoted else 'NO_REFERENTIAL_CORE_PROMOTION' summary={'test':'REFERENTIAL-CORE-019','date':'2026-08-29','seed':SEED,'null_replicates':REPS,'original _stems':77,'removed_register_candidates':sorted(REMOVED),'tested_stems':len(stems),'duplicate_groups':le