Voynich Master Archive - Volume 03 - Pages 2001-3000
Chinese classical control text, plus later workspace supplement files in the same PDF
PDF page 648 of 1000. Catalog page range 2001-3000.
Extracted text
Voynich Complete Reproducibility Compendium - 2026-08-28 Page 2647
c1 = np.bincount(ids, minlength=A).astype(float)
c2 = np.zeros((A, A))
np.add.at(c2, (ids[:-1], ids[1:]), 1.0)
c3 = np.zeros((A, A, A))
np.add.at(c3, (ids[:-2], ids[1:-1], ids[2:]), 1.0)
p1 = (c1 + 0.5) / (c1.sum() + 0.5 * A)
p2 = (c2 + 0.5) / (c2.sum(1, keepdims=True) + 0.5 * A)
p3 = (c3 + 0.5) / (np.maximum(c3.sum(2, keepdims=True), 1e-9) + 0.5 * A)
P = lam[0] * p1[None, None, :] + lam[1] * p2[None, :, :] + lam[2] * p3
self.logp = np.log2(P)
self.unigram = p1
def anchor_bits(self, heldout: str) -> float:
"""Per-symbol log2-prob of real held-out text of this language."""
ids = np.array([self.index[c] for c in heldout if c in self.index],
dtype=np.int32)
return float(self.logp[ids[:-2], ids[1:-1], ids[2:]].mean())
def build_lms(langs) -> dict[str, tuple["TrigramLM", float]]:
out = {}
for lang in langs:
base = lang[:-9] if lang.endswith("_novowels") else lang
s = letters_of(base)
if lang.endswith("_novowels"):
s = novowels(s)
cut = int(len(s) * 0.85)
lm = TrigramLM(s[:cut])
out[lang] = (lm, lm.anchor_bits(s[cut:]))
return out
# ------------------------------------------------- BPE + Brown-style merge --
def unit_stream(lines, segmap):
return [[u for w in ln for u in segmap[w]] for ln in lines]
def pipeline_classes(lines, k: int, m_targets: list[int], seed=0):
"""BPE(k) then agglomerative merge; returns unit lines, and per-m classmap."""
segmap = bpe_checkpoints(lines, {k}, k)[k]
ustream = unit_stream(lines, segmap)
train = [ln for i, ln in enumerate(ustream) if i % 2 == 0 and len(ln) > 1]
types = sorted({u for ln in train for u in ln})
idx = {u: i for i, u in enumerate(types)}
V = len(types)
C = np.zeros((V, V))
for ln in train:
for a, b in zip(ln, ln[1:]):
if a in idx and b in idx:
C[idx[a], idx[b]] += 1
def mi_of(M):
P = M / M.sum()
ra = P.sum(1, keepdims=True)
rb = P.sum(0, keepdims=True)
with np.errstate(divide="ignore", invalid="ignore"):
T = P * np.log2(P / (ra @ rb))
return np.nansum(T)
alive = list(range(V))
members = {i: [types[i]] for i in range(V)}
maps = {}
while len(alive) > min(m_targets):
best, bp = -1e18, None
for ii, a in enumerate(alive):
for b in alive[ii + 1:]:
sub = C[np.ix_(alive, alive)].copy()
ia, ib = alive.index(a), alive.index(b)
sub[ia, :] += sub[ib, :]
sub[:, ia] += sub[:, ib]
sub = np.delete(np.delete(sub, ib, 0), ib, 1)
v = mi_of(sub)
if v > best:
best, bp = v, (a, b)
a, b = bp
C[a, :] += C[b, :]
C[:, a] += C[:, b]
C[b, :] = 0
C[:, b] = 0
members[a] += members.pop(b)
alive.remove(b)
if len(alive) in m_targets:
cm = {}
for root_i, root in enumerate(sorted(alive)):
for u in members[root]:
cm[u] = root_i
maps[len(alive)] = cm
return segmap, ustream, maps
# ------------------------------------------------------------------ attack --
def class_arrays(ustream, classmap, parity):
"""Concatenated class ids + trigram index triples (not crossing lines)."""
seqs = []
for i, ln in enumerate(ustream):