Voynich Complete Reproducibility Compendium - 2026-08-28 Page 2644 def stream_stats(lines, segmap): uni, bi = Counter(), Counter() glyphs = 0 for ln in lines: units = [] for w in ln: units.extend(segmap[w]) glyphs += len(w) uni.update(units) bi.update(zip(units, units[1:])) n = sum(uni.values()) H1 = -sum(c/n * math.log2(c/n) for c in uni.values()) nb = sum(bi.values()) H12 = -sum(c/nb * math.log2(c/nb) for c in bi.values()) # H(next|prev) = H(pair) - H(prev-marginal over bigram table) prev = Counter() for (x, _), c in bi.items(): prev[x] += c Hprev = -sum(c/nb * math.log2(c/nb) for c in prev.values()) H2 = H12 - Hprev return dict(types=len(uni), units=n, glyphs=glyphs, mean_len=glyphs/n, H1=H1, H2=H2, bits_per_glyph=H2*n/glyphs, gap=H1-H2) # ----------------------------------------------------------------- E1 run -- def run_e1(): vy = voynich_lines() lat_all = to_lines(latin_words()) n_vy = sum(len(w) for ln in vy for w in ln) print(f"voynich: {len(vy)} lines, {n_vy} glyphs", flush=True) t_v2, t_v13, t_homo = build_ciphers(lat_all) corpora = { "voynich": vy, "latin": lat_all, "latin_verbose2": cipher_corpus(lat_all, t_v2), "latin_verbose13": cipher_corpus(lat_all, t_v13), "latin_homophonic": cipher_corpus(lat_all, t_homo), "selfcitation": selfcite_lines(vy), } target = min(n_vy, *(sum(len(w) for ln in c for w in ln) for c in corpora.values())) print("target glyphs:", target, flush=True) checkpoints = [0, 4, 8, 16, 32, 64, 128, 256, 512, 1024] out = {} merged_first = {} for name, lines in corpora.items(): lines = truncate(lines, target) res = bpe_checkpoints(lines, set(checkpoints), max(checkpoints)) out[name] = {} for k, segmap in sorted(res.items()): st = stream_stats(lines, segmap) out[name][k] = st print(f"{name:18s} k={k:5d} types={st['types']:5d} len={st['mean_len']:.2f} " f"H1={st['H1']:.3f} H2={st['H2']:.3f} b/g={st['bits_per_glyph']:.3f} " f"gap={st['gap']:.3f}", flush=True) # record the first 25 discovered units (longest-first among merged) if 32 in res: units = Counter() for ln in lines: for w in ln: units.update(u for u in res[32][w] if len(u) > 1) merged_first[name] = [u for u, _ in units.most_common(25)] (SCRATCH / "output" / "e1_results.json").write_text(json.dumps( dict(stats=out, early_units=merged_first), indent=2)) # ----------------------------------------------------------------- E2 run -- def one_edit_components(vocab): parent = {w: w for w in vocab} def find(x): while parent[x] != x: parent[x] = parent[parent[x]]; x = parent[x] return x def union(a, b): ra, rb = find(a), find(b) if ra != rb: parent[ra] = rb dels = defaultdict(list) for w in vocab: for i in range(len(w)): dels[w[:i] + w[i+1:]].append(w) for key, words in dels.items(): if len(words) > 250: bylen = defaultdict(list) for w in words: bylen[len(w)].append(w) groups = list(bylen.values()) else: groups = [words] for group in groups: for i, a in enumerate(group): for b in group[i+1:]: if abs(len(a)-len(b)) <= 1 and lev(a, b) <= 1: union(a, b)