What does Context-Parametric Rule Distillation and Online Calibration conclude, in numbers, about “Closing the Loop: Field Tools and Checker Specifications, the Risk Ledger and a Pre-registered Test”?
Answer: Chapter 8 gives the Conditional-Parametric Rule Compiler and Online Calibrator, checker specifications, a risk-control ledger and a pre-registered test. Marked boxes separate published evidence, runnable Python calculations (22 programs), classical sources and the author's hypotheses.
Scope of the numbers: Parameters are illustrative and all calculations are generated by the book's programs. This is general business analysis, not investment, legal or medical advice, and it describes no real customer or sale.
Data table
The numbers below are printed verbatim by the chapter's Python program and can be reproduced by running it. standard-library Python only
id bundle n mean 5% 95% n_min verdict K01 B 3,200 0.0440 0.0382 0.0501 992 GREEN K02 B 2,100 0.0335 0.0274 0.0401 992 GREEN K03 D 600 0.0508 0.0374 0.0657 992 RED K04 S 5,000 0.0396 0.0352 0.0442 992 RED K05 D 4,100 0.0390 0.0342 0.0441 992 RED K06 S 900 0.0442 0.0338 0.0557 992 RED K07 S 1,500 0.0348 0.0275 0.0428 992 YELLOW K08 D 1,800 0.0690 0.0599 0.0786 829 YELLOW K03: WIDE DUPEVID:K07 K04: NOCOND K05: CONFLICT:K06 ECE K06: CONFLICT:K05 THIN K07: DUPEVID:K03 K08: DRIFT red 4, yellow 2, green 2 K08 prior 90% interval 0.0202 to 0.0651
Show the full program
# Chapter 8. p81: the rule-ledger checker run on an illustrative pack.
# Same functions as distill/tool.py. Each ledger row: id, source book
# and chapter, condition vector, bundle, prior Beta(a, b), exposures n,
# clicks, pays, used for pricing, threshold changed, binned calibration
# error, evidence ids, rulings. Red: NOCOND (no condition vector),
# CONFLICT (equal specificity, overlapping region, different bundle,
# no ruling), WIDE (priced on a 90% interval wider than 0.020), THIN
# (threshold changed below the minimum exposures n_min). Yellow:
# DUPEVID (one observation id in two rules), DRIFT (posterior mean
# outside the prior 90% interval), ECE (calibration error > 0.020).
import math
DEMO = [
"K01;B-150 ch3;visit=return;B;2;48;3200;410;141;1;0;0.012;o1;"
"K03,K05,K06",
"K02;B-311 ch2;src=social,dev=mobile;B;2;48;2100;260;70;0;1;"
"0.018;o2;",
"K03;B-026 ch5;tier=high;D;2;48;600;70;31;1;0;0.009;o3;K06",
"K04;B-100 ch4;;S;2;48;5000;520;198;0;0;0.011;o4;",
"K05;B-146 ch6;src=search;D;2;48;4100;600;160;0;0;0.026;o5;",
"K06;B-268 ch2;src=search;S;2;48;900;95;40;0;1;0.010;o6;",
"K07;B-152 ch7;tier=high,visit=return;S;2;48;1500;150;52;0;0;"
"0.008;o3;K02,K08",
"K08;B-150 ch5;src=direct,slot=night;D;8;192;1800;190;130;0;0;"
"0.014;o7;",
]
def betacf(a, b, x):
tiny = 1e-300
qab, qap, qam = a + b, a + 1.0, a - 1.0
c, d = 1.0, 1.0 - qab * x / qap
d = 1.0 / (d if abs(d) > tiny else tiny)
h = d
for m in range(1, 400):
m2 = 2 * m
aa = m * (b - m) * x / ((qam + m2) * (a + m2))
d = 1.0 + aa * d
d = 1.0 / (d if abs(d) > tiny else tiny)
c = 1.0 + aa / c
c = c if abs(c) > tiny else tiny
h *= d * c
aa = -(a + m) * (qab + m) * x / ((a + m2) * (qap + m2))
d = 1.0 + aa * d
d = 1.0 / (d if abs(d) > tiny else tiny)
c = 1.0 + aa / c
c = c if abs(c) > tiny else tiny
delta = d * c
h *= delta
if abs(delta - 1.0) < 1e-14:
break
return h
def ibeta(a, b, x):
if x <= 0.0:
return 0.0
if x >= 1.0:
return 1.0
lb = (math.lgamma(a + b) - math.lgamma(a) - math.lgamma(b)
+ a * math.log(x) + b * math.log(1.0 - x))
if x < (a + 1.0) / (a + b + 2.0):
return math.exp(lb) * betacf(a, b, x) / a
return 1.0 - math.exp(lb) * betacf(b, a, 1.0 - x) / b
def bquant(a, b, q):
lo, hi = 0.0, 1.0
for _ in range(80):
mid = 0.5 * (lo + hi)
if ibeta(a, b, mid) < q:
lo = mid
else:
hi = mid
return 0.5 * (lo + hi)
def min_n(a0, b0, w):
p = a0 / (a0 + b0)
def width(n):
k = round(p * n)
a, b = a0 + k, b0 + n - k
return bquant(a, b, 0.95) - bquant(a, b, 0.05)
lo, hi = 1, 400000
while lo < hi:
mid = (lo + hi) // 2
if width(mid) <= w:
hi = mid
else:
lo = mid + 1
return lo
def parse(s):
f = s.split(";")
if len(f) != 14:
raise ValueError("rule needs 14 fields: " + s)
cond = {}
for kv in f[2].split(","):
if kv.strip():
k, v = kv.split("=")
cond[k.strip()] = v.strip()
return {"id": f[0], "source": f[1], "cond": cond, "bundle": f[3],
"a": float(f[4]), "b": float(f[5]), "n": int(f[6]),
"clicks": int(f[7]), "pays": int(f[8]),
"pricing": f[9] == "1", "changed": f[10] == "1",
"ece": float(f[11]),
"evidence": [e for e in f[12].split(",") if e],
"ruling": [e for e in f[13].split(",") if e]}
def overlap(c1, c2):
return all(c2.get(k, v) == v for k, v in c1.items())
def check(rules, max_width, ece_max):
out = []
for r in rules:
a, b = r["a"] + r["pays"], r["b"] + r["n"] - r["pays"]
lo, hi = bquant(a, b, 0.05), bquant(a, b, 0.95)
plo = bquant(r["a"], r["b"], 0.05)
phi = bquant(r["a"], r["b"], 0.95)
nmin = min_n(r["a"], r["b"], max_width)
red, yellow = [], []
if not r["cond"]:
red.append("NOCOND")
for o in rules:
if o is r or o["bundle"] == r["bundle"]:
continue
same = len(o["cond"]) == len(r["cond"])
ruled = o["id"] in r["ruling"] or r["id"] in o["ruling"]
if same and overlap(r["cond"], o["cond"]) and not ruled:
red.append("CONFLICT:" + o["id"])
if set(o["evidence"]) & set(r["evidence"]):
yellow.append("DUPEVID:" + o["id"])
if r["pricing"] and hi - lo > max_width:
red.append("WIDE")
if r["changed"] and r["n"] < nmin:
red.append("THIN")
mean = a / (a + b)
if mean < plo or mean > phi:
yellow.append("DRIFT")
if r["ece"] > ece_max:
yellow.append("ECE")
color = "RED" if red else ("YELLOW" if yellow else "GREEN")
out.append({"id": r["id"], "source": r["source"],
"bundle": r["bundle"], "n": r["n"],
"post_mean": round(mean, 4), "lo90": round(lo, 4),
"hi90": round(hi, 4), "n_min": nmin,
"color": color, "codes": red + yellow})
return out
def main():
rows = check([parse(s) for s in DEMO], 0.02, 0.02)
print("id bundle n mean 5% 95% n_min verdict")
for r in rows:
print("{:<4} {:<4} {:>8,} {:.4f} {:.4f} {:.4f} {:>6,} {}".format(
r["id"], r["bundle"], r["n"], r["post_mean"], r["lo90"],
r["hi90"], r["n_min"], r["color"]))
for r in rows:
if r["codes"]:
print(" {}: {}".format(r["id"], " ".join(r["codes"])))
tally = {}
for r in rows:
tally[r["color"]] = tally.get(r["color"], 0) + 1
print("red {}, yellow {}, green {}".format(
tally.get("RED", 0), tally.get("YELLOW", 0), tally.get("GREEN", 0)))
k08 = parse(DEMO[7])
print("K08 prior 90% interval {:.4f} to {:.4f}".format(
bquant(k08["a"], k08["b"], 0.05), bquant(k08["a"], k08["b"], 0.95)))
if __name__ == "__main__":
main()Single source and citation
Fan, Y. (2026). Next-Generation Knowledge Distillation, Context-Parametric Compilation and Live-Conversion Feedback Calibration (Version 1.0.0), Chapter 8: Closing the Loop: Field Tools and Checker Specifications, the Risk Ledger and a Pre-registered Test. 5D Library. DOI pending
DOI pending · monograph page goes live after publication · 5DL-B-377 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026377,
author = {Fan, Yafu},
title = {Next-Generation Knowledge Distillation, Context-Parametric Compilation and Live-Conversion Feedback Calibration},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
note = {DOI pending}
}Other chapter answers in this book
- Chapter 1 · Simpson's Reversal: Why a Rule Without Its Context Can Point the Wrong Way
- Chapter 2 · Context-Parametric Compilation: Squeezing a Decision Table into Decision Lists and Ordered Decision Diagrams
- Chapter 3 · Resolving Conflicts Across Volumes: Do More Rules Make a Pack More Accurate?
- Chapter 4 · Online Bayesian Calibration: Giving Every Rule a Beta Distribution That Grows
- Chapter 5 · Threshold Drift: Discounted Beta Updates, Sliding Windows and a Cumulative-Sum Alarm
- Chapter 6 · Calibration and the Whole Pipeline: the Brier Partition, Binned Calibration Error and a Net-Benefit Simulation
- Chapter 7 · Classical Sources: Wheelwright Bian and Aristotle on Equity