run_engine_slot_021.py VOYNICH RESEARCH ARCHIVE | 16 SEPTEMBER 2026 1 run_engine_slot_021.py Source: /Voynich/run_engine_slot_021.py SHA-256: e310619d7f6c353fae734e44b1f426d6ce84c98ec916377abebffdc7412e9df5 !/usr/bin/env python3 """ENGINE-SLOT-021: held-out test of a small reusable structural engine inventory.""" import csv, hashlib, json, math, re from collections import Counter, defaultdict from pathlib import Path import numpy as np from sklearn.cluster import KMeans from sklearn.feature_extraction import DictVectorizer from sklearn.linear_model import LogisticRegression from sklearn.metrics import log_loss SEED = 20260829 REPS = 500 KS = tuple(range(2, 9)) ROOT = Path(__file__).resolve().parent OUT = ROOT / "engine_slot_021" OUT.mkdir(exist_ok=True) SCAFF = ROOT / "outer_scaffold_coverage_001/corpus_scaffold.csv" RAW = ROOT / "crosswalk002_inputs/Voynich_Line_Local_Reproducibility_2026-08-22/data/ZL.txt" CLUST = ROOT / "stem_context_geometry_004/consensus_clusters.csv" def folio_fold(folio): return int(hashlib.sha256(("engine-slot-021|" + folio).encode()).hexdigest()[:8], 16) % 5 def section(folio): n = int(re.search(r"\d+", folio).group()) if n <= 66: return "Herbal" if n <= 73: return "Astro" if 75 <= n <= 84: return "Bio" if 87 <= n <= 102: return "Pharma" if 103 <= n <= 116: return "Recipes" return "Other" payload_cluster = {r["payload"]: r["cluster"] for r in csv.DictReader(CLUST.open())} meta = {} for s in RAW.read_text(errors="ignore").splitlines(): m = re.match(r"^<(f\d+[rv])>\s+", s) if m: d = dict(re.findall(r"\$([A-Z])=([^\s>]+)", m.group(2))) meta[m.group(1)] = {"currier": d.get("L", "?"), "hand": d.get("H", "?")} grouped = defaultdict(list) for r in csv.DictReader(SCAFF.open()): grouped[(r["witness"], r["folio"], r["line"])].append(r) lines = [] for (wit, fol, line_no), rows in grouped.items(): if fol not in meta: continue rows.sort(key=lambda r: int(r["index"])) rows = [r for r in rows if r["both_resolved"] == "1" and r["payload"] in payload_cluster] if len(rows) < 6: continue cut = len(rows) // 2 first, second = rows[:cut], rows[cut:] fv = Counter() for j, r in enumerate(first): frame = r["left_function"] + ">" + r["right_function"] fv["frame=" + frame] += 1 fv["left=" + r["left_function"]] += 1 fv["right=" + r["right_function"]] += 1