Reproducible V8, stored V5 row, token collision probability

This commit is contained in:
KiHoLee
2026-08-26 15:02:21 +09:00
parent d061a9be88
commit 8d29dfa5ad
5 changed files with 51 additions and 7 deletions
+33 -2
View File
@@ -233,13 +233,41 @@ if HAVE_TEX:
# so the quoted floor must track the data and not one lucky draw.
kl = rows("sec_keylen.csv")
floor = min(float(r["eve_ser"]) for r in kl)
chk("eavesdropper floor over key length", abs(floor - 0.9984) < 5e-4,
chk("eavesdropper floor over key length", 0.9983 < floor < 0.9984,
"%.6f" % floor)
if HAVE_TEX:
chk("quoted eavesdropper floor in tex", "$0.9984$" in tex,
chk("quoted eavesdropper floor in tex", "$0.9983$" in tex,
"searched tex", needs_tex=True)
# --- quantities that used to be quoted with no artifact ---------------
import json as _json
rs = _json.load(open(base / "data" / "real_sec_stats.json"))
chk("token collision probability", abs(rs["token_collision"] - 0.0065) < 5e-5,
"%.6f" % rs["token_collision"])
vm = {r["check"]: r for r in rows("verify_math.csv")}
chk("V5 matched-over-blind ratio stored",
"V5 matched bias over blind RMS" in vm,
", ".join(sorted(vm))[:60])
chk("V8 cross-period remainder",
abs(float(vm["V8 cross-period remainder"]["empirical"])) < 5e-4,
vm["V8 cross-period remainder"]["empirical"])
# --- information-theoretic leakage, which no assertion covered ---------
it = {float(r["snr_db"]): r for r in rows("infotheory.csv")}[10.0]
chk("fixed-key leakage 1.34 bits",
abs(float(it["mi_eve_fixed_bits"]) - 1.34) < 5e-3, it["mi_eve_fixed_bits"])
chk("distinguishing advantage 0.27",
abs(float(it["tv_fixed"]) - 0.27) < 5e-3, it["tv_fixed"])
chk("refreshed leakage 0.055 bits",
abs(float(it["mi_eve_refresh_bits"]) - 0.055) < 5e-4,
it["mi_eve_refresh_bits"])
chk("secrecy rate 14.87 of 14.93",
abs(float(it["secrecy_rate_refresh_bits"]) - 14.87) < 5e-3
and abs(float(it["mi_legit_bits"]) - 14.93) < 5e-3,
"%s of %s" % (it["secrecy_rate_refresh_bits"], it["mi_legit_bits"]))
# --- tables against their generator -----------------------------------
# Every printed table cell must be the one make_tables.py derives from
# data/, so a rerun that moves a number cannot leave the manuscript behind.
@@ -273,3 +301,6 @@ chk("abstract has no abbreviations",
print()
print("ALL CONSISTENT" if ok else "INCONSISTENCIES FOUND")
# a checker that always exits zero cannot gate anything
import sys as _sys
_sys.exit(0 if ok else 1)
+4
View File
@@ -189,6 +189,10 @@ def main():
"repeats": REPEATS,
"decisions_per_point": N * U * REPEATS,
"distinct_tokens": int(torch.unique(ids_all).numel()),
# the chance that two independently drawn tokens coincide, which
# is the floor the insider TER is measured against
"token_collision": float(((torch.bincount(ids_all.reshape(-1)).double()
/ ids_all.numel()) ** 2).sum()),
"max_token_id": int(ids_all.max()),
"headlines_scored": sum(len(b) for b in bounds),
"headline_runs": REC_RUNS,
+11 -4
View File
@@ -185,6 +185,10 @@ def v5_matched_jammer_concentrates():
print(f"[{'PASS' if ok else 'FAIL'}] V5 matched bias / blind RMS: "
f"matched={bm:.3f} blind_rms={brms:.4f} ratio={ratio:.1f} "
f"(claim sqrt(d)={np.sqrt(D):.1f})")
ROWS.append(("V5 matched bias over blind RMS",
"%.1f" % np.sqrt(D), "%.1f" % ratio,
"%.2f" % abs(ratio - np.sqrt(D)), "1.0",
"PASS" if ok else "FAIL"))
return ok
@@ -260,16 +264,19 @@ def v8_cross_period_terms():
import math
import torch
from exp_full import main_model
torch.manual_seed(7)
m = main_model()
Bn = m.unit_codebook().detach().cpu()
pat = m.masks().detach().cpu()[0]
L, P, d = m.L, m.P, m.d
# a generator of its own, seeded after the model is built: seeding the
# global one first leaves the draw dependent on how main_model consumed
# it, which moved this number between runs
g = torch.Generator().manual_seed(7)
rel = []
for _ in range(300):
w = torch.randn(d)
for _ in range(20000):
w = torch.randn(d, generator=g)
w /= w.norm()
i = torch.randint(m.vu, (P,))
i = torch.randint(m.vu, (P,), generator=g)
e = (Bn[i] / math.sqrt(P)).reshape(-1)
a = (w * e).reshape(P, L) * pat[None, :]
diag = float((a ** 2).sum())